結果
| 問題 |
No.2036 Max Middle
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 21:11:26 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 975 bytes |
| コンパイル時間 | 241 ms |
| コンパイル使用メモリ | 81,920 KB |
| 実行使用メモリ | 53,632 KB |
| 最終ジャッジ日時 | 2025-06-12 21:12:57 |
| 合計ジャッジ時間 | 4,195 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 4 TLE * 1 -- * 12 |
ソースコード
import sys
from collections import deque
def main():
input = sys.stdin.read().split()
N = int(input[0])
A = list(map(int, input[1:N+1]))
if N < 3:
print(0)
return
dq = deque()
# Identify initial peaks
for j in range(1, N-1):
if A[j-1] < A[j] and A[j] > A[j+1]:
dq.append(j)
operations = 0
while dq:
j = dq.popleft()
# Check if j is still a peak
if j <= 0 or j >= N-1:
continue
if not (A[j-1] < A[j] and A[j] > A[j+1]):
continue
# Process the peak
new_val = min(A[j-1], A[j+1]) - 1
A[j] = new_val
operations += 1
# Check left and right neighbors
for k in [j-1, j+1]:
if 1 <= k <= N-2:
if A[k-1] < A[k] and A[k] > A[k+1]:
dq.append(k)
print(operations)
if __name__ == "__main__":
main()
gew1fw