結果

問題 No.1029 JJOOII 3
ユーザー yuji9511yuji9511
提出日時 2020-04-18 01:14:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,756 bytes
コンパイル時間 1,725 ms
コンパイル使用メモリ 167,412 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-14 18:44:54
合計ジャッジ時間 4,778 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,K;
    cin >> N >> K;
    string S[85];
    ll C[85];
    rep(i,0,N) cin >> S[i] >> C[i];
    ll dp[300010] = {};
    rep(i,0,3*K+1) dp[i] = INF;
    string T = "";
    T += string(K, 'J');
    T += string(K, 'O');
    T += string(K, 'I');
    dp[0] = 0;
    ll cj[85] = {}, co[85] = {}, ci[85] = {};
    rep(i,0,N){
        for(auto &e: S[i]){
            if(e == 'J') cj[i]++;
            else if(e == 'O') co[i]++;
            else ci[i]++;
        }
    }
    rep(i,0,3*K){
        rep(j,0,N){
            ll idx = i;
            ll cnt = 0;
            if(abs(K - i) <= 100 || abs(2*K - i) <= 100){
                rep(k,0,S[j].size()){
                    if(idx >= 3*K) break;
                    if(T[idx] == S[j][k]){
                        cnt++;
                        idx++;
                    }
                }

            }else{
                if(i <= K){
                    cnt = cj[j];
                }else if(i <= 2*K){
                    cnt = co[j];
                }else{
                    cnt = ci[j];
                }
            }
            dp[i+cnt] = min(dp[i+cnt], dp[i] + C[j]);
        }
    }
    if(dp[3*K] == INF){
        print(-1);
    }else{
        print(dp[3*K]);
    }
    

}
0