結果

問題 No.2283 Prohibit Three Consecutive
コンテスト
ユーザー No-World
提出日時 2023-04-28 23:21:42
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,658 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 242 ms
コンパイル使用メモリ 39,680 KB
実行使用メモリ 6,912 KB
最終ジャッジ日時 2026-06-30 11:21:33
合計ジャッジ時間 1,129 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 6 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

// Problem: No.2283 Prohibit Three Consecutive
// Contest: yukicoder
// URL: https://yukicoder.me/problems/no/2283
// Memory Limit: 512 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)

// #include <bits/stdc++.h>
#include <cstdio>
// #include <iostream>
// #include <cstring>
// #include <algorithm>
// #include <cmath>
// #include <queue>
// #include <map>
// #include <vector>
// #include <stack>
// #include <set>
// #include <unordered_map>
// #include <cstdlib>
// typedef long long ll;
using namespace std;
const int inf = 0x3f3f3f3f, N = 1e5 + 10;
// const ll INF = __LONG_LONG_MAX__;

int n;
bool dfs(char *s, int idx)
{
    if (idx == n)
        return true;
    if (s[idx] != '?')
    {
        if (idx >= 2)
        {
            if (s[idx] == s[idx - 1] && s[idx] == s[idx - 2])
                return false;
        }
        else if (idx == 1)
        {
            if (s[idx] == s[idx - 1] && s[idx] == s[n - 1])
            {
                return false;
            }
        }
        else
        {
            if (s[idx] == s[n - 1] && s[idx] == s[n - 2])
            {
                return false;
            }
        }
        return dfs(s, idx + 1);
    }
    s[idx] = '0';
    if (dfs(s, idx))
        return true;
    s[idx] = '1';
    if (dfs(s, idx))
        return true;
    return false;
}

inline void Solution()
{
    scanf("%d", &n);
    char a[n + 10];
    scanf("%s", a);
    if (dfs(a, 0))
        printf("Yes\n");
    else
        printf("No\n");
}

int main(int argc, char const *argv[])
{
    int T = 1;
    scanf("%d", &T);
    while (T--)
    {
        Solution();
    }
    return 0;
}
0