結果

問題 No.2518 Adjacent Larger
ユーザー 👑 KA37RIKA37RI
提出日時 2023-10-28 00:36:33
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 160 ms / 2,000 ms
コード長 582 bytes
コンパイル時間 297 ms
コンパイル使用メモリ 11,924 KB
実行使用メモリ 14,820 KB
最終ジャッジ日時 2023-10-28 00:36:37
合計ジャッジ時間 4,029 ms
ジャッジサーバーID
(参考情報)
judge10 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,008 KB
testcase_01 AC 135 ms
10,024 KB
testcase_02 AC 134 ms
10,024 KB
testcase_03 AC 160 ms
10,024 KB
testcase_04 AC 135 ms
10,024 KB
testcase_05 AC 133 ms
10,024 KB
testcase_06 AC 51 ms
10,040 KB
testcase_07 AC 52 ms
10,036 KB
testcase_08 AC 52 ms
10,036 KB
testcase_09 AC 51 ms
10,040 KB
testcase_10 AC 51 ms
10,040 KB
testcase_11 AC 42 ms
10,160 KB
testcase_12 AC 46 ms
10,140 KB
testcase_13 AC 45 ms
10,144 KB
testcase_14 AC 43 ms
10,148 KB
testcase_15 AC 44 ms
10,156 KB
testcase_16 AC 109 ms
14,820 KB
testcase_17 AC 74 ms
12,536 KB
testcase_18 AC 76 ms
12,552 KB
testcase_19 AC 65 ms
12,308 KB
testcase_20 AC 85 ms
13,408 KB
testcase_21 AC 70 ms
14,816 KB
testcase_22 AC 70 ms
14,816 KB
testcase_23 AC 109 ms
14,816 KB
testcase_24 AC 104 ms
14,464 KB
testcase_25 AC 109 ms
14,816 KB
testcase_26 AC 108 ms
14,816 KB
testcase_27 AC 73 ms
14,816 KB
testcase_28 AC 107 ms
14,816 KB
権限があれば一括ダウンロードができます

ソースコード

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