結果

問題 No.1029 JJOOII 3
ユーザー Dente
提出日時 2020-04-17 22:52:45
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,036 bytes
コンパイル時間 1,757 ms
コンパイル使用メモリ 170,480 KB
実行使用メモリ 13,640 KB
最終ジャッジ日時 2024-10-03 14:43:41
合計ジャッジ時間 27,699 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28 TLE * 2 -- * 8
権限があれば一括ダウンロードができます

ソースコード

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;

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;
    rep(i, k) {
        t.push_back('J');
    }
    rep(i, k) {
        t.push_back('O');
    }
    rep(i, k) {
        t.push_back('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