結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 16 ms
8,248 KB
testcase_02 AC 16 ms
8,148 KB
testcase_03 AC 16 ms
8,208 KB
testcase_04 AC 16 ms
8,112 KB
testcase_05 AC 15 ms
8,184 KB
testcase_06 AC 16 ms
8,108 KB
testcase_07 AC 15 ms
8,184 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 WA -
testcase_11 RE -
testcase_12 RE -
testcase_13 AC 16 ms
8,100 KB
testcase_14 AC 17 ms
8,172 KB
testcase_15 AC 16 ms
8,188 KB
testcase_16 RE -
testcase_17 RE -
testcase_18 WA -
testcase_19 RE -
testcase_20 RE -
testcase_21 TLE -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import product


def solve():
    SS = input()
    S = [c for c in SS if c in 'KUROI?']
    L1 = len(S)
    L2 = L1 // 5 + 1

    dp = [[[[[-1 for o in range(L2)] for r in range(L2)] for u in range(L2)] for k in range(L2)] for x in range(L1 + 1)]
    # dp[x][k][u][r][o] = 次に見るのが x 文字目で、 kまで: k個、uまで: u個、rまで: r個、oまで: o個 のとき、i までできた数
    dp[0][0][0][0][0] = 0
    ma = 0

    for x, c in enumerate(S):
        dpx = dp[x]
        for k, u, r, o in product(range(L2), repeat=4):
            if dpx[k][u][r][o] < 0:
                continue
            now = dpx[k][u][r][o]
            dpy = dp[x + 1]

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


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