結果
| 問題 |
No.2283 Prohibit Three Consecutive
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-04-28 23:17:18 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,410 bytes |
| コンパイル時間 | 929 ms |
| コンパイル使用メモリ | 83,400 KB |
| 最終ジャッジ日時 | 2025-02-12 15:37:22 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 7 WA * 6 |
ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}
void solve(){
int n;
string s;
cin>>n>>s;
rep(x,2)rep(y,2){
if((s[0]!='?'&&s[0]-'0'!=x)||(s[1]!='?'&&s[1]-'0'!=y))continue;
vector dp(n,vector<vector<bool>>(2,vector<bool>(2)));
dp[1][x][y]=true;
for(int i=2;i<n;i++){
if(s[i]!='0'){
dp[i][0][1]=dp[i-1][0][0]||dp[i-1][1][0];
dp[i][1][1]=dp[i-1][0][1];
}
if(s[i]!='1'){
dp[i][0][0]=dp[i-1][1][0];
dp[i][1][0]=dp[i-1][0][1]||dp[i-1][1][1];
}
}
bool flag=false;
rep(i,2)rep(j,2){
if(x==y&&y==j)continue;
if(y==i&&i==j)continue;
if(dp[n-1][i][j])flag=true;
}
if(flag){
cout<<"Yes"<<"\n";
return;
}
}
cout<<"No"<<"\n";
}
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
cin>>t;
while(t--){
solve();
}
}