結果

問題 No.291 黒い文字列
ユーザー rpy3cpprpy3cpp
提出日時 2015-10-17 08:31:12
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
WA  
実行時間 -
コード長 1,369 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 10,952 KB
実行使用メモリ 9,968 KB
最終ジャッジ日時 2023-09-29 13:34:07
合計ジャッジ時間 3,918 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,588 KB
testcase_01 AC 16 ms
8,540 KB
testcase_02 AC 17 ms
8,496 KB
testcase_03 AC 15 ms
8,512 KB
testcase_04 AC 15 ms
8,484 KB
testcase_05 AC 16 ms
8,568 KB
testcase_06 AC 16 ms
8,412 KB
testcase_07 AC 15 ms
8,464 KB
testcase_08 AC 16 ms
8,520 KB
testcase_09 AC 14 ms
8,540 KB
testcase_10 AC 15 ms
8,536 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 15 ms
8,568 KB
testcase_14 AC 15 ms
8,524 KB
testcase_15 AC 15 ms
8,512 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 62 ms
8,996 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 151 ms
9,856 KB
testcase_26 AC 111 ms
9,960 KB
testcase_27 AC 16 ms
8,472 KB
testcase_28 AC 28 ms
8,684 KB
testcase_29 AC 75 ms
9,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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] += 1

print(solve(S))
0