結果

問題 No.1029 JJOOII 3
ユーザー tktk_snsntktk_snsn
提出日時 2020-12-31 18:01:47
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,278 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 77,184 KB
最終ジャッジ日時 2024-04-17 23:23:39
合計ジャッジ時間 6,410 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,480 KB
testcase_01 AC 40 ms
52,608 KB
testcase_02 AC 35 ms
52,480 KB
testcase_03 AC 61 ms
64,384 KB
testcase_04 AC 81 ms
66,432 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 193 ms
74,112 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 141 ms
72,832 KB
testcase_13 AC 214 ms
74,112 KB
testcase_14 WA -
testcase_15 AC 129 ms
67,968 KB
testcase_16 AC 113 ms
67,200 KB
testcase_17 AC 170 ms
71,040 KB
testcase_18 WA -
testcase_19 RE -
testcase_20 WA -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 AC 62 ms
67,712 KB
testcase_28 AC 60 ms
66,944 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 57 ms
66,688 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 217 ms
75,264 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 RE -
testcase_40 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

inf = 10 ** 18

N, K = map(int, input().split())
C = [-1] * N
J = [-1] * N
O = [-1] * N
I = [-1] * N
JO = [-1] * N
OI = [-1] * N

for i in range(N):
    si, ci = input().split()
    C[i] = int(ci)
    J[i] = si.count("J")
    O[i] = si.count("O")
    I[i] = si.count("I")

    jj = 0
    oo = O[i]
    tmp = [(0, oo)]
    for s in si:
        if s == "J":
            jj += 1
            tmp.append((jj, oo))
        if s == "O":
            oo -= 1
    JO[i] = tmp[:]

    oo = 0
    ii = I[i]
    tmp = [(0, ii)]
    for s in si:
        if s == "O":
            oo += 1
            tmp.append((oo, ii))
        if s == "I":
            ii -= 1
    OI[i] = tmp[:]
    

dpJ = [inf] * (K + 1)
dpO = [inf] * (K + 1)
dpI = [inf] * (K + 1)
dpJ[0] = 0
for j, c in zip(J, C):
    for i in range(K - j + 1):
        dpJ[i+j] = min(dpJ[i+j], dpJ[i] + c)
for jo, c in zip(JO, C):
    for a, b in jo:
        dpO[b] = min(dpO[b], dpJ[K-a] + c)
for j, c in zip(O, C):
    for i in range(K - j + 1):
        dpO[i+j] = min(dpO[i+j], dpO[i] + c)
for oi, c in zip(OI, C):
    for a, b in oi:
        dpI[b] = min(dpI[b], dpO[K-a] + c)
for j, c in zip(I, C):
    for i in range(K - j + 1):
        dpI[i+j] = min(dpI[i+j], dpI[i] + c)

if dpI[K] >= inf:
    print(-1)
else:
    print(dpI[K])
0