結果

問題 No.291 黒い文字列
ユーザー しらっ亭しらっ亭
提出日時 2015-10-20 00:54:10
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,412 bytes
コンパイル時間 1,120 ms
コンパイル使用メモリ 86,940 KB
実行使用メモリ 304,368 KB
最終ジャッジ日時 2023-09-29 16:48:24
合計ジャッジ時間 23,010 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 151 ms
92,616 KB
testcase_01 AC 144 ms
90,400 KB
testcase_02 AC 198 ms
101,884 KB
testcase_03 AC 212 ms
101,652 KB
testcase_04 AC 143 ms
90,400 KB
testcase_05 AC 136 ms
90,144 KB
testcase_06 AC 123 ms
86,044 KB
testcase_07 AC 156 ms
92,912 KB
testcase_08 AC 168 ms
94,740 KB
testcase_09 AC 130 ms
88,164 KB
testcase_10 WA -
testcase_11 AC 391 ms
133,356 KB
testcase_12 AC 371 ms
133,196 KB
testcase_13 AC 144 ms
90,376 KB
testcase_14 AC 259 ms
112,760 KB
testcase_15 AC 207 ms
101,572 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 1,158 ms
261,908 KB
testcase_20 AC 1,240 ms
263,984 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 1,540 ms
304,368 KB
testcase_24 WA -
testcase_25 AC 1,370 ms
304,032 KB
testcase_26 AC 1,361 ms
304,084 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

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