結果
| 問題 |
No.1029 JJOOII 3
|
| コンテスト | |
| ユーザー |
beet
|
| 提出日時 | 2020-04-17 21:30:09 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,385 bytes |
| コンパイル時間 | 2,872 ms |
| コンパイル使用メモリ | 197,896 KB |
| 最終ジャッジ日時 | 2025-01-09 19:46:14 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 WA * 4 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';
//INSERT ABOVE HERE
const Int MAX = 1e5+100;
const Int INF = 1e18;
Int dp[4][MAX];
Int cnt[4][100]={};
signed main(){
cin.tie(0);
ios::sync_with_stdio(0);
for(Int i=0;i<4;i++)
for(Int j=0;j<MAX;j++)
dp[i][j]=INF;
Int n,k;
cin>>n>>k;
vector<string> ss(n);
vector<Int> cs(n);
for(Int i=0;i<n;i++) cin>>ss[i]>>cs[i];
string B="JOI$";
for(Int i=0;i<3;i++)
for(Int p=0;p<n;p++)
for(char c:ss[p])
if(c==B[i]) cnt[i][p]++;
dp[0][0]=0;
for(Int i=0;i<3;i++){
for(Int j=0;j<k;j++){
for(Int p=0;p<n;p++){
if(j+cnt[i][p]<k){
chmin(dp[i][j+cnt[i][p]],dp[i][j]+cs[p]);
}else{
Int need=k-j,start=0;
for(char c:ss[p]){
if(c==B[i]) need--;
if(need<=0 and c==B[i+1]) start++;
}
if(need>0){
cout<<j<<" "<<k<<endl;
cout<<cnt[i][p]<<endl;
cout<<B[i]<<' '<<ss[p]<<endl;
}
assert(need<=0);
chmin(dp[i+1][start],dp[i][j]+cs[p]);
}
}
}
}
Int ans=dp[3][0];
if(ans==INF) ans=-1;
cout<<ans<<newl;
return 0;
}
beet