結果
| 問題 | No.2283 Prohibit Three Consecutive |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-04-29 00:54:45 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,658 bytes |
| 記録 | |
| コンパイル時間 | 190 ms |
| コンパイル使用メモリ | 39,680 KB |
| 実行使用メモリ | 6,912 KB |
| 最終ジャッジ日時 | 2026-06-30 11:27:13 |
| 合計ジャッジ時間 | 1,052 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 8 WA * 5 |
ソースコード
// 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;
}