結果

問題 No.1029 JJOOII 3
ユーザー knshnbknshnb
提出日時 2020-04-17 22:07:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,553 bytes
コンパイル時間 2,262 ms
コンパイル使用メモリ 202,116 KB
実行使用メモリ 13,760 KB
最終ジャッジ日時 2024-04-14 14:18:06
合計ジャッジ時間 20,887 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,760 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 70 ms
6,944 KB
testcase_04 AC 238 ms
6,944 KB
testcase_05 AC 1,066 ms
6,940 KB
testcase_06 AC 826 ms
6,944 KB
testcase_07 AC 923 ms
6,940 KB
testcase_08 AC 1,120 ms
6,944 KB
testcase_09 AC 862 ms
6,944 KB
testcase_10 AC 984 ms
6,940 KB
testcase_11 AC 1,302 ms
6,940 KB
testcase_12 AC 624 ms
6,940 KB
testcase_13 AC 1,126 ms
6,940 KB
testcase_14 AC 1,179 ms
6,940 KB
testcase_15 AC 813 ms
6,940 KB
testcase_16 AC 966 ms
6,940 KB
testcase_17 AC 1,124 ms
6,940 KB
testcase_18 AC 1,116 ms
6,944 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 3 ms
6,944 KB
testcase_21 AC 3 ms
6,944 KB
testcase_22 AC 3 ms
6,940 KB
testcase_23 AC 3 ms
6,940 KB
testcase_24 AC 3 ms
6,944 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 3 ms
6,944 KB
testcase_29 AC 3 ms
6,940 KB
testcase_30 AC 4 ms
6,940 KB
testcase_31 AC 3 ms
6,940 KB
testcase_32 TLE -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Fri Apr 17 21:50:59 JST 2020
 **/

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

const Int INF = 2e18;
signed main() {
    Int n, K;
    std::cin >> n >> K;
    std::string T(3 * K + 100, '$');
    REP(i, K) T[i] = 'J';
    REP(i, K, 2 * K) T[i] = 'O';
    REP(i, 2 * K, 3 * K) T[i] = 'I';
    std::vector<std::pair<std::string, Int>> ps(n);
    REP(i, n) std::cin >> ps[i].first >> ps[i].second;
    std::vector<Int> dp(3 * K + 100, INF);
    dp[0] = 0;
    REP(i, 3 * K) {
        for (auto& p : ps) {
            Int j = i, idx = 0;
            std::string& s = p.first;
            while (1) {
                idx = std::find(s.begin() + idx, s.end(), T[j]) - s.begin() + 1;
                if (idx > s.size()) break;
                j++;
            }
            chmin(dp[j], dp[i] + p.second);
        }
    }
    std::cout << (dp[3 * K] == INF ? -1 : dp[3 * K]) << std::endl;
}
0