結果
| 問題 |
No.2283 Prohibit Three Consecutive
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-04-28 21:34:23 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 6 ms / 2,000 ms |
| コード長 | 1,514 bytes |
| コンパイル時間 | 1,666 ms |
| コンパイル使用メモリ | 194,484 KB |
| 最終ジャッジ日時 | 2025-02-12 14:55:52 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 13 |
ソースコード
#include <bits/stdc++.h>
using i64 = long long;
void solve() {
int N;
std::cin >> N;
std::string S;
std::cin >> S;
for (int x = 0; x < 2; x++) {
for (int y = 0; y < 2; y++) {
if (S[0] == '0' + !x) {
continue;
}
if (S[1] == '0' + !y) {
continue;
}
std::array<std::array<bool, 2>, 2> dp{};
dp[x][y] = true;
for (int i = 2; i < N; i++) {
std::array<std::array<bool, 2>, 2> g{};
for (int x = 0; x < 2; x++) {
for (int y = 0; y < 2; y++) {
for (int z = 0; z < 2; z++) {
if (dp[x][y] && S[i] != '0' + !z && (x != y || y != z)) {
g[y][z] = true;
}
}
}
}
dp = g;
}
for (int t = 0; t < 2; t++) {
for (int z = 0; z < 2; z++) {
if ((t != z || z != x) && (z != x || x != y) && dp[t][z]) {
std::cout << "Yes\n";
return;
}
}
}
}
}
std::cout << "No\n";
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}