結果

問題 No.1029 JJOOII 3
ユーザー finefine
提出日時 2020-04-17 22:19:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 982 bytes
コンパイル時間 1,616 ms
コンパイル使用メモリ 168,096 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-14 14:36:08
合計ジャッジ時間 33,051 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

constexpr ll INF = 1e17;

inline char target_char(int nexi, int K) {
    if (nexi < K) return 'J';
    if (nexi < 2 * K) return 'O';
    if (nexi < 3 * K) return 'I';
    else return '#';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, K;
    cin >> n >> K;

    vector<string> s(n);
    vector<ll> c(n);
    for (int i = 0; i < n; ++i) {
        cin >> s[i] >> c[i];
    }

    vector<ll> dp(3 * K + 1, INF);
    dp[0] = 0;
    for (int i = 0; i < 3 * K; ++i) {
        if (dp[i] >= INF) continue;
        for (int j = 0; j < n; ++j) {
            int nexi = i;
            for (char ch : s[j]) {
                char tar = target_char(nexi, K);
                if (tar == ch) ++nexi;
            }
            if (nexi == i) continue;
            dp[nexi] = min(dp[nexi], dp[i] + c[j]);
        }
    }
    cout << (dp[3 * K] >= INF ? -1 : dp[3 * K]) << "\n";
    return 0;
}
0