結果

問題 No.2283 Prohibit Three Consecutive
ユーザー No-WorldNo-World
提出日時 2023-04-29 00:54:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,658 bytes
コンパイル時間 229 ms
コンパイル使用メモリ 32,256 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 01:24:04
合計ジャッジ時間 1,003 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 4 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 #

// 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] = '1';
    if (dfs(s, idx))
        return true;
    s[idx] = '0';
    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