結果
| 問題 |
No.2283 Prohibit Three Consecutive
|
| コンテスト | |
| ユーザー |
Rubikun
|
| 提出日時 | 2023-04-28 21:29:34 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 12 ms / 2,000 ms |
| コード長 | 1,955 bytes |
| コンパイル時間 | 2,059 ms |
| コンパイル使用メモリ | 200,244 KB |
| 最終ジャッジ日時 | 2025-02-12 14:53:40 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 13 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=1<<30;
int main(){
std::ifstream in("text.txt");
std::cin.rdbuf(in.rdbuf());
cin.tie(0);
ios::sync_with_stdio(false);
int QQ;cin>>QQ;
while(QQ--){
int N;cin>>N;
string S;cin>>S;
queue<int> Q;
vector<int> seen(N);
for(int i=0;i<N;i++){
if(S[i]=='?') continue;
if(S[(i+1)%N]=='?') continue;
if(S[i]==S[(i+1)%N]){
seen[i]=true;
Q.push(i);
}
}
bool ok=true;
while(!Q.empty()){
int u=Q.front();Q.pop();
char to=char('0'+((int)(S[u]-'0')^1));
int v=(u+1)%N;
int L=(u+N-2)%N,R=(u+3)%N;
int l=(u+N-1)%N,r=(u+2)%N;
if(S[l]=='?') S[l]=to;
if(S[r]=='?') S[r]=to;
if(!seen[L]&&S[L]==S[l]){
seen[L]=true;
Q.push(L);
}
if(!seen[l]&&S[l]==S[u]){
seen[l]=true;
Q.push(l);
}
if(!seen[v]&&S[v]==S[r]){
seen[v]=true;
Q.push(v);
}
if(!seen[r]&&S[r]==S[R]){
seen[r]=true;
Q.push(r);
}
}
//cout<<S<<endl;
for(int i=0;i<N;i++){
int j=(i+1)%N,k=(i+2)%N;
if(S[i]!='?'&&(S[i]==S[j])&&(S[j]==S[k])) ok=false;
}
if(ok) cout<<"Yes\n";
else cout<<"No\n";
}
}
Rubikun