結果

問題 No.2283 Prohibit Three Consecutive
ユーザー KKT89KKT89
提出日時 2023-04-28 21:41:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,190 bytes
コンパイル時間 2,613 ms
コンパイル使用メモリ 211,876 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-28 23:20:44
合計ジャッジ時間 3,294 ms
ジャッジサーバーID
(参考情報)
judge4 / 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 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 2 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 WA -
testcase_13 WA -
権限があれば一括ダウンロードができます

ソースコード

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 {
            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;
                    s[(i+2)%n] = (s[i]^1);
                }
                if (s[i] == s[(i+2)%n] and s[(i+1)%n] == '?') {
                    s[(i+1)%n] = (s[i]^1);
                }
            }
            return true;
        };
        if (slv(n, s)) {
            cout << "Yes" << "\n";
        }
        else {
            cout << "No" << "\n";
        }
    }
}
0