結果

問題 No.1029 JJOOII 3
ユーザー carrot46carrot46
提出日時 2020-04-17 22:17:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,070 bytes
コンパイル時間 1,914 ms
コンパイル使用メモリ 174,040 KB
実行使用メモリ 258,176 KB
最終ジャッジ日時 2024-04-14 14:32:13
合計ジャッジ時間 7,716 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 15 ms
16,000 KB
testcase_04 AC 54 ms
50,176 KB
testcase_05 AC 244 ms
225,536 KB
testcase_06 AC 171 ms
160,640 KB
testcase_07 AC 211 ms
198,656 KB
testcase_08 AC 222 ms
211,200 KB
testcase_09 AC 197 ms
184,704 KB
testcase_10 AC 202 ms
192,384 KB
testcase_11 AC 258 ms
240,512 KB
testcase_12 AC 142 ms
132,224 KB
testcase_13 AC 255 ms
242,944 KB
testcase_14 AC 255 ms
246,528 KB
testcase_15 AC 176 ms
164,992 KB
testcase_16 AC 203 ms
191,104 KB
testcase_17 AC 240 ms
224,512 KB
testcase_18 AC 245 ms
228,224 KB
testcase_19 WA -
testcase_20 AC 3 ms
6,944 KB
testcase_21 AC 3 ms
6,940 KB
testcase_22 AC 4 ms
6,940 KB
testcase_23 AC 3 ms
6,940 KB
testcase_24 AC 3 ms
6,940 KB
testcase_25 AC 3 ms
6,940 KB
testcase_26 AC 3 ms
6,940 KB
testcase_27 AC 4 ms
6,940 KB
testcase_28 AC 4 ms
6,944 KB
testcase_29 AC 3 ms
6,940 KB
testcase_30 AC 4 ms
6,940 KB
testcase_31 AC 4 ms
6,944 KB
testcase_32 AC 268 ms
258,048 KB
testcase_33 AC 267 ms
258,176 KB
testcase_34 AC 276 ms
258,048 KB
testcase_35 AC 280 ms
258,176 KB
testcase_36 AC 276 ms
258,176 KB
testcase_37 WA -
testcase_38 AC 2 ms
6,940 KB
testcase_39 AC 2 ms
6,944 KB
testcase_40 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
const ll INF = 1LL<<60;
typedef pair<ll, ll> P;

template<class T> bool chmin(T &a, const T &b){
    if(a > b) {a = b; return true;}
    else return false;
}
template<class T> bool chmax(T &a, const T &b){
    if(a < b) {a = b; return true;}
    else return false;
}

int main() {
    cin>>N>>K;
    vector<string> s(N);
    vec cost(N);
    rep(i,N) cin>>s[i]>>cost[i];
    mat num(N, vec(3, 0));
    rep(i,N){
        for(char c : s[i]){
            ++num[i][c == 'J' ? 0 : (c == 'O' ? 1 : 2)];
        }
    }
    vector<mat> dp(3, mat(N + 1, vec(K + 81, INF)));
    dp[0][0][0] = 0;
    string JOI = "JOI";
    rep(c, 3){
        if(c > 0){
            reps(j, max(0LL, K - 80), K + 81) {
                ll temp = dp[c - 1][N][j];
                rep(k, N) {
                    ll rest = max(0LL, K - j);
                    for (char si : s[k]) {
                        if (rest > 0) {
                            rest -= si == JOI[c - 1];
                        } else {
                            rest -= si == JOI[c];
                        }
                    }
                    if (rest <= 0) chmin(dp[c][0][min(K + 80, -rest)], temp + cost[k]);
                }
            }

        }
        rep(i,N){
            rep(j, K + 81){
                chmin(dp[c][i+1][j], dp[c][i][j]);
                if(j >= num[i][c]) chmin(dp[c][i+1][j], dp[c][i+1][j - num[i][c]] + cost[i]);
                //if(j <= K) cout<<dp[c][i+1][j]<<' ';
            }
            //cout<<endl;
        }
    }
    ll ans = INF;
    reps(j,K,K + 81) chmin(ans, dp[2][N][j]);
    cout<<(ans == INF ? -1 : ans)<<endl;
}
0