結果
問題 |
No.1029 JJOOII 3
|
ユーザー |
|
提出日時 | 2020-04-17 22:12:47 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 641 bytes |
コンパイル時間 | 1,534 ms |
コンパイル使用メモリ | 167,240 KB |
実行使用メモリ | 12,704 KB |
最終ジャッジ日時 | 2024-10-03 13:36:00 |
合計ジャッジ時間 | 26,037 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 TLE * 4 -- * 8 |
ソースコード
#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; }