結果

問題 No.2283 Prohibit Three Consecutive
ユーザー rlangevinrlangevin
提出日時 2023-04-28 21:49:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 526 ms / 2,000 ms
コード長 1,170 bytes
コンパイル時間 219 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 173,704 KB
最終ジャッジ日時 2024-04-28 23:27:22
合計ジャッジ時間 4,466 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
52,096 KB
testcase_01 AC 54 ms
61,184 KB
testcase_02 AC 53 ms
60,672 KB
testcase_03 AC 526 ms
173,704 KB
testcase_04 AC 523 ms
170,096 KB
testcase_05 AC 292 ms
77,696 KB
testcase_06 AC 293 ms
77,696 KB
testcase_07 AC 43 ms
52,096 KB
testcase_08 AC 263 ms
128,488 KB
testcase_09 AC 268 ms
128,356 KB
testcase_10 AC 278 ms
128,640 KB
testcase_11 AC 285 ms
128,744 KB
testcase_12 AC 221 ms
77,832 KB
testcase_13 AC 369 ms
78,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline

T = int(readline())
for _ in range(T):
    N = int(readline())
    S = list(input().rstrip("\n"))
    dp = [[[0] * 4 for i in range(4)] for j in range(N + 1)]
    for i in range(4):
        dp[0][i][i] = 1
    for k in range(4):
        for i in range(N):
            for s in range(4):
                if S[i] == "0":
                    if s == 0:
                        continue
                    nex = s % 2 * 2
                    dp[i + 1][nex][k] |= dp[i][s][k]
                elif S[i] == "1":
                    if s == 3:
                        continue
                    nex = s % 2 * 2 + 1
                    dp[i + 1][nex][k] |= dp[i][s][k]
                else:
                    if s != 0:
                        nex = s % 2 * 2
                        dp[i + 1][nex][k] |= dp[i][s][k]
                    if s != 3:
                        nex = s % 2 * 2 + 1
                        dp[i + 1][nex][k] |= dp[i][s][k]
                        
    ans = 0
    for i in range(4):
        ans |= dp[N][i][i]
    print("Yes") if ans else print("No")
                    
                
                 
0