結果

問題 No.2283 Prohibit Three Consecutive
ユーザー KKT89
提出日時 2023-04-28 21:43:12
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 1,590 bytes
コンパイル時間 2,535 ms
コンパイル使用メモリ 212,308 KB
最終ジャッジ日時 2025-02-12 15:03:05
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int q; cin >> q;
    while (q--) {
        int n; cin >> n;
        string s; cin >> s;
        auto slv = [](int n, string s) -> bool {
            bool chg = false;
            while (1) {
                chg = false;
                for (int i = 0; i < n; ++i) {
                    if (s[i] == '?') continue;
                    if (s[i] == s[(i+1)%n]) {
                        if (s[(i+2)%n] == s[i]) return false;
                        if (s[(i+2)%n] == '?') {
                            chg = true;
                        }
                        s[(i+2)%n] = (s[i]^1);
                    }
                    if (s[i] == s[(i+2)%n] and s[(i+1)%n] == '?') {
                        if (s[(i+1)%n] == '?') {
                            chg = true;
                        }
                        s[(i+1)%n] = (s[i]^1);
                    }
                }
                if (!chg) break;
            }
            return true;
        };
        if (slv(n, s)) {
            cout << "Yes" << "\n";
        }
        else {
            cout << "No" << "\n";
        }
    }
}
0