結果
問題 | No.2283 Prohibit Three Consecutive |
ユーザー | Shirotsume |
提出日時 | 2023-04-28 23:39:39 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 493 ms / 2,000 ms |
コード長 | 2,269 bytes |
コンパイル時間 | 146 ms |
コンパイル使用メモリ | 82,236 KB |
実行使用メモリ | 144,324 KB |
最終ジャッジ日時 | 2024-11-17 22:29:25 |
合計ジャッジ時間 | 4,237 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 47 ms
55,436 KB |
testcase_01 | AC | 59 ms
65,848 KB |
testcase_02 | AC | 47 ms
62,088 KB |
testcase_03 | AC | 485 ms
144,324 KB |
testcase_04 | AC | 493 ms
125,432 KB |
testcase_05 | AC | 458 ms
79,052 KB |
testcase_06 | AC | 457 ms
79,280 KB |
testcase_07 | AC | 45 ms
54,880 KB |
testcase_08 | AC | 94 ms
86,836 KB |
testcase_09 | AC | 280 ms
139,952 KB |
testcase_10 | AC | 132 ms
96,660 KB |
testcase_11 | AC | 285 ms
139,932 KB |
testcase_12 | AC | 269 ms
78,888 KB |
testcase_13 | AC | 339 ms
79,420 KB |
ソースコード
import sys from collections import deque, Counter input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 63 - 1 mod = 998244353 def solve(): n = ii() s = [-1 if v == '?' else int(v) for v in input()] p = [] for i in range(n): if s[i] == -1: p.append(i) p = list(set(p[:2] + p[-2:])) m = len(p) for bit in range(1 << m): a = s[::] for i in range(m): if 1 & (bit >> i): a[p[i]] = 1 else: a[p[i]] = 0 dp = [[[0] * (n + 1) for _ in range(2)] for _ in range(2)] if a[0] == a[1] == -1: if a[2] != 0: dp[0][0][2] = 1 dp[0][1][2] = 1 dp[1][0][2] = 1 if a[2] != 1: dp[1][1][2] = 1 elif a[0] == -1: if not a[1] == a[2] == 0: dp[0][a[1]][2] = 1 if not a[1] == a[2] == 1: dp[1][a[1]][2] = 1 elif a[1] == -1: if not a[0] == a[2] == 0: dp[a[0]][0][2] = 1 if not a[0] == a[2] == 1: dp[a[0]][1][2] = 1 else: if not a[0] == a[1] == a[2]: dp[a[0]][a[1]][2] = 1 for i in range(2, n): for j in range(2): for k in range(2): if a[i] == -1: if j == k: dp[k][1 - k][i + 1] |= dp[j][k][i] else: dp[k][0][i + 1] |= dp[j][k][i] dp[k][1][i + 1] |= dp[j][k][i] else: if j == k == a[i]: pass else: dp[k][a[i]][i + 1] |= dp[j][k][i] for a1 in range(2): for a2 in range(2): for b1 in range(2): for b2 in range(2): if not((a1 == a2 == b2) or (a1 == b1 == b2)) and dp[a1][a2][2] and dp[b1][b2][n]: print('Yes') return print('No') for _ in range(ii()): solve()