結果
| 問題 |
No.291 黒い文字列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-10-17 08:36:22 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,374 bytes |
| コンパイル時間 | 99 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 12,444 KB |
| 最終ジャッジ日時 | 2024-07-22 07:52:40 |
| 合計ジャッジ時間 | 5,102 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 21 WA * 5 |
ソースコード
import collections
target = 'KUROI'
S = input()
def solve(S):
lst = preprocess(S)
m = len(lst) // len(target)
dp = collections.defaultdict(int)
dp[0,0,0,0] = 0
for c in lst:
update_dp(dp, c, m)
return max(dp.values())
def preprocess(S):
candidates = target + '?'
dic = {c: i for i, c in enumerate(candidates)}
return [dic[c] for c in S if c in dic]
def update_dp(dp, c, m):
dp_copy = {key: val for key, val in dp.items()}
for (k0, k1, k2, k3), val in dp_copy.items():
if (c == 0 or c == 5) and m > k0:
new_key = (k0 + 1, k1, k2, k3)
if (new_key not in dp_copy) or dp_copy[new_key] < val:
dp[new_key] = val
if (c == 1 or c == 5) and k0 > k1:
new_key = (k0, k1 + 1, k2, k3)
if (new_key not in dp_copy) or dp_copy[new_key] < val:
dp[new_key] = val
if (c == 2 or c == 5) and k1 > k2:
new_key = (k0, k1, k2 + 1, k3)
if (new_key not in dp_copy) or dp_copy[new_key] < val:
dp[new_key] = val
if (c == 3 or c == 5) and k2 > k3:
new_key = (k0, k1, k2, k3 + 1)
if (new_key not in dp_copy) or dp_copy[new_key] < val:
dp[new_key] = val
if (c == 4 or c == 5) and k3 > val:
dp[k0, k1, k2, k3] = val + 1
print(solve(S))