結果
問題 | No.2283 Prohibit Three Consecutive |
ユーザー |
|
提出日時 | 2023-04-28 21:54:37 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 43 ms / 2,000 ms |
コード長 | 1,090 bytes |
コンパイル時間 | 1,936 ms |
コンパイル使用メモリ | 193,460 KB |
最終ジャッジ日時 | 2025-02-12 15:07:23 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 13 |
ソースコード
#include<bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin>>T; while(T--){ int N; cin>>N; string S; cin>>S; bool ok=false; for(int gh=0;gh<4;gh++){ if((gh&2)==0&&S[0]=='1')continue; if((gh&2)==2&&S[0]=='0')continue; if((gh&1)==0&&S[1]=='1')continue; if((gh&1)==1&&S[1]=='0')continue; array<bool,4>dp; for(int i=0;i<4;i++){dp[i]=false;} dp[gh]=true; for(int i=0;i<N;i++){ array<bool,4>dp2={false,false,false,false}; switch(S[(i+2)%N]){ case '?':{ dp2[0]=dp[2]; dp2[1]=(dp[0]||dp[2]); dp2[2]=(dp[1]||dp[3]); dp2[3]=dp[1]; break; } case '1':{ dp2[1]=(dp[0]||dp[2]); dp2[3]=dp[1]; break; } case '0':{ dp2[0]=dp[2]; dp2[2]=(dp[1]||dp[3]); } } dp=dp2; } if(dp[gh]){ ok=true; } } cout<<(ok?"Yes\n":"No\n"); } }