結果
問題 | No.2283 Prohibit Three Consecutive |
ユーザー |
|
提出日時 | 2023-07-06 23:40:29 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 49 ms / 2,000 ms |
コード長 | 1,038 bytes |
コンパイル時間 | 1,021 ms |
コンパイル使用メモリ | 98,564 KB |
最終ジャッジ日時 | 2025-02-15 06:28:55 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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の終了 }