結果
問題 |
No.2283 Prohibit Three Consecutive
|
ユーザー |
![]() |
提出日時 | 2023-08-09 13:40:58 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 168 ms / 2,000 ms |
コード長 | 932 bytes |
コンパイル時間 | 167 ms |
コンパイル使用メモリ | 82,148 KB |
実行使用メモリ | 78,480 KB |
最終ジャッジ日時 | 2024-11-15 09:22:17 |
合計ジャッジ時間 | 2,288 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 13 |
ソースコード
# 左側から必要な変更を?に行う、次は右側から必要な変更を?に行う # それで3連続があればアウト T = int(input()) for t in range(T): N = int(input()) S = list(input()) # from left for i in range(N): if S[i] == '?': # 1個前2個前双方ともに?のケースに注意 if S[(i-2)%N] == S[(i-1)%N] == '0': S[i] = '1' if S[(i-2)%N] == S[(i-1)%N] == '1': S[i] = '0' # from right for i in range(N-1, -1, -1): if S[i] == '?': if S[(i+2)%N] == S[(i+1)%N] == '0': S[i] = '1' if S[(i+2)%N] == S[(i+1)%N] == '1': S[i] = '0' ans = 'Yes' for i in range(N): if S[(i-2)%N] == S[(i-1)%N] == S[(i)%N] == '0': ans = 'No' if S[(i-2)%N] == S[(i-1)%N] == S[(i)%N] == '1': ans = 'No' print(ans)