結果

問題 No.1029 JJOOII 3
ユーザー DenteDente
提出日時 2020-04-17 22:33:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,692 bytes
コンパイル時間 2,003 ms
コンパイル使用メモリ 177,872 KB
実行使用メモリ 13,616 KB
最終ジャッジ日時 2024-04-14 14:51:15
合計ジャッジ時間 8,597 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,368 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 WA -
testcase_04 TLE -
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 #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int n, k;
    cin >> n >> k;
    string s[n];
    ll c[n];
    rep(i, n) {
        cin >> s[i] >> c[i];
    }
    map<string, ll> mp;
    rep(i, n) {
        rep(j, s[i].size() + 1) {
            for (int k = j; k < s[i].size() + 1; k++){
                string t;
                rep(l, j) {
                    if (s[i][l] == 'J') t.push_back('J');
                }
                if (k == j) goto fin;
                for (int l = j; l < k; l++) {
                    if (s[i][l] == 'O') t.push_back('O');
                }
                for (int l = k; l < s[i].size(); l++) {
                    if (s[i][l] == 'I') t.push_back('I');
                }
            fin:;
                if(mp.count(t)){
                    mp[t] = min(mp[t], c[i]);
                }else{
                    mp[t] = c[i];
                }
            }
        }
    }
    string t;
    rep(i, k) {
        t.push_back('J');
    }
    rep(i, k) {
        t.push_back('O');
    }
    rep(i, k) {
        t.push_back('I');
    }
    ll dp[3 * k + 1];
    fill(dp, dp + 3 * k + 1, LINF);
    dp[0] = 0;
    rep(i, 3 * k) {
        for (int j = 1; j <= 80; j++) {
            if (i + j > 3 * k) continue;
            if (mp.count(t.substr(i, j)))
                dp[i + j] = min(dp[i + j], dp[i] + mp[t.substr(i, j)]);
        }
    }
    cout << (dp[3 * k] != LINF ? dp[3 * k] : - 1)<< endl;
    return 0;
}
0