結果

問題 No.2283 Prohibit Three Consecutive
ユーザー 河城白露河城白露
提出日時 2023-04-28 23:38:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 1,399 bytes
コンパイル時間 709 ms
コンパイル使用メモリ 83,368 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 00:43:05
合計ジャッジ時間 1,400 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 11 ms
5,376 KB
testcase_06 AC 11 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 5 ms
5,376 KB
testcase_10 AC 6 ms
5,376 KB
testcase_11 AC 4 ms
5,376 KB
testcase_12 AC 6 ms
5,376 KB
testcase_13 AC 11 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0