結果

問題 No.2283 Prohibit Three Consecutive
ユーザー 沙耶花沙耶花
提出日時 2023-04-28 21:25:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 1,045 bytes
コンパイル時間 4,422 ms
コンパイル使用メモリ 262,572 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-28 23:07:02
合計ジャッジ時間 5,467 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 36 ms
5,376 KB
testcase_04 AC 46 ms
5,376 KB
testcase_05 AC 53 ms
5,376 KB
testcase_06 AC 54 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 44 ms
5,376 KB
testcase_09 AC 22 ms
5,376 KB
testcase_10 AC 22 ms
5,376 KB
testcase_11 AC 22 ms
5,376 KB
testcase_12 AC 32 ms
5,376 KB
testcase_13 AC 68 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001

int main(){
	
	int _t;
	cin>>_t;
	rep(_,_t){
		int n;
		cin>>n;
		string s;
		cin>>s;
		bool f = false;
		rep(i,2){
			rep(j,2){
				if(s[0]!='?'&&s[0]!='0'+i)continue;
				if(s[1]!='?'&&s[1]!='0'+j)continue;
				vector dp(2,vector<int>(2,0));
				dp[i][j] = 1;
				for(int k=2;k<n;k++){
					vector ndp(2,vector<int>(2,0));
					rep(ii,2){
						rep(jj,2){
							if(dp[ii][jj]){
								rep(kk,2){
									if(s[k]!='?'&&s[k]!='0'+kk)continue;
									if(ii==jj&&ii==kk)continue;
									ndp[jj][kk] = 1;
								}
							}
						}
					}
					swap(dp,ndp);
				}
				rep(k,2){
					rep(l,2){
						if(dp[k][l]){
							if(k==l&&k==i)continue;
							if(l==i&&l==j)continue;
							f = true;
						}
					}
				}
			}
		}
		if(f)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	
	return 0;
}
0