結果
| 問題 |
No.2283 Prohibit Three Consecutive
|
| コンテスト | |
| ユーザー |
河城白露
|
| 提出日時 | 2023-04-28 23:38:30 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 12 ms / 2,000 ms |
| コード長 | 1,399 bytes |
| コンパイル時間 | 857 ms |
| コンパイル使用メモリ | 83,372 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-17 22:28:50 |
| 合計ジャッジ時間 | 1,608 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 13 |
ソースコード
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#define ll long long
#define db double
using namespace std;
const ll N = 2e5 + 100;
ll tt,n;
char ch[N];
void solve() {
scanf("%lld",&n);
scanf("%s",ch);
bool f = 1;
for (ll i = 0;i < n;i++) {
ll x = i;
ll y = (i + 1) % n;
ll lf = (x + n - 1) % n;
ll rt = (y + 1) % n;
if (ch[x] == ch[y] && (ch[y] != '?')) {
ll res = ch[y] - '0';
res ^= 1;
char c = res + '0';
if (ch[lf] == '?') {
ch[lf] = c;
} else {
if (ch[lf] == ch[x]) {
f = 0;
break;
}
}
if (ch[rt] == '?') {
ch[rt] = c;
} else {
if (ch[rt] == ch[y]) {
f = 0;
break;
}
}
}
}
for (ll i = n - 1;i >= 0;i--) {
ll x = i;
ll y = (i + n - 1) % n;
ll lf = (y + n - 1) % n;
ll rt = (x + 1) % n;
if (ch[x] == ch[y] && (ch[y] != '?')) {
ll res = ch[y] - '0';
res ^= 1;
char c = res + '0';
if (ch[lf] == '?') {
ch[lf] = c;
} else {
if (ch[lf] == ch[x]) {
f = 0;
break;
}
}
if (ch[rt] == '?') {
ch[rt] = c;
} else {
if (ch[rt] == ch[y]) {
f = 0;
break;
}
}
}
}
if (f) {
printf("Yes\n");
} else {
printf("No\n");
}
}
int main() {
scanf("%lld",&tt);
while(tt) {
solve();
tt--;
}
return 0;
}
河城白露