結果
問題 | No.2283 Prohibit Three Consecutive |
ユーザー | ニックネーム |
提出日時 | 2023-04-28 21:55:35 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 683 ms / 2,000 ms |
コード長 | 876 bytes |
コンパイル時間 | 102 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 31,488 KB |
最終ジャッジ日時 | 2024-11-17 20:53:43 |
合計ジャッジ時間 | 5,033 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 13 |
ソースコード
for _ in range(int(input())): n = int(input()); s = input(); ans = "No" for i in range(4): if i==0 and (s[0]=="1" or s[1]=="1"): continue if i==1 and (s[0]=="1" or s[1]=="0"): continue if i==2 and (s[0]=="0" or s[1]=="1"): continue if i==3 and (s[0]=="0" or s[1]=="0"): continue dp = [[False]*4 for _ in range(n)]; dp[1][i] = True for j in range(2,n): if s[j]!="1" and dp[j-1][2]: dp[j][0] = True if s[j]!="0" and dp[j-1][0]+dp[j-1][2]: dp[j][1] = True if s[j]!="1" and dp[j-1][1]+dp[j-1][3]: dp[j][2] = True if s[j]!="0" and dp[j-1][1]: dp[j][3] = True if i==0 and dp[-1][1]+dp[-1][3]: ans = "Yes" if i==1 and sum(dp[-1][1:]): ans = "Yes" if i==2 and sum(dp[-1][:3]): ans = "Yes" if i==3 and dp[-1][0]+dp[-1][2]: ans = "Yes" print(ans)