結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,352 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 98 ms
93,792 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 58 ms
72,960 KB
testcase_09 AC 77 ms
89,856 KB
testcase_10 AC 79 ms
87,672 KB
testcase_11 AC 81 ms
90,124 KB
testcase_12 WA -
testcase_13 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def is_ok(n,s):
  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:
        return True
  return False

def solve():
  n=int(input())
  s=list(input())
  s2=[]
  for i in s:
    if i=='0':
      s2.append('1')
    elif i=='1':
      s2.append('0')
    else:
      s2.append('?')
  if is_ok(n,s) or is_ok(n,s2):
    print('Yes')
  else:
    print('No')

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