結果

問題 No.2283 Prohibit Three Consecutive
ユーザー とりゐとりゐ
提出日時 2023-04-28 22:26:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 321 ms / 2,000 ms
コード長 732 bytes
コンパイル時間 400 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 96,256 KB
最終ジャッジ日時 2024-04-28 23:56:35
合計ジャッジ時間 2,718 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
51,968 KB
testcase_01 AC 43 ms
51,968 KB
testcase_02 AC 44 ms
51,968 KB
testcase_03 AC 129 ms
91,208 KB
testcase_04 AC 125 ms
96,256 KB
testcase_05 AC 255 ms
78,632 KB
testcase_06 AC 257 ms
77,952 KB
testcase_07 AC 43 ms
52,352 KB
testcase_08 AC 64 ms
72,960 KB
testcase_09 AC 72 ms
79,232 KB
testcase_10 AC 95 ms
90,240 KB
testcase_11 AC 79 ms
78,976 KB
testcase_12 AC 258 ms
78,380 KB
testcase_13 AC 321 ms
78,568 KB
権限があれば一括ダウンロードができます

ソースコード

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=[inf,1]
      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[0]<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