結果

問題 No.291 黒い文字列
ユーザー rpy3cpprpy3cpp
提出日時 2015-10-17 09:06:13
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,471 ms / 2,000 ms
コード長 1,080 bytes
コンパイル時間 139 ms
コンパイル使用メモリ 10,944 KB
実行使用メモリ 10,120 KB
最終ジャッジ日時 2023-09-29 13:38:24
合計ジャッジ時間 7,157 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,480 KB
testcase_01 AC 19 ms
8,444 KB
testcase_02 AC 19 ms
8,480 KB
testcase_03 AC 18 ms
8,448 KB
testcase_04 AC 18 ms
8,496 KB
testcase_05 AC 18 ms
8,536 KB
testcase_06 AC 18 ms
8,496 KB
testcase_07 AC 18 ms
8,496 KB
testcase_08 AC 18 ms
8,568 KB
testcase_09 AC 18 ms
8,456 KB
testcase_10 AC 19 ms
8,528 KB
testcase_11 AC 20 ms
8,492 KB
testcase_12 AC 20 ms
8,568 KB
testcase_13 AC 19 ms
8,476 KB
testcase_14 AC 18 ms
8,480 KB
testcase_15 AC 18 ms
8,476 KB
testcase_16 AC 96 ms
8,640 KB
testcase_17 AC 181 ms
8,684 KB
testcase_18 AC 127 ms
8,736 KB
testcase_19 AC 481 ms
9,180 KB
testcase_20 AC 529 ms
9,196 KB
testcase_21 AC 118 ms
9,112 KB
testcase_22 AC 1,050 ms
10,000 KB
testcase_23 AC 1,471 ms
9,968 KB
testcase_24 AC 759 ms
9,976 KB
testcase_25 AC 318 ms
10,120 KB
testcase_26 AC 217 ms
9,956 KB
testcase_27 AC 20 ms
8,440 KB
testcase_28 AC 42 ms
8,720 KB
testcase_29 AC 116 ms
9,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 = dp.copy()
    for (k0, k1, k2, k3), val in dp_c.items():
        if (c == 4 or c == 5) and k3 > val and dp[k0, k1, k2, k3] <= val:
            dp[k0, k1, k2, k3] = val + 1
        if (c == 3 or c == 5) and k2 > k3:
            new_key = (k0, k1, k2, k3 + 1)
            if (new_key not in dp) or dp[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) or dp[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) or dp[new_key] < val:
                dp[new_key] = val
        if (c == 0 or c == 5) and m > k0:
            new_key = (k0 + 1, k1, k2, k3)
            if (new_key not in dp) or dp[new_key] < val:
                dp[new_key] = val
print(max(dp.values()))
0