結果
問題 |
No.2283 Prohibit Three Consecutive
|
ユーザー |
![]() |
提出日時 | 2023-04-28 23:24:12 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,281 bytes |
コンパイル時間 | 622 ms |
コンパイル使用メモリ | 83,200 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-17 22:17:50 |
合計ジャッジ時間 | 1,178 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 6 WA * 7 |
ソースコード
#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]) && (fg[1])) { if ((ch[rt] != '?')) { ll x = ch[rt] - '0'; fg[x] = 0; } } 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; }