結果

問題 No.2283 Prohibit Three Consecutive
ユーザー Nzt3Nzt3
提出日時 2023-04-28 21:54:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 1,090 bytes
コンパイル時間 2,102 ms
コンパイル使用メモリ 201,532 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-28 23:30:28
合計ジャッジ時間 2,792 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 8 ms
5,376 KB
testcase_04 AC 10 ms
5,376 KB
testcase_05 AC 10 ms
5,376 KB
testcase_06 AC 10 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 6 ms
5,376 KB
testcase_13 AC 10 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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");
  }
}
0