結果
| 問題 |
No.2036 Max Middle
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 19:07:28 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 914 bytes |
| コンパイル時間 | 244 ms |
| コンパイル使用メモリ | 81,968 KB |
| 実行使用メモリ | 301,612 KB |
| 最終ジャッジ日時 | 2025-06-12 19:07:33 |
| 合計ジャッジ時間 | 4,603 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / 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
q = deque()
for i in range(N-2):
if A[i] < A[i+1] and A[i+1] > A[i+2]:
q.append(i)
operations = 0
while q:
i = q.popleft()
left = A[i]
right = A[i+2]
min_val = min(left, right)
A[i+1] = min_val - 1
operations += 1
# Check i-1
if i - 1 >= 0:
j = i - 1
if j <= N - 3:
if A[j] < A[j+1] and A[j+1] > A[j+2]:
q.append(j)
# Check i+1
j = i + 1
if j <= N - 3:
if A[j] < A[j+1] and A[j+1] > A[j+2]:
q.append(j)
print(operations)
if __name__ == "__main__":
main()
gew1fw