結果

問題 No.291 黒い文字列
ユーザー rpy3cpprpy3cpp
提出日時 2015-10-17 09:04:05
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,408 ms / 2,000 ms
コード長 1,063 bytes
コンパイル時間 100 ms
コンパイル使用メモリ 11,048 KB
実行使用メモリ 10,112 KB
最終ジャッジ日時 2023-09-29 13:36:59
合計ジャッジ時間 6,517 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,480 KB
testcase_01 AC 16 ms
8,388 KB
testcase_02 AC 16 ms
8,444 KB
testcase_03 AC 16 ms
8,484 KB
testcase_04 AC 16 ms
8,392 KB
testcase_05 AC 17 ms
8,468 KB
testcase_06 AC 17 ms
8,468 KB
testcase_07 AC 16 ms
8,480 KB
testcase_08 AC 16 ms
8,472 KB
testcase_09 AC 16 ms
8,392 KB
testcase_10 AC 17 ms
8,504 KB
testcase_11 AC 17 ms
8,524 KB
testcase_12 AC 17 ms
8,496 KB
testcase_13 AC 16 ms
8,576 KB
testcase_14 AC 16 ms
8,488 KB
testcase_15 AC 16 ms
8,396 KB
testcase_16 AC 88 ms
8,696 KB
testcase_17 AC 167 ms
8,812 KB
testcase_18 AC 115 ms
8,948 KB
testcase_19 AC 453 ms
9,192 KB
testcase_20 AC 470 ms
9,276 KB
testcase_21 AC 111 ms
9,272 KB
testcase_22 AC 964 ms
9,980 KB
testcase_23 AC 1,408 ms
10,048 KB
testcase_24 AC 691 ms
10,112 KB
testcase_25 AC 300 ms
9,956 KB
testcase_26 AC 223 ms
10,012 KB
testcase_27 AC 18 ms
8,564 KB
testcase_28 AC 38 ms
8,688 KB
testcase_29 AC 110 ms
9,504 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:
    for (k0, k1, k2, k3), val in list(dp.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