結果

問題 No.2283 Prohibit Three Consecutive
ユーザー cureskolcureskol
提出日時 2023-04-25 21:55:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 494 ms / 2,000 ms
コード長 1,026 bytes
コンパイル時間 2,133 ms
コンパイル使用メモリ 214,888 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-27 05:22:38
合計ジャッジ時間 3,896 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 4 ms
6,944 KB
testcase_04 AC 4 ms
6,944 KB
testcase_05 AC 75 ms
6,940 KB
testcase_06 AC 84 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 494 ms
6,940 KB
testcase_09 AC 26 ms
6,944 KB
testcase_10 AC 17 ms
6,944 KB
testcase_11 AC 19 ms
6,944 KB
testcase_12 AC 31 ms
6,944 KB
testcase_13 AC 71 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)

string solve(){
  int n;cin>>n;
  string s;cin>>s;

  set<pair<string,string>> se;
  REP(i,2)REP(j,2){
    string t=s.substr(0,2);
    if(t[0]!='0'+(i^1))t[0]='0'+i;
    if(t[1]!='0'+(j^1))t[1]='0'+j;
    se.emplace(t,t);
  }

  for(int i=2;i<n;i++){
    set<pair<string,string>> nxt;
    for(auto it=se.begin();it!=se.end();it=se.erase(it)){
      auto [a,b]=*it;
      b += "!";
      REP(j,2){
        if(s[i] == '0'+(j^1))continue;
        b[2]='0'+j;
        if(b=="000" or b=="111")continue;
        nxt.emplace(a,b.substr(1));
      }
    }
    se=nxt;
  }

  for(auto it=se.begin();it!=se.end();it=se.erase(it)){
    auto [a,b]=*it;
    b += a;
    bool ok=true;
    REP(i,b.size()-2)if(b.substr(i,3)=="000" or b.substr(i,3)=="111") 
      ok=false;
    if(ok)return "Yes";
  }
  return "No";
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int testsize;cin>>testsize;
  while(testsize--)cout<<solve()<<'\n';
}
0