結果

問題 No.1687 What the Heck?
ユーザー 👑 H20H20
提出日時 2021-09-24 21:57:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 618 bytes
コンパイル時間 286 ms
コンパイル使用メモリ 87,192 KB
実行使用メモリ 110,624 KB
最終ジャッジ日時 2023-09-18 21:18:03
合計ジャッジ時間 3,265 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,152 KB
testcase_01 AC 72 ms
71,224 KB
testcase_02 AC 71 ms
71,548 KB
testcase_03 AC 71 ms
71,368 KB
testcase_04 AC 71 ms
71,220 KB
testcase_05 AC 72 ms
71,396 KB
testcase_06 AC 74 ms
71,160 KB
testcase_07 AC 95 ms
86,660 KB
testcase_08 AC 102 ms
91,856 KB
testcase_09 AC 96 ms
86,536 KB
testcase_10 AC 90 ms
82,624 KB
testcase_11 AC 90 ms
82,716 KB
testcase_12 AC 130 ms
110,376 KB
testcase_13 AC 129 ms
110,624 KB
testcase_14 AC 123 ms
110,312 KB
testcase_15 AC 121 ms
110,064 KB
testcase_16 AC 122 ms
109,916 KB
testcase_17 AC 78 ms
76,344 KB
testcase_18 AC 122 ms
110,264 KB
testcase_19 AC 77 ms
76,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
P = list(map(int, input().split()))
if N == 1:
    print(0)
    exit()
if N == 2 and P[0]==1:
    print(0)
    exit()

i = P.index(N)+1
ans1 = N*(N+1)//2-i*2

P = P[::-1]
L = [0]*(N+1)
ans = 0
mi = 1
for i in range(N):
    p = P[i]
    for j in range(p+1,N+1):
        if L[j]==0:
            L[j]=1
            ans += N-i
            break
    else:
        if L[p]==0:
            L[p]=1
        else:
            for j in range(mi,N+1):
                if L[j]==0:
                    mi=j+1
                    L[j]=1

                    ans -= N-i
                    break
print(max(ans,ans1))
0