結果
| 問題 |
No.291 黒い文字列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-10-17 09:11:04 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 1,408 ms / 2,000 ms |
| コード長 | 948 bytes |
| コンパイル時間 | 224 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 12,796 KB |
| 最終ジャッジ日時 | 2024-07-22 07:57:20 |
| 合計ジャッジ時間 | 7,227 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 26 |
ソースコード
import collections
S = input()
lst = ['KUROI?'.index(c) for c in S if c in 'KUROI?']
m = len(lst) // 5
dp = collections.defaultdict(int)
dp[0,0,0,0] = 0
for c in lst:
dp_c = {k: v for k, v in dp.items()}
for (k0, k1, k2, k3), val in dp_c.items():
if (c == 5 or c == 4) and k3 > val and dp[k0, k1, k2, k3] <= val:
dp[k0, k1, k2, k3] = val + 1
if (c == 5 or c == 3) and k2 > k3:
new_key = (k0, k1, k2, k3 + 1)
if dp[new_key] <= val: dp[new_key] = val
if (c == 5 or c == 2) and k1 > k2:
new_key = (k0, k1, k2 + 1, k3)
if dp[new_key] <= val: dp[new_key] = val
if (c == 5 or c == 1) and k0 > k1:
new_key = (k0, k1 + 1, k2, k3)
if dp[new_key] <= val: dp[new_key] = val
if (c == 5 or c == 0) and m > k0:
new_key = (k0 + 1, k1, k2, k3)
if dp[new_key] <= val: dp[new_key] = val
print(max(dp.values()))