結果
| 問題 |
No.2283 Prohibit Three Consecutive
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-04-28 22:49:03 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 267 ms / 2,000 ms |
| コード長 | 1,274 bytes |
| コンパイル時間 | 179 ms |
| コンパイル使用メモリ | 82,432 KB |
| 実行使用メモリ | 78,824 KB |
| 最終ジャッジ日時 | 2024-11-17 21:45:59 |
| 合計ジャッジ時間 | 2,279 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 13 |
ソースコード
def solve():
n = int(input())
dic = {"0":0,"1":1,"?":2}
S = [dic[s] for s in input()]
# print(S)
for i in range(4):
a = i//2
b = i&1
if S[0] != a and S[0] != 2:
continue
if S[1] != b and S[1] != 2:
continue
dp = [0]*4
dp[i] = 1
# print(i,dp,a,b)
for s in range(2,n+2):
if s < n:
x = S[s]
elif s == n:
x = a
else:
x = b
ndp = [0]*4
for j in range(4):
if dp[j] == 0:
continue
if j == 0:
if x != 0:
ndp[(j*2+1)%4] = 1
elif j == 3:
if x != 1:
ndp[(j*2)%4] = 1
else:
if x != 0:
ndp[(j*2+1)%4] = 1
if x != 1:
ndp[(j*2)%4] = 1
dp = ndp
# print(s,x,dp)
if sum(dp) == 0:
break
if dp[i]:
return "Yes"
return "No"
t = int(input())
for _ in range(t):
print(solve())