結果

問題 No.2089 置換の符号
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-09-30 22:15:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 346 bytes
コンパイル時間 1,025 ms
コンパイル使用メモリ 86,812 KB
実行使用メモリ 76,416 KB
最終ジャッジ日時 2023-08-24 15:49:33
合計ジャッジ時間 4,116 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,308 KB
testcase_01 AC 70 ms
71,420 KB
testcase_02 AC 71 ms
70,960 KB
testcase_03 AC 71 ms
71,164 KB
testcase_04 AC 70 ms
71,168 KB
testcase_05 AC 70 ms
71,216 KB
testcase_06 AC 70 ms
71,268 KB
testcase_07 AC 69 ms
71,148 KB
testcase_08 AC 70 ms
71,224 KB
testcase_09 AC 70 ms
71,276 KB
testcase_10 AC 71 ms
71,272 KB
testcase_11 AC 71 ms
71,332 KB
testcase_12 AC 70 ms
71,308 KB
testcase_13 AC 70 ms
71,116 KB
testcase_14 AC 70 ms
71,404 KB
testcase_15 AC 70 ms
71,224 KB
testcase_16 AC 71 ms
71,428 KB
testcase_17 AC 70 ms
71,248 KB
testcase_18 AC 70 ms
71,264 KB
testcase_19 AC 71 ms
71,096 KB
testcase_20 AC 70 ms
71,088 KB
testcase_21 AC 71 ms
71,096 KB
testcase_22 AC 70 ms
71,260 KB
testcase_23 AC 71 ms
71,248 KB
testcase_24 AC 71 ms
71,092 KB
testcase_25 AC 72 ms
71,100 KB
testcase_26 AC 72 ms
71,096 KB
testcase_27 AC 78 ms
76,308 KB
testcase_28 AC 78 ms
76,400 KB
testcase_29 AC 78 ms
76,416 KB
testcase_30 AC 77 ms
76,396 KB
testcase_31 AC 80 ms
76,056 KB
testcase_32 AC 77 ms
76,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
A = [int(x)-1 for x in input().split()]

sign = 1

done = [0]*n

for i in range(n):
    if done[i]:
        continue
    now = i
    count = 0
    done[i] = 1
    while True:
        now = A[now]
        count += 1
        if now == i:
            break
        done[now] = 1
    if (count-1) % 2:
        sign *= -1

print(sign)
0