結果

問題 No.1687 What the Heck?
ユーザー shinichishinichi
提出日時 2021-09-24 23:09:50
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 394 bytes
コンパイル時間 410 ms
コンパイル使用メモリ 87,240 KB
実行使用メモリ 110,644 KB
最終ジャッジ日時 2023-09-18 22:17:38
合計ジャッジ時間 3,620 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,228 KB
testcase_01 AC 77 ms
71,340 KB
testcase_02 WA -
testcase_03 AC 75 ms
71,436 KB
testcase_04 AC 75 ms
71,420 KB
testcase_05 AC 73 ms
71,316 KB
testcase_06 AC 73 ms
71,432 KB
testcase_07 AC 103 ms
95,400 KB
testcase_08 AC 111 ms
104,684 KB
testcase_09 WA -
testcase_10 AC 95 ms
89,252 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 145 ms
110,604 KB
testcase_14 AC 141 ms
110,584 KB
testcase_15 AC 144 ms
110,644 KB
testcase_16 AC 142 ms
110,432 KB
testcase_17 AC 80 ms
77,548 KB
testcase_18 AC 142 ms
110,564 KB
testcase_19 AC 77 ms
76,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
P = list(map(int, input().split()))

total = 0
used = set()
for i in range(N-1, -1, -1):
    p = P[i]
    if p != N and p+1 not in used:
        total += i+1
        used.add(p+1)
    elif p not in used:
        used.add(p)
    else:
        total -= i+1
        for j in range(1, N):
            if j not in used:
                used.add(j)
                break
print(total)
0