結果

問題 No.2283 Prohibit Three Consecutive
ユーザー 👑 rin204rin204
提出日時 2024-04-29 21:12:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 290 ms / 2,000 ms
コード長 1,271 bytes
コンパイル時間 143 ms
コンパイル使用メモリ 82,364 KB
実行使用メモリ 78,308 KB
最終ジャッジ日時 2024-04-29 21:12:37
合計ジャッジ時間 3,003 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,352 KB
testcase_01 AC 39 ms
52,936 KB
testcase_02 AC 37 ms
52,224 KB
testcase_03 AC 129 ms
76,600 KB
testcase_04 AC 150 ms
76,416 KB
testcase_05 AC 267 ms
78,308 KB
testcase_06 AC 290 ms
77,752 KB
testcase_07 AC 37 ms
51,968 KB
testcase_08 AC 78 ms
75,904 KB
testcase_09 AC 94 ms
76,208 KB
testcase_10 AC 82 ms
76,160 KB
testcase_11 AC 96 ms
76,160 KB
testcase_12 AC 238 ms
78,196 KB
testcase_13 AC 286 ms
77,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve():
    n = int(input())
    S = input()

    for i in range(2):
        for j in range(2):
            dp = [False] * 4
            if str(1 - i) == S[0] or str(1 - j) == S[1]:
                continue
            dp[2 * i + j] = True
            for s in S[2:]:
                ndp = [False] * 4
                if s != "1":
                    nex = 0
                    for ii in range(2):
                        for jj in range(2):
                            if nex == ii == jj:
                                continue
                            ndp[2 * jj + nex] |= dp[2 * ii + jj]
                if s != "0":
                    nex = 1
                    for ii in range(2):
                        for jj in range(2):
                            if nex == ii == jj:
                                continue
                            ndp[2 * jj + nex] |= dp[2 * ii + jj]
                dp = ndp

            for ii in range(2):
                for jj in range(2):
                    if ii == jj == i or jj == i == j:
                        continue
                    if dp[2 * ii + jj]:
                        return True

    return False


for _ in range(int(input())):
    if solve():
        print("Yes")
    else:
        print("No")
0