結果

問題 No.241 出席番号(1)
ユーザー 👑 rin204rin204
提出日時 2022-07-10 17:42:35
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 746 bytes
コンパイル時間 1,470 ms
コンパイル使用メモリ 86,672 KB
実行使用メモリ 71,464 KB
最終ジャッジ日時 2023-09-02 00:47:33
合計ジャッジ時間 7,374 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,108 KB
testcase_01 AC 69 ms
71,320 KB
testcase_02 AC 70 ms
71,304 KB
testcase_03 AC 69 ms
71,304 KB
testcase_04 AC 70 ms
71,084 KB
testcase_05 WA -
testcase_06 AC 69 ms
71,228 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 69 ms
71,304 KB
testcase_10 AC 71 ms
71,392 KB
testcase_11 AC 69 ms
71,412 KB
testcase_12 AC 68 ms
71,156 KB
testcase_13 AC 68 ms
70,952 KB
testcase_14 AC 67 ms
71,232 KB
testcase_15 AC 69 ms
71,104 KB
testcase_16 AC 68 ms
71,256 KB
testcase_17 WA -
testcase_18 AC 68 ms
71,116 KB
testcase_19 AC 69 ms
71,252 KB
testcase_20 AC 68 ms
71,216 KB
testcase_21 AC 71 ms
70,948 KB
testcase_22 AC 70 ms
71,444 KB
testcase_23 AC 70 ms
71,156 KB
testcase_24 AC 71 ms
71,464 KB
testcase_25 AC 70 ms
71,088 KB
testcase_26 AC 71 ms
71,288 KB
testcase_27 AC 71 ms
71,100 KB
testcase_28 AC 69 ms
71,288 KB
testcase_29 AC 71 ms
71,288 KB
testcase_30 AC 72 ms
71,460 KB
testcase_31 AC 71 ms
71,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
A = [int(input()) for _ in range(n)]
se = set(A)
if len(se) == 1:
    print(-1)
    exit()
P = [i for i in range(n)]
while 1:
    lst = []
    for i in range(n):
        if A[i] == P[i]:
            lst.append(i)
            if len(lst) == 2:
                break
    if len(lst) == 2:
        i, j = lst
        P[i], P[j] = P[j], P[i]
    else:
        break

lst = []
for i in range(n):
    if A[i] == P[i]:
        lst.append(i)
        
if lst:
    i = lst[0]
    ok = False
    for j in range(n):
        if i == j:
            continue
        if A[i] != P[j] and P[i] != A[j]:
            P[i], P[j] = P[j], P[i]
            ok = True
            break
    if not ok:
        print(-1)
        exit()
print(*P, sep="\n")
0