結果

問題 No.1029 JJOOII 3
ユーザー autumn-eelautumn-eel
提出日時 2020-04-17 22:12:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 641 bytes
コンパイル時間 1,540 ms
コンパイル使用メモリ 163,964 KB
実行使用メモリ 13,756 KB
最終ジャッジ日時 2024-04-14 14:29:54
合計ジャッジ時間 6,075 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
13,756 KB
testcase_01 AC 4 ms
6,944 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 204 ms
6,940 KB
testcase_04 AC 665 ms
6,940 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます

ソースコード

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