結果

問題 No.241 出席番号(1)
ユーザー 👑 rin204rin204
提出日時 2022-07-10 17:43:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 705 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 87,132 KB
実行使用メモリ 71,608 KB
最終ジャッジ日時 2023-09-02 00:48:39
合計ジャッジ時間 4,436 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
71,404 KB
testcase_01 AC 70 ms
71,336 KB
testcase_02 AC 67 ms
71,608 KB
testcase_03 AC 68 ms
71,112 KB
testcase_04 AC 70 ms
71,092 KB
testcase_05 AC 67 ms
71,596 KB
testcase_06 AC 68 ms
71,424 KB
testcase_07 AC 69 ms
71,304 KB
testcase_08 AC 69 ms
71,304 KB
testcase_09 AC 69 ms
71,500 KB
testcase_10 AC 67 ms
71,340 KB
testcase_11 AC 69 ms
71,296 KB
testcase_12 AC 71 ms
71,136 KB
testcase_13 AC 68 ms
71,096 KB
testcase_14 AC 68 ms
71,404 KB
testcase_15 AC 68 ms
71,092 KB
testcase_16 AC 66 ms
71,544 KB
testcase_17 AC 67 ms
71,276 KB
testcase_18 AC 67 ms
71,356 KB
testcase_19 AC 65 ms
71,400 KB
testcase_20 AC 67 ms
71,244 KB
testcase_21 AC 65 ms
71,332 KB
testcase_22 AC 69 ms
71,316 KB
testcase_23 AC 66 ms
71,548 KB
testcase_24 AC 68 ms
71,508 KB
testcase_25 AC 67 ms
71,468 KB
testcase_26 AC 69 ms
71,304 KB
testcase_27 AC 67 ms
71,472 KB
testcase_28 AC 69 ms
71,092 KB
testcase_29 AC 69 ms
71,136 KB
testcase_30 AC 68 ms
71,608 KB
testcase_31 AC 68 ms
71,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
A = [int(input()) for _ in range(n)]
se = set(A)

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