結果

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

テストケース

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

ソースコード

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++) {
		bool fg[5];
		fg[0] = 1;
		fg[1] = 1;
		ll lf = (i + n - 1) % n;
		ll lfw = (i + n - 2) % n;
		ll rt = (i + n + 1) % n;
		ll rtw = (i + n + 2) % n;
		if (ch[i] != '?' && (ch[i] == ch[lf]) && (ch[i] == ch[rt])) {
			f = 0;
			break;
		}
		if (ch[i] != '?') {
			continue;
		}
		if (ch[lf] == ch[rt] && (ch[lf] != '?')) {
			ll x = ch[lf] - '0';
			fg[x] = 0;
		}
		if (ch[lf] == ch[lfw] && (ch[lf] != '?')) {
			ll x = ch[lf] - '0';
			fg[x] = 0;
		}
		if (ch[rt] == ch[rtw] && (ch[rt] != '?')) {
			ll x = ch[rt] - '0';
			fg[x] = 0;
		}
		if ((!fg[0]) && (!fg[1])) {
			f = 0;
			break;
		}
		if (fg[0]) {
			ch[i] = '0';
		} else {
			ch[i] = '1';
		}
	}
	if (f) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}
}
int main() {
	scanf("%lld",&tt);
	while(tt) {
		solve();
		tt--;
	}
	return 0;
}
0