結果

問題 No.2283 Prohibit Three Consecutive
ユーザー sepa38sepa38
提出日時 2023-04-28 21:58:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 309 ms / 2,000 ms
コード長 819 bytes
コンパイル時間 263 ms
コンパイル使用メモリ 82,412 KB
実行使用メモリ 85,120 KB
最終ジャッジ日時 2024-04-28 23:34:49
合計ジャッジ時間 2,672 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,096 KB
testcase_01 AC 41 ms
52,352 KB
testcase_02 AC 41 ms
52,352 KB
testcase_03 AC 69 ms
81,536 KB
testcase_04 AC 79 ms
80,768 KB
testcase_05 AC 259 ms
77,824 KB
testcase_06 AC 261 ms
78,480 KB
testcase_07 AC 42 ms
51,968 KB
testcase_08 AC 86 ms
84,956 KB
testcase_09 AC 76 ms
84,480 KB
testcase_10 AC 93 ms
85,120 KB
testcase_11 AC 90 ms
84,864 KB
testcase_12 AC 285 ms
79,344 KB
testcase_13 AC 309 ms
78,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

for _ in range(int(input())):
  n = int(input())
  s = list(map(str, input()))
  ans = "Yes"
  for j in range(n):
    i = (j - 1) % n
    k = (j + 1) % n
    tmp = s[i] + s[j] + s[k]
    if tmp == "0" * 3 or tmp == "1" * 3:
      ans = "No"
      break
    if s[i] == s[j] != "?":
      s[k] = str(1-int(s[j]))
      continue
    elif s[i-1] == s[i] != "?" and s[j] == "?" and s[k] == s[(k+1)%n] != "?" and s[i] != s[k]:
      ans = "No"
      break
  for j in range(n):
    i = (j - 1) % n
    k = (j + 1) % n
    tmp = s[i] + s[j] + s[k]
    if tmp == "0" * 3 or tmp == "1" * 3:
      ans = "No"
      break
    if s[i] == s[j] != "?":
      s[k] = str(1-int(s[j]))
      continue
    elif s[i-1] == s[i] != "?" and s[j] == "?" and s[k] == s[(k+1)%n] != "?" and s[i] != s[k]:
      ans = "No"
      break
  print(ans)
0