結果

問題 No.291 黒い文字列
ユーザー しらっ亭
提出日時 2015-10-20 00:51:42
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 1,412 bytes
コンパイル時間 104 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 220,320 KB
最終ジャッジ日時 2024-07-22 10:31:18
合計ジャッジ時間 16,632 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 11 WA * 3 TLE * 3 -- * 9
権限があれば一括ダウンロードができます

ソースコード

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