結果
| 問題 |
No.1029 JJOOII 3
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-17 22:12:05 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 640 bytes |
| コンパイル時間 | 1,459 ms |
| コンパイル使用メモリ | 168,112 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-03 13:23:54 |
| 合計ジャッジ時間 | 4,610 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 WA * 16 |
ソースコード
#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];
int 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]==INF)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]==INF)puts("-1");
else cout<<dp[3*K]<<endl;
}