結果
| 問題 |
No.1029 JJOOII 3
|
| コンテスト | |
| ユーザー |
👑 SPD_9X2
|
| 提出日時 | 2020-04-17 22:58:10 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,397 bytes |
| コンパイル時間 | 1,480 ms |
| コンパイル使用メモリ | 171,708 KB |
| 実行使用メモリ | 10,624 KB |
| 最終ジャッジ日時 | 2024-10-03 14:52:51 |
| 合計ジャッジ時間 | 6,041 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 2 TLE * 7 -- * 29 |
ソースコード
/*
https://yukicoder.me/problems/no/1029
個数無制限ナップザック?
部分文字列としてどこまで完成されているかを
0 ~ 3Kで表す?
各Kに関して、どの数字の時に何を足すといくつ増えるかをO(1)でだせれば
あとはO(KN)の平易なdpでいける
適当に2分探索すれば行けるのでは??
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n,m) for(ll (i)=(n);(i)<(m);(i)++)
#define rrep(i,n,m) for(ll (i)=(n);(i)>(m);(i)--)
using ll = long long;
const ll mod = 998244353;
ll want(ll now,ll K,string S){
rep(i,0,S.size()){
if ((now < K) && (S[i] == 'J')){
now++;
}else if( (K <= now)&&(now < 2*K)&&(S[i]=='O' )){
now++;
}else if( (2*K <= now) && (now < 3*K) && (S[i]=='I')){
now++;
}
}
return now;
}
int main(){
ll N,K;
cin >> N >> K;
int flag = 0;
vector<string> S(N,"");
vector<ll> C(N,0);
rep(i,0,N){
cin >> S[i] >> C[i];
}
vector<ll> ans(3*K+1,LLONG_MAX/5);
ans[0] = 0;
ll nex;
rep(i,0,3*K){
rep(j,0,N){
nex = want(i,K,S[j]);
ans[nex] = min(ans[nex] , ans[i] + C[j]);
if (nex == 3*K) flag = 1;
}
}
if (flag == 1){
cout << ans[3*K] << endl;
}else{
cout << -1 << endl;
}
}
SPD_9X2