結果

問題 No.1029 JJOOII 3
ユーザー DenteDente
提出日時 2020-04-17 22:56:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,736 ms / 2,000 ms
コード長 1,034 bytes
コンパイル時間 2,701 ms
コンパイル使用メモリ 182,604 KB
実行使用メモリ 6,148 KB
最終ジャッジ日時 2023-07-27 01:52:12
合計ジャッジ時間 23,638 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 57 ms
4,376 KB
testcase_04 AC 184 ms
5,284 KB
testcase_05 AC 806 ms
5,816 KB
testcase_06 AC 593 ms
5,084 KB
testcase_07 AC 697 ms
5,704 KB
testcase_08 AC 816 ms
5,572 KB
testcase_09 AC 654 ms
5,436 KB
testcase_10 AC 722 ms
5,552 KB
testcase_11 AC 929 ms
6,148 KB
testcase_12 AC 470 ms
4,788 KB
testcase_13 AC 843 ms
6,116 KB
testcase_14 AC 879 ms
5,924 KB
testcase_15 AC 584 ms
5,032 KB
testcase_16 AC 714 ms
5,412 KB
testcase_17 AC 815 ms
5,844 KB
testcase_18 AC 825 ms
5,944 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 3 ms
4,384 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,384 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 3 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1,733 ms
6,020 KB
testcase_33 AC 1,726 ms
6,012 KB
testcase_34 AC 1,735 ms
6,092 KB
testcase_35 AC 1,736 ms
6,048 KB
testcase_36 AC 1,735 ms
6,076 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 1 ms
4,384 KB
testcase_40 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#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;

ll dp[300000 + 1];

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n, k;
    cin >> n >> k;
    string s[n];
    ll c[n];
    rep(i, n) {
        cin >> s[i] >> c[i];
    }
    string t = string(k, 'J') + string(k, 'O') + string(k, 'I');
    fill(dp, dp + 3 * k + 1, LINF);
    dp[0] = 0;
    rep(i, 3 * k) {
        rep(j, n) {
            int now = 0;
            rep(l, s[j].size()) {
                if (s[j][l] == t[i + now]) {
                    now++;
                    dp[i + now] = min(dp[i + now], dp[i] + c[j]);
                }
            }
        }
    }
    cout << (dp[3 * k] != LINF ? dp[3 * k] : -1) << endl;
    return 0;
}
0