結果

問題 No.2036 Max Middle
ユーザー taiga0629kyopro
提出日時 2022-08-12 21:48:00
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 310 bytes
コンパイル時間 163 ms
コンパイル使用メモリ 82,032 KB
実行使用メモリ 103,620 KB
最終ジャッジ日時 2024-09-23 02:03:47
合計ジャッジ時間 4,165 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 4 TLE * 1 -- * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())
a=[10**12]+list(map(int,input().split()))+[10**12]
s=[]
def ok(i):
    return a[i-1]<a[i] and a[i]>a[i+1]
for i in range(1,n+1):
    if ok(i):s.append(i)
ans=0
while s:
    i=s.pop()
    ans+=1
    a[i]=min(a[i-1],a[i+1])-1
    if ok(i-1):s.append(i-1)
    if ok(i+1):s.append(i+1)
print(ans)

0