結果
| 問題 |
No.2283 Prohibit Three Consecutive
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-04-28 21:38:55 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 8 ms / 2,000 ms |
| コード長 | 1,623 bytes |
| コンパイル時間 | 1,449 ms |
| コンパイル使用メモリ | 169,616 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-17 20:37:57 |
| 合計ジャッジ時間 | 2,221 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 13 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin >> T;
while(T--){
int n;
string s;
cin >> n >> s;
bool ans = false;
for(int st = 0; st < 4; st++){
if(s[0] != '?' && (st & 1) != s[0] - '0') continue;
if(s[1] != '?' && (st >> 1 & 1) != s[1] - '0') continue;
vector<array<bool, 4>> dp(n + 1, array<bool, 4>({0, 0, 0, 0}));
dp[2][st] = true;
for(int i = 2; i < n; i++){
if(s[i] != '?'){
int nv = s[i] - '0';
for(int j = 0; j < 4; j++){
if(!dp[i][j]) continue;
int ns = nv * 4 + j;
if(ns == 0 || ns == 7) continue;
dp[i + 1][ns / 2] = true;
}
}else{
for(int j = 0; j < 4; j++){
if(!dp[i][j]) continue;
if(j != 0) dp[i + 1][j / 2] = true;
if(j + 4 != 7) dp[i + 1][(j + 4) / 2] = true;
}
}
}
for(int j = 0; j < 4; j++){
if(!dp[n][j]) continue;
int s1 = (st & 1) * 4 + j;
int s2 = st * 2 + j / 2;
if(s1 != 0 && s1 != 7 && s2 != 0 && s2 != 7){
ans = true;
break;
}
}
if(ans) break;
}
cout << (ans ? "Yes" : "No") << '\n';
}
}