結果

問題 No.2283 Prohibit Three Consecutive
ユーザー yukster714yukster714
提出日時 2023-04-28 23:39:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 969 bytes
コンパイル時間 565 ms
コンパイル使用メモリ 64,664 KB
実行使用メモリ 13,756 KB
最終ジャッジ日時 2024-04-29 00:43:44
合計ジャッジ時間 3,945 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>

using namespace std;
#define yesif(x) cout << ((x) ? "Yes": "No") << endl 

bool is_valid(string& s) {
    for (int i = 0; i < s.size(); i++) {
        if (s[i%s.size()] == s[(i + 1)%s.size()] && s[i] == s[(i + 2)%s.size()]) {
            return false;
        }
    }
    return true;
}

bool try_all_combinations(string& s, int index) {
    if (index == s.size()) {
        return is_valid(s);
    }
    if (s[index] == '?') {
        s[index] = '0';
        if (try_all_combinations(s, index + 1)) {
            return true;
        }
        s[index] = '1';
        if (try_all_combinations(s, index + 1)) {
            return true;
        }
        s[index] = '?';
    } else {
        return try_all_combinations(s, index + 1);
    }
    return false;
}




int main() {
    int t; cin>>t;
    while(t--){
        int n; cin >> n;
        string s; cin>> s;
        yesif(try_all_combinations(s,0));
    }
    return 0;
}

0