結果
問題 | No.1029 JJOOII 3 |
ユーザー |
|
提出日時 | 2020-04-17 22:33:17 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 264 ms / 2,000 ms |
コード長 | 852 bytes |
コンパイル時間 | 1,447 ms |
コンパイル使用メモリ | 169,512 KB |
実行使用メモリ | 148,372 KB |
最終ジャッジ日時 | 2024-10-03 14:10:00 |
合計ジャッジ時間 | 6,909 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
#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; }