結果
| 問題 |
No.2283 Prohibit Three Consecutive
|
| コンテスト | |
| ユーザー |
yukster714
|
| 提出日時 | 2023-04-28 23:39:43 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 969 bytes |
| コンパイル時間 | 510 ms |
| コンパイル使用メモリ | 65,636 KB |
| 実行使用メモリ | 18,632 KB |
| 最終ジャッジ日時 | 2024-11-17 22:29:52 |
| 合計ジャッジ時間 | 25,195 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 5 TLE * 8 |
ソースコード
#include <iostream>
#include <string>
using namespace std;
#define yesif(x) cout << ((x) ? "Yes": "No") << endl
bool is_valid(string& s) {
for (int i = 0; i < s.size(); i++) {
if (s[i%s.size()] == s[(i + 1)%s.size()] && s[i] == s[(i + 2)%s.size()]) {
return false;
}
}
return true;
}
bool try_all_combinations(string& s, int index) {
if (index == s.size()) {
return is_valid(s);
}
if (s[index] == '?') {
s[index] = '0';
if (try_all_combinations(s, index + 1)) {
return true;
}
s[index] = '1';
if (try_all_combinations(s, index + 1)) {
return true;
}
s[index] = '?';
} else {
return try_all_combinations(s, index + 1);
}
return false;
}
int main() {
int t; cin>>t;
while(t--){
int n; cin >> n;
string s; cin>> s;
yesif(try_all_combinations(s,0));
}
return 0;
}
yukster714