結果
問題 | No.2283 Prohibit Three Consecutive |
ユーザー | aaaaaaaaaa2230 |
提出日時 | 2023-04-28 22:49:03 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 343 ms / 2,000 ms |
コード長 | 1,274 bytes |
コンパイル時間 | 317 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 78,780 KB |
最終ジャッジ日時 | 2024-04-29 00:12:43 |
合計ジャッジ時間 | 2,904 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
51,968 KB |
testcase_01 | AC | 44 ms
52,224 KB |
testcase_02 | AC | 45 ms
52,352 KB |
testcase_03 | AC | 82 ms
76,800 KB |
testcase_04 | AC | 85 ms
76,544 KB |
testcase_05 | AC | 316 ms
78,780 KB |
testcase_06 | AC | 298 ms
78,720 KB |
testcase_07 | AC | 44 ms
51,840 KB |
testcase_08 | AC | 93 ms
76,672 KB |
testcase_09 | AC | 96 ms
76,672 KB |
testcase_10 | AC | 96 ms
77,184 KB |
testcase_11 | AC | 101 ms
76,928 KB |
testcase_12 | AC | 313 ms
77,956 KB |
testcase_13 | AC | 343 ms
78,500 KB |
ソースコード
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())