結果

問題 No.1029 JJOOII 3
ユーザー autumn-eelautumn-eel
提出日時 2020-04-17 22:33:17
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 276 ms / 2,000 ms
コード長 852 bytes
コンパイル時間 1,723 ms
コンパイル使用メモリ 166,524 KB
実行使用メモリ 262,884 KB
最終ジャッジ日時 2024-04-14 14:50:55
合計ジャッジ時間 7,803 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
10,320 KB
testcase_01 AC 3 ms
6,944 KB
testcase_02 AC 5 ms
14,668 KB
testcase_03 AC 21 ms
49,444 KB
testcase_04 AC 49 ms
62,092 KB
testcase_05 AC 250 ms
228,572 KB
testcase_06 AC 190 ms
223,136 KB
testcase_07 AC 223 ms
236,308 KB
testcase_08 AC 231 ms
242,384 KB
testcase_09 AC 202 ms
230,200 KB
testcase_10 AC 218 ms
232,056 KB
testcase_11 AC 250 ms
248,540 KB
testcase_12 AC 157 ms
205,464 KB
testcase_13 AC 262 ms
251,712 KB
testcase_14 AC 276 ms
258,676 KB
testcase_15 AC 162 ms
223,860 KB
testcase_16 AC 164 ms
228,012 KB
testcase_17 AC 220 ms
244,316 KB
testcase_18 AC 244 ms
240,212 KB
testcase_19 AC 5 ms
14,416 KB
testcase_20 AC 26 ms
114,004 KB
testcase_21 AC 25 ms
108,888 KB
testcase_22 AC 24 ms
109,912 KB
testcase_23 AC 24 ms
110,680 KB
testcase_24 AC 25 ms
109,268 KB
testcase_25 AC 25 ms
113,236 KB
testcase_26 AC 33 ms
152,280 KB
testcase_27 AC 37 ms
162,768 KB
testcase_28 AC 35 ms
160,600 KB
testcase_29 AC 35 ms
159,060 KB
testcase_30 AC 37 ms
164,948 KB
testcase_31 AC 34 ms
159,700 KB
testcase_32 AC 266 ms
262,884 KB
testcase_33 AC 265 ms
260,080 KB
testcase_34 AC 266 ms
256,244 KB
testcase_35 AC 272 ms
258,544 KB
testcase_36 AC 269 ms
259,956 KB
testcase_37 AC 3 ms
6,940 KB
testcase_38 AC 4 ms
10,700 KB
testcase_39 AC 4 ms
12,884 KB
testcase_40 AC 4 ms
12,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

string s[100];
int c[100];
ll dp[320000];
int nx[100][3200000];

int main(){
	int n,K;cin>>n>>K;
	rep(i,n){
		cin>>s[i]>>c[i];
	}
	rep(i,n){
		rep(j,3*K){
			if(j){
				int l=(j-1)/K,r=(j+100)/K;
				if(l==r){
					nx[i][j]=nx[i][j-1]+1;
					continue;
				}
			}
			int cur=j;
			rep(k,s[i].size()){
				char want=(cur<K?'J':(cur<2*K?'O':'I'));
				if(cur<3*K&&s[i][k]==want)cur++;
			}
			cur=min(cur,3*K);
			nx[i][j]=cur;
		}
	}
	memset(dp,0x3f,sizeof(dp));
	dp[0]=0;
	rep(i,3*K){
		if(dp[i]==INFL)continue;
		rep(j,n){
			dp[nx[j][i]]=min(dp[nx[j][i]],dp[i]+c[j]);
		}
	}
	if(dp[3*K]==INFL)puts("-1");
	else cout<<dp[3*K]<<endl;
}
0