結果
| 問題 |
No.2036 Max Middle
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 19:11:07 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 941 bytes |
| コンパイル時間 | 333 ms |
| コンパイル使用メモリ | 82,256 KB |
| 実行使用メモリ | 300,248 KB |
| 最終ジャッジ日時 | 2025-06-12 19:11:22 |
| 合計ジャッジ時間 | 4,344 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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):
j = i + 1
if A[i] < A[j] and A[j] > A[j+1]:
q.append(j)
count = 0
while q:
j = q.popleft()
if j < 1 or j >= len(A) - 1:
continue
if not (A[j-1] < A[j] and A[j] > A[j+1]):
continue
m = min(A[j-1], A[j+1])
A[j] = m - 1
count += 1
i_new = j - 2
if i_new >= 0:
if A[i_new] < A[j-1] and A[j-1] > A[j]:
q.append(j-1)
i_new = j
if i_new <= len(A) - 3:
if A[i_new] < A[j+1] and A[j+1] > A[j+2]:
q.append(j+1)
print(count)
if __name__ == '__main__':
main()
gew1fw