結果

問題 No.2518 Adjacent Larger
ユーザー 👑 KA37RI
提出日時 2023-10-28 00:27:13
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 536 bytes
コンパイル時間 294 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 15,656 KB
最終ジャッジ日時 2024-09-25 15:46:38
合計ジャッジ時間 3,775 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 18 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

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]
		if a[j] == 0 and left[j] or a[j] == 2 and not left[j]:
			return False
		right[j] = (a[j] - left[j]) > 0
	return True

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")
0