結果
問題 | No.2283 Prohibit Three Consecutive |
ユーザー | Shirotsume |
提出日時 | 2023-04-28 23:34:51 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,266 bytes |
コンパイル時間 | 335 ms |
コンパイル使用メモリ | 82,040 KB |
実行使用メモリ | 379,056 KB |
最終ジャッジ日時 | 2024-11-17 22:27:15 |
合計ジャッジ時間 | 22,635 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
62,520 KB |
testcase_01 | AC | 87 ms
356,432 KB |
testcase_02 | AC | 55 ms
71,000 KB |
testcase_03 | TLE | - |
testcase_04 | TLE | - |
testcase_05 | TLE | - |
testcase_06 | TLE | - |
testcase_07 | AC | 53 ms
64,144 KB |
testcase_08 | AC | 965 ms
279,132 KB |
testcase_09 | TLE | - |
testcase_10 | TLE | - |
testcase_11 | TLE | - |
testcase_12 | AC | 307 ms
78,984 KB |
testcase_13 | AC | 570 ms
87,228 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[:3] + p[-3:])) 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] * 2 for _ in range(2)] for _ in range(n + 1)] if a[0] == a[1] == -1: if a[2] != 0: dp[2][0][0] = 1 dp[2][0][1] = 1 dp[2][1][0] = 1 if a[2] != 1: dp[2][1][1] = 1 elif a[0] == -1: if not a[1] == a[2] == 0: dp[2][0][a[1]] = 1 if not a[1] == a[2] == 1: dp[2][1][a[1]] = 1 elif a[1] == -1: if not a[0] == a[2] == 0: dp[2][a[0]][0] = 1 if not a[0] == a[2] == 1: dp[2][a[0]][1] = 1 else: if not a[0] == a[1] == a[2]: dp[2][a[0]][a[1]] = 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[i + 1][k][1 - k] |= dp[i][j][k] else: dp[i + 1][k][0] |= dp[i][j][k] dp[i + 1][k][1] |= dp[i][j][k] else: if j == k == a[i]: pass else: dp[i + 1][k][a[i]] |= dp[i][j][k] 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[2][a1][a2] and dp[n][b1][b2]: print('Yes') return print('No') for _ in range(ii()): solve()