結果

問題 No.291 黒い文字列
ユーザー しらっ亭しらっ亭
提出日時 2015-10-20 01:18:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,192 bytes
コンパイル時間 1,107 ms
コンパイル使用メモリ 10,920 KB
実行使用メモリ 23,492 KB
最終ジャッジ日時 2023-09-29 16:49:04
合計ジャッジ時間 7,601 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,432 KB
testcase_01 AC 18 ms
8,520 KB
testcase_02 AC 17 ms
8,572 KB
testcase_03 AC 17 ms
8,480 KB
testcase_04 AC 18 ms
8,420 KB
testcase_05 AC 18 ms
8,424 KB
testcase_06 AC 17 ms
8,420 KB
testcase_07 AC 18 ms
8,448 KB
testcase_08 AC 17 ms
8,572 KB
testcase_09 AC 18 ms
8,484 KB
testcase_10 AC 19 ms
8,484 KB
testcase_11 AC 34 ms
8,564 KB
testcase_12 AC 28 ms
8,532 KB
testcase_13 AC 18 ms
8,580 KB
testcase_14 AC 18 ms
8,400 KB
testcase_15 AC 18 ms
8,460 KB
testcase_16 AC 566 ms
11,116 KB
testcase_17 AC 1,082 ms
13,412 KB
testcase_18 AC 662 ms
12,804 KB
testcase_19 TLE -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict


def solve():
    SS = input()
    S = [c for c in SS if c in 'KUROI?']

    dp2 = defaultdict(lambda: -1)

    # dp[x, k, u, r, o] = 次に見るのが x 文字目で、 kまで: k個、uまで: u個、rまで: r個、oまで: o個 のとき、i までできた数
    dp2[0, 0, 0, 0] = 0
    ma = 0

    for x, c in enumerate(S):
        dp1 = dp2
        dp2 = defaultdict(lambda: -1, dp1)
        for kuro in dp1:
            now = dp1[kuro]
            k, u, r, o = kuro

            if c == 'K' or c == '?':
                dp2[k + 1, u, r, o] = max(dp2[k + 1, u, r, o], now)
            if (c == 'U' or c == '?') and k:
                dp2[k - 1, u + 1, r, o] = max(dp2[k - 1, u + 1, r, o], now)
            if (c == 'R' or c == '?') and u:
                dp2[k, u - 1, r + 1, o] = max(dp2[k, u - 1, r + 1, o], now)
            if (c == 'O' or c == '?') and r:
                dp2[k, u, r - 1, o + 1] = max(dp2[k, u, r - 1, o + 1], now)
            if (c == 'I' or c == '?') and o:
                dp2[k, u, r, o - 1] = max(dp2[k, u, r, o - 1], now + 1)
                ma = max(ma, now + 1)
    print(ma)


if __name__ == '__main__':
    solve()
0