結果

問題 No.2283 Prohibit Three Consecutive
ユーザー とりゐとりゐ
提出日時 2023-04-28 22:18:17
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 537 bytes
コンパイル時間 671 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 83,456 KB
最終ジャッジ日時 2024-04-28 23:49:59
合計ジャッジ時間 2,799 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 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 56 ms
64,640 KB
testcase_09 WA -
testcase_10 AC 79 ms
83,456 KB
testcase_11 AC 63 ms
72,192 KB
testcase_12 WA -
testcase_13 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve():
  n=int(input())
  s=list(input())
  inf=10**9
  for i in range(3):
    if s[i]!='0' and s[i-1]!='1':
      t=s[i:]+s[:i]
      dp=[1,inf]
      for j in range(1,n):
        ndp=[inf,inf]
        if t[j]=='0' or t[j]=='?':
          ndp[0]=dp[0]+1
          if dp[1]<3:
            ndp[0]=1
        if t[j]=='1' or t[j]=='?':
          ndp[1]=dp[1]+1
          if dp[0]<3:
            ndp[1]=1
        dp=ndp
      if dp[1]<3:
        print('Yes')
        return
      
  print('No')

for _ in range(int(input())):
  solve()
0