結果

問題 No.2283 Prohibit Three Consecutive
ユーザー PzPz
提出日時 2023-05-04 14:49:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 707 bytes
コンパイル時間 1,812 ms
コンパイル使用メモリ 200,992 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 23:26:31
合計ジャッジ時間 2,650 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define PII std::pair<int, int> 

using ll = long long;

void solve() {
	int n; std::cin >> n;
	std::string s; std::cin >> s;
	s += s;
	for (int i = 2; i < n + n; i++) {
		if(s[i - 1] == s[i - 2] and s[i - 2] != '?') {
			if(s[i] == s[i - 1]) {
				std::cout << "No\n";
				return;
			} else if(s[i] == '?') {
				char x = '1' - s[i - 1] + '0';
				if(s[i + 1] == s[i + 2] and s[i + 1] == x) {
					std::cout << "No\n";
					return;
				} else {
					s[i] = x;
				}
			}
		}
	}
	std::cout << "Yes\n";
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	int T = 1;
	std::cin >> T;
	while(T--) {
		solve();
	}

	return 0;
}
0