Submission #18580694


Source Code Expand

Copy
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def from_read(dtype=np.int64):
    return np.fromstring(read().decode(), dtype=dtype, sep=' ')


def from_readline(dtype=np.int64):
    return np.fromstring(readline().decode(), dtype=dtype, sep=' ')

def main(P):
    P = np.append(0, P)
    pos = np.zeros_like(P)
    N = len(P)
    for i in range(N):
        pos[P[i]] = i
    use = np.zeros(N - 1, np.bool_)
    ans = []
    A = P
    for x in range(N - 1, 0, -1):
        if pos[x] == x:
            continue
        p = pos[x]
        for i in range(p, x):
            A[i], A[i + 1] = A[i + 1], A[i]
            pos[A[i]] = i
            pos[A[i + 1]] = i + 1
            if use[i]:
                return False, ans
            use[i] = 1
            ans.append(i)
    return np.all(use[1:]), ans

P = from_read()[1:]

bl, ans = main(P)
if bl:
    print(*ans)
else:
    print(-1)

Submission Info

Submission Time
Task C - Exoswap
User maspy
Language Python (3.8.2)
Score 500
Code Size 1016 Byte
Status AC
Exec Time 530 ms
Memory 40380 KB

Judge Result

Set Name All Sample
Score / Max Score 500 / 500 0 / 0
Status
AC × 59
AC × 2
Set Name Test Cases
All sample_01.txt, sample_02.txt, testcase_1.txt, testcase_10.txt, testcase_11.txt, testcase_12.txt, testcase_13.txt, testcase_14.txt, testcase_15.txt, testcase_16.txt, testcase_17.txt, testcase_18.txt, testcase_19.txt, testcase_2.txt, testcase_20.txt, testcase_21.txt, testcase_22.txt, testcase_23.txt, testcase_24.txt, testcase_25.txt, testcase_26.txt, testcase_27.txt, testcase_28.txt, testcase_29.txt, testcase_3.txt, testcase_30.txt, testcase_31.txt, testcase_32.txt, testcase_33.txt, testcase_34.txt, testcase_35.txt, testcase_36.txt, testcase_37.txt, testcase_38.txt, testcase_39.txt, testcase_4.txt, testcase_40.txt, testcase_41.txt, testcase_42.txt, testcase_43.txt, testcase_44.txt, testcase_45.txt, testcase_46.txt, testcase_47.txt, testcase_48.txt, testcase_49.txt, testcase_5.txt, testcase_50.txt, testcase_51.txt, testcase_52.txt, testcase_53.txt, testcase_54.txt, testcase_55.txt, testcase_56.txt, testcase_57.txt, testcase_6.txt, testcase_7.txt, testcase_8.txt, testcase_9.txt
Sample sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
sample_01.txt AC 115 ms 27024 KB
sample_02.txt AC 109 ms 27104 KB
testcase_1.txt AC 107 ms 26712 KB
testcase_10.txt AC 125 ms 27968 KB
testcase_11.txt AC 213 ms 32528 KB
testcase_12.txt AC 194 ms 31484 KB
testcase_13.txt AC 150 ms 29408 KB
testcase_14.txt AC 496 ms 39836 KB
testcase_15.txt AC 499 ms 39664 KB
testcase_16.txt AC 502 ms 40000 KB
testcase_17.txt AC 498 ms 39712 KB
testcase_18.txt AC 502 ms 39932 KB
testcase_19.txt AC 504 ms 39744 KB
testcase_2.txt AC 109 ms 26848 KB
testcase_20.txt AC 501 ms 39908 KB
testcase_21.txt AC 499 ms 39988 KB
testcase_22.txt AC 502 ms 39716 KB
testcase_23.txt AC 526 ms 39856 KB
testcase_24.txt AC 499 ms 39988 KB
testcase_25.txt AC 502 ms 39996 KB
testcase_26.txt AC 498 ms 39760 KB
testcase_27.txt AC 495 ms 39756 KB
testcase_28.txt AC 367 ms 35316 KB
testcase_29.txt AC 121 ms 27556 KB
testcase_3.txt AC 108 ms 26820 KB
testcase_30.txt AC 475 ms 40380 KB
testcase_31.txt AC 437 ms 39108 KB
testcase_32.txt AC 199 ms 29760 KB
testcase_33.txt AC 427 ms 37316 KB
testcase_34.txt AC 456 ms 39828 KB
testcase_35.txt AC 464 ms 39936 KB
testcase_36.txt AC 467 ms 40020 KB
testcase_37.txt AC 452 ms 39756 KB
testcase_38.txt AC 449 ms 40024 KB
testcase_39.txt AC 454 ms 39800 KB
testcase_4.txt AC 111 ms 27020 KB
testcase_40.txt AC 453 ms 40024 KB
testcase_41.txt AC 211 ms 30808 KB
testcase_42.txt AC 367 ms 36588 KB
testcase_43.txt AC 350 ms 35672 KB
testcase_44.txt AC 344 ms 36640 KB
testcase_45.txt AC 456 ms 39912 KB
testcase_46.txt AC 351 ms 36604 KB
testcase_47.txt AC 271 ms 34588 KB
testcase_48.txt AC 454 ms 39852 KB
testcase_49.txt AC 295 ms 35620 KB
testcase_5.txt AC 112 ms 26912 KB
testcase_50.txt AC 448 ms 39124 KB
testcase_51.txt AC 199 ms 30032 KB
testcase_52.txt AC 129 ms 27772 KB
testcase_53.txt AC 187 ms 29472 KB
testcase_54.txt AC 530 ms 40024 KB
testcase_55.txt AC 458 ms 39664 KB
testcase_56.txt AC 213 ms 31288 KB
testcase_57.txt AC 361 ms 39860 KB
testcase_6.txt AC 111 ms 27020 KB
testcase_7.txt AC 106 ms 26928 KB
testcase_8.txt AC 109 ms 27132 KB
testcase_9.txt AC 367 ms 39392 KB