結果

問題 No.1029 JJOOII 3
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2020-04-17 22:58:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,397 bytes
コンパイル時間 1,639 ms
コンパイル使用メモリ 168,520 KB
実行使用メモリ 13,884 KB
最終ジャッジ日時 2024-04-14 15:18:48
合計ジャッジ時間 5,860 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,884 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 127 ms
6,944 KB
testcase_04 AC 414 ms
6,940 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

/*

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;
    }

}
0