結果
| 問題 | No.2283 Prohibit Three Consecutive |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-07-06 23:40:29 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 26 ms / 2,000 ms |
| コード長 | 1,038 bytes |
| 記録 | |
| コンパイル時間 | 595 ms |
| コンパイル使用メモリ | 113,820 KB |
| 実行使用メモリ | 6,528 KB |
| 最終ジャッジ日時 | 2026-07-01 15:03:17 |
| 合計ジャッジ時間 | 1,595 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 13 |
ソースコード
#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<int,int> P;
typedef pair<int,P> PP;
const ll MOD=998244353;
const double PI=acos(-1);
bool solve(int N,string S){
for(int t=0;t<2;t++){
for(int i=0;i<2*N;i++){
if(S[i%N]!='?' && (S[i%N]==S[(i+1)%N] && S[(i+2)%N]=='?'))
{
S[(i+2)%N]=(char)((1-(S[i%N]-'0'))+'0');
}
}
reverse(S.begin(),S.end());
}
for(int i=0;i<N;i++){
if(S[i]!='?' && (S[i]==S[(i+1)%N] && S[(i+1)%N]==S[(i+2)%N]) ){
return false;
}
}
return true;
}
int main(){
int T;
cin>>T;
for(int t=0;t<T;t++){
int N;
cin>>N;
string S;
cin>>S;
bool flag=solve(N,S);
cout<<(flag?"Yes":"No")<<endl;
}//テストケースtの終了
}