結果
問題 | No.2283 Prohibit Three Consecutive |
ユーザー | buey_t |
提出日時 | 2023-04-28 22:09:10 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,676 bytes |
コンパイル時間 | 167 ms |
コンパイル使用メモリ | 82,248 KB |
実行使用メモリ | 144,820 KB |
最終ジャッジ日時 | 2024-11-17 21:06:07 |
合計ジャッジ時間 | 5,199 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 129 ms
89,584 KB |
testcase_01 | AC | 128 ms
89,412 KB |
testcase_02 | AC | 130 ms
89,580 KB |
testcase_03 | AC | 341 ms
144,820 KB |
testcase_04 | AC | 344 ms
133,372 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 219 ms
118,484 KB |
testcase_09 | AC | 220 ms
118,460 KB |
testcase_10 | AC | 229 ms
118,632 KB |
testcase_11 | AC | 235 ms
118,624 KB |
testcase_12 | WA | - |
testcase_13 | WA | - |
ソースコード
from math import sqrt,sin,cos,tan,ceil,radians,floor,gcd,exp,log,log10,log2,factorial,fsum from heapq import heapify, heappop, heappush from bisect import bisect_left, bisect_right from copy import deepcopy import copy import random from random import randrange from collections import deque,Counter,defaultdict from itertools import permutations,combinations from decimal import Decimal,ROUND_HALF_UP #tmp = Decimal(mid).quantize(Decimal('0'), rounding=ROUND_HALF_UP) from functools import lru_cache, reduce #@lru_cache(maxsize=None) from operator import add,sub,mul,xor,and_,or_,itemgetter import sys input = sys.stdin.readline # .rstrip() INF = 10**18 mod1 = 10**9+7 mod2 = 998244353 #DecimalならPython #再帰ならPython!!!!!!!!!!!!!!!!!!!!!!!!!! ''' dpだとは思う 直前の二個を記録すればいいかな ''' for _ in range(int(input())): N = int(input()) S = list(input().rstrip()) dp = [[[0]*2 for _ in range(2)] for _ in range(N+1)] for i in range(2): for j in range(2): dp[0][i][j] = 1 for i in range(1,N+1): if S[i-1] == '0': for j in range(2): dp[i][j][0] = max(dp[i][j][0], dp[i-1][1][j]) dp[i][1][0] = max(dp[i][1][0], dp[i-1][0][1]) elif S[i-1] == '1': for j in range(2): dp[i][j][1] = max(dp[i][j][1], dp[i-1][0][j]) dp[i][0][1] = max(dp[i][0][1], dp[i-1][1][0]) else: for j in range(2): dp[i][j][0] = max(dp[i][j][0], dp[i-1][1][j]) dp[i][j][1] = max(dp[i][j][1], dp[i-1][0][j]) dp[i][1][0] = max(dp[i][1][0], dp[i-1][0][1]) dp[i][0][1] = max(dp[i][0][1], dp[i-1][1][0]) f = 0 if S[0] == '1': if S[1] == '1': if dp[N][0][0] == 1 or dp[N][1][0] == 1: f = 1 else: if dp[N][0][1] == 1 or dp[N][1][0] == 1 or dp[N][0][0] == 1: f = 1 elif S[0] == '0': if S[1] == '0': if dp[N][1][1] == 1 or dp[N][0][1] == 1: f = 1 else: if dp[N][0][1] == 1 or dp[N][1][0] == 1 or dp[N][1][1] == 1: f = 1 else: if S[1] == '1': if dp[N][0][1] == 1 or dp[N][1][0] == 1 or dp[N][0][0] == 1: f = 1 elif S[1] == '0': if dp[N][0][1] == 1 or dp[N][1][0] == 1 or dp[N][1][1] == 1: f = 1 else: if dp[N][0][1] == 1 or dp[N][1][0] == 1 or dp[N][0][0] == 1 or dp[N][1][1] == 1: f = 1 if f: print('Yes') else: print('No')