結果
| 問題 |
No.2518 Adjacent Larger
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-10-28 00:36:33 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 152 ms / 2,000 ms |
| コード長 | 582 bytes |
| コンパイル時間 | 555 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 15,328 KB |
| 最終ジャッジ日時 | 2024-09-25 15:48:40 |
| 合計ジャッジ時間 | 4,007 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 28 |
ソースコード
import sys
def solve(n, a):
left = [False] * n
right = [False] * n
idx2 = -1
for i in range(n):
if a[i] == 2:
idx2 = i
break
if idx2 == -1:
return False
left[idx2] = True
right[idx2] = True
for i in range(idx2 + 1, idx2 + n):
j = i % n
left[j] = not right[j-1]
r = a[j] - left[j]
if r < 0 or r > 1:
return False
else:
right[j] = (r == 1)
return left[idx2] and not right[idx2-1] or not left[idx2] and right[idx2-1]
t = int(input())
for _ in range(t):
n = int(input())
a = [int(x) for x in input().split()]
print("Yes" if solve(n, a) else "No")