結果

問題 No.2283 Prohibit Three Consecutive
ユーザー shobonvipshobonvip
提出日時 2023-04-28 21:39:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 1,293 bytes
コンパイル時間 4,523 ms
コンパイル使用メモリ 265,040 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-28 23:18:24
合計ジャッジ時間 5,209 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 24 ms
5,376 KB
testcase_04 AC 25 ms
5,376 KB
testcase_05 AC 35 ms
5,376 KB
testcase_06 AC 36 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 10 ms
5,376 KB
testcase_09 AC 10 ms
5,376 KB
testcase_10 AC 9 ms
5,376 KB
testcase_11 AC 9 ms
5,376 KB
testcase_12 AC 24 ms
5,376 KB
testcase_13 AC 50 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;

typedef modint998244353 mint;
typedef long long ll;

void solve(){
	int n; cin >> n;
	string s; cin >> s;
	vector<int> a(n);
	for (int i=0; i<n; i++){
		if (s[i] == '0') a[i] = 0;
		if (s[i] == '1') a[i] = 1;
		if (s[i] == '?') a[i] = 2;
	}
	// first prefix 3
	for (int num=1; num<7; num++){
		bool mode = true;
		for (int j=0; j<3; j++){
			if (num>>j&1){
				if (a[j] == 0) mode = false;
			}else{
				if (a[j] == 1) mode = false;
			}
		}
		if (!mode) continue;
		vector<bool> dp(8);
		dp[num] = true;
		for (int i=3; i<n; i++){
			vector<bool> ndp(8);
			for (int j=0; j<8; j++){
				if (!dp[j]) continue;
				int v = j>>1;
				if (a[i] == 0){
					if (v != 0) ndp[v] = true;
				}
				else if (a[i] == 1){
					if (v != 3) ndp[v+4] = true;
				}else{
					if (v != 0) ndp[v] = true;
					if (v != 3) ndp[v+4] = true;
				}
			}
			dp = ndp;
		}
		for (int x=1; x<7; x++){
			if (dp[x]){
				bool mode = true;
				if ((x>>2&1)==(num>>0&1) && (num>>0&1)==(num>>1&1)) mode = false;
				if ((x>>1&1)==(x>>2&1) && (x>>2&1)==(num>>0&1)) mode = false;
				if (mode){
					cout << "Yes\n";
					return;
				}
			}
		}
	}
	cout << "No\n";
	return;
}

int main(){
	int t; cin >> t;
	while(t--) solve();
}
0