ARC110C
https://gyazo.com/f71976b9a1f12a846b3cf359703b0135
ARC110C
Do it greedily
Think "How to bring one to the front of the line?"
It is essential to have a replacement that brings you from where you are now to the front of the line.
If there is an excess or deficiency, it is NG.
code:python
def solve(N, PS):
ret = []
def swap(x):
ret.append(x)
for target in range(1, N):
x = PS.index(target, target - 1)
for i in range(x, target - 1, -1):
swap(i)
if False in used:
return ret
---
This page is auto-translated from /nishio/ARC110C. If you looks something interesting but the auto-translated English is not good enough to understand it, feel free to let me know at @nishio_en. I'm very happy to spread my thought to non-Japanese readers.