結果

問題 No.291 黒い文字列
ユーザー しらっ亭しらっ亭
提出日時 2015-10-20 00:51:42
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,412 bytes
コンパイル時間 331 ms
コンパイル使用メモリ 10,860 KB
実行使用メモリ 171,472 KB
最終ジャッジ日時 2023-09-29 16:25:45
合計ジャッジ時間 16,278 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 182 ms
25,360 KB
testcase_01 AC 155 ms
22,724 KB
testcase_02 AC 314 ms
34,840 KB
testcase_03 AC 309 ms
34,748 KB
testcase_04 AC 157 ms
22,608 KB
testcase_05 AC 157 ms
22,624 KB
testcase_06 AC 106 ms
17,964 KB
testcase_07 AC 181 ms
25,212 KB
testcase_08 AC 206 ms
27,644 KB
testcase_09 AC 133 ms
20,168 KB
testcase_10 WA -
testcase_11 AC 711 ms
69,008 KB
testcase_12 AC 724 ms
69,184 KB
testcase_13 AC 156 ms
22,716 KB
testcase_14 AC 438 ms
47,228 KB
testcase_15 AC 313 ms
34,984 KB
testcase_16 WA -
testcase_17 TLE -
testcase_18 TLE -
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 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(21)] for r in range(21)] for u in range(21)] for k in range(21)] 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(21), 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