結果
問題 | No.2283 Prohibit Three Consecutive |
ユーザー | ニックネーム |
提出日時 | 2023-04-28 21:55:35 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 727 ms / 2,000 ms |
コード長 | 876 bytes |
コンパイル時間 | 300 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 31,488 KB |
最終ジャッジ日時 | 2024-04-28 23:32:17 |
合計ジャッジ時間 | 5,302 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 31 ms
10,752 KB |
testcase_01 | AC | 32 ms
10,880 KB |
testcase_02 | AC | 35 ms
10,880 KB |
testcase_03 | AC | 467 ms
23,528 KB |
testcase_04 | AC | 565 ms
20,932 KB |
testcase_05 | AC | 418 ms
10,880 KB |
testcase_06 | AC | 442 ms
10,880 KB |
testcase_07 | AC | 31 ms
10,752 KB |
testcase_08 | AC | 727 ms
31,360 KB |
testcase_09 | AC | 323 ms
31,360 KB |
testcase_10 | AC | 321 ms
31,360 KB |
testcase_11 | AC | 321 ms
31,488 KB |
testcase_12 | AC | 244 ms
11,008 KB |
testcase_13 | AC | 494 ms
10,880 KB |
ソースコード
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)