結果

問題 No.2036 Max Middle
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-08-12 21:50:09
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 524 bytes
コンパイル時間 164 ms
コンパイル使用メモリ 81,800 KB
実行使用メモリ 117,156 KB
最終ジャッジ日時 2023-10-24 09:35:30
合計ジャッジ時間 4,408 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,552 KB
testcase_01 AC 39 ms
53,372 KB
testcase_02 AC 39 ms
53,372 KB
testcase_03 AC 39 ms
53,372 KB
testcase_04 AC 39 ms
53,372 KB
testcase_05 AC 40 ms
53,372 KB
testcase_06 AC 39 ms
53,372 KB
testcase_07 AC 40 ms
53,372 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush,heappop

n = int(input())
A = list(map(int,input().split()))
num = A[:]
done = [0]*n

h = []
for i,a in enumerate(A):
    heappush(h,[-a,i])

ans = 0
while h:
    c,ind = heappop(h)
    # print(c,ind)
    c = -c
    if ind == 0 or ind == n-1:
        done[ind] = 1   
        num[ind] = c
        continue

    if done[ind-1] == done[ind+1] == 0:
        ans += 1
        c = min(num[ind-1],num[ind+1])-1
        num[ind] = c
        heappush(h,[-c,ind])
    else:
        done[ind] = 1
print(ans)
0