結果

問題 No.1029 JJOOII 3
ユーザー titiatitia
提出日時 2020-04-17 22:05:01
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,209 bytes
コンパイル時間 211 ms
コンパイル使用メモリ 82,612 KB
実行使用メモリ 97,736 KB
最終ジャッジ日時 2024-04-14 14:16:28
合計ジャッジ時間 12,222 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 136 ms
88,700 KB
testcase_01 AC 136 ms
88,280 KB
testcase_02 AC 140 ms
88,604 KB
testcase_03 WA -
testcase_04 RE -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 313 ms
93,556 KB
testcase_16 AC 338 ms
93,816 KB
testcase_17 AC 319 ms
95,816 KB
testcase_18 WA -
testcase_19 AC 147 ms
89,344 KB
testcase_20 AC 157 ms
89,932 KB
testcase_21 AC 156 ms
89,668 KB
testcase_22 AC 158 ms
89,452 KB
testcase_23 AC 156 ms
89,724 KB
testcase_24 AC 158 ms
89,672 KB
testcase_25 AC 157 ms
89,816 KB
testcase_26 AC 159 ms
89,620 KB
testcase_27 AC 163 ms
89,608 KB
testcase_28 AC 161 ms
89,616 KB
testcase_29 AC 157 ms
89,828 KB
testcase_30 AC 163 ms
89,300 KB
testcase_31 AC 166 ms
89,856 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 136 ms
88,700 KB
testcase_38 AC 149 ms
89,312 KB
testcase_39 RE -
testcase_40 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N,K=map(int,input().split())

S=[input().split() for i in range(N)]

DP=[1<<63]*(3*K+2+100)
DP[0]=0

T=["J"]*K+["O"]*K+["I"]*K

J=[]
O=[]
I=[]
for s,M in S:
    J.append((s.count("J"),int(M)))
    O.append((s.count("O"),int(M)))
    I.append((s.count("I"),int(M)))

from fractions import Fraction

MAXJ=max(J,key=lambda x:Fraction(x[0],x[1]))
MAXO=max(J,key=lambda x:Fraction(x[0],x[1]))
MAXI=max(J,key=lambda x:Fraction(x[0],x[1]))
    

for i in range(3*K):
    #NEXT=T[i:i+80]

    if i<K-500:
        if DP[i]==1<<63:
            continue
        else:
            DP[i+MAXJ[0]]=DP[i]+MAXJ[1]

    elif K+100<i<K*2-500:
        if DP[i]==1<<63:
            continue
        else:
            DP[i+MAXO[0]]=DP[i]+MAXO[1]
            
    elif K*2+100<i<K*3-500:
        if DP[i]==1<<63:
            continue
        else:
            DP[i+MAXI[0]]=DP[i]+MAXI[1]

    else:
        for j in range(N):
            ind=0
            M=int(S[j][1])
            for s in S[j][0]:
                if i+ind<3*K and s==T[i+ind]:
                    ind+=1
                    DP[i+ind]=min(DP[i+ind],DP[i]+M)

if 1<<63==DP[K*3]:
    print(-1)
else:
    print(DP[K*3])

    

0