結果

問題 No.1687 What the Heck?
ユーザー roarisroaris
提出日時 2021-09-24 21:34:56
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 519 bytes
コンパイル時間 1,191 ms
コンパイル使用メモリ 87,128 KB
実行使用メモリ 108,580 KB
最終ジャッジ日時 2023-09-18 20:51:02
合計ジャッジ時間 4,342 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 97 ms
71,672 KB
testcase_01 AC 99 ms
71,644 KB
testcase_02 WA -
testcase_03 AC 96 ms
71,576 KB
testcase_04 AC 96 ms
71,516 KB
testcase_05 AC 97 ms
71,704 KB
testcase_06 AC 96 ms
71,572 KB
testcase_07 AC 117 ms
86,392 KB
testcase_08 AC 120 ms
91,500 KB
testcase_09 WA -
testcase_10 AC 113 ms
82,508 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 150 ms
108,248 KB
testcase_14 AC 151 ms
108,268 KB
testcase_15 AC 151 ms
108,580 KB
testcase_16 AC 148 ms
108,188 KB
testcase_17 AC 106 ms
77,376 KB
testcase_18 AC 145 ms
108,244 KB
testcase_19 AC 104 ms
77,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import *

N = int(input())
P = list(map(int, input().split()))
flag = [False]*N
ans = 0

for i in range(N-1, -1, -1):
    P[i] -= 1
    
    if P[i]==N-1:
        if flag[N-1]:
            ans -= i+1
        else:
            flag[N-1] = True
    else:
        if flag[P[i]+1]:
            if flag[P[i]]:
                ans -= i+1
            else:
                flag[P[i]] = True
        else:
            flag[P[i]+1] = True
            ans += i+1

print(ans)
0