結果

問題 No.291 黒い文字列
ユーザー rpy3cpprpy3cpp
提出日時 2015-10-17 08:36:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,374 bytes
コンパイル時間 89 ms
コンパイル使用メモリ 10,984 KB
実行使用メモリ 9,984 KB
最終ジャッジ日時 2023-09-29 13:34:13
合計ジャッジ時間 4,375 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,528 KB
testcase_01 AC 17 ms
8,440 KB
testcase_02 AC 15 ms
8,512 KB
testcase_03 AC 15 ms
8,544 KB
testcase_04 AC 15 ms
8,524 KB
testcase_05 AC 16 ms
8,468 KB
testcase_06 AC 19 ms
8,476 KB
testcase_07 AC 18 ms
8,508 KB
testcase_08 AC 15 ms
8,572 KB
testcase_09 AC 19 ms
8,408 KB
testcase_10 AC 18 ms
8,516 KB
testcase_11 AC 19 ms
8,564 KB
testcase_12 AC 16 ms
8,512 KB
testcase_13 AC 19 ms
8,520 KB
testcase_14 AC 19 ms
8,596 KB
testcase_15 AC 16 ms
8,444 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 72 ms
8,724 KB
testcase_19 WA -
testcase_20 AC 251 ms
8,996 KB
testcase_21 AC 61 ms
9,108 KB
testcase_22 WA -
testcase_23 AC 663 ms
9,928 KB
testcase_24 WA -
testcase_25 AC 148 ms
9,980 KB
testcase_26 AC 111 ms
9,984 KB
testcase_27 AC 16 ms
8,456 KB
testcase_28 AC 26 ms
8,712 KB
testcase_29 AC 63 ms
9,456 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] = val + 1

print(solve(S))
0