結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
51,840 KB
testcase_01 AC 42 ms
51,968 KB
testcase_02 AC 42 ms
52,352 KB
testcase_03 AC 76 ms
77,312 KB
testcase_04 AC 86 ms
81,024 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 41 ms
51,968 KB
testcase_08 AC 55 ms
65,152 KB
testcase_09 AC 63 ms
74,624 KB
testcase_10 WA -
testcase_11 AC 65 ms
75,904 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]!='1' and s[i-1]!='0':
      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