結果

問題 No.2283 Prohibit Three Consecutive
ユーザー tassei903tassei903
提出日時 2023-04-29 15:17:35
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,355 bytes
コンパイル時間 217 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 103,552 KB
最終ジャッジ日時 2024-04-29 09:01:07
合計ジャッジ時間 2,630 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,224 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 97 ms
90,368 KB
testcase_09 AC 97 ms
90,368 KB
testcase_10 WA -
testcase_11 AC 95 ms
91,008 KB
testcase_12 WA -
testcase_13 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################################################

def f(x):
    if x == "0":
        return [0]
    elif x == "1":
        return [1]
    else:
        return [0,1]

for _ in range(ni()):
    n = ni()
    s = input()
    ok = 0
    for a in f(s[0]):
        for b in f(s[1]):
            dp = [[0] * 8 for i in range(n-2)]
            dp[0][a * 2 + b] = 1
            for i in range(n-3):
                for j in range(4):
                    if dp[i][j] ^ 1:
                        continue
                    nj = j % 2
                    for k in f(s[i+3]):
                        if j * 2 + k == 0 or j * 2 + k == 7:continue
                        nj = nj * 2 + k
                        dp[i+1][nj] = 1
                dp[i+1][0] = 0
                dp[i+1][-1] = 0


            for j in range(4):
                if (j % 2) + a * 4 + b * 2 in [0, 7]:continue
                if dp[-1][j]:
                    ok = 1
            if ok:
                break
        if ok:
            break
    if ok:
        Yes()
    else:
        No()
0