結果

問題 No.1029 JJOOII 3
ユーザー 👑 hitonanodehitonanode
提出日時 2020-04-20 02:00:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 1,602 bytes
コンパイル時間 2,482 ms
コンパイル使用メモリ 201,512 KB
実行使用メモリ 5,760 KB
最終ジャッジ日時 2024-04-16 00:28:54
合計ジャッジ時間 3,810 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 4 ms
5,376 KB
testcase_04 AC 8 ms
5,376 KB
testcase_05 AC 35 ms
5,376 KB
testcase_06 AC 25 ms
5,376 KB
testcase_07 AC 25 ms
5,376 KB
testcase_08 AC 32 ms
5,376 KB
testcase_09 AC 33 ms
5,376 KB
testcase_10 AC 35 ms
5,376 KB
testcase_11 AC 37 ms
5,632 KB
testcase_12 AC 23 ms
5,376 KB
testcase_13 AC 37 ms
5,632 KB
testcase_14 AC 38 ms
5,632 KB
testcase_15 AC 8 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 26 ms
5,376 KB
testcase_18 AC 42 ms
5,504 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 3 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 3 ms
5,376 KB
testcase_31 AC 3 ms
5,376 KB
testcase_32 AC 45 ms
5,632 KB
testcase_33 AC 37 ms
5,760 KB
testcase_34 AC 43 ms
5,760 KB
testcase_35 AC 39 ms
5,760 KB
testcase_36 AC 40 ms
5,760 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define REP(i, n) FOR(i,0,n)
template<typename T> bool chmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }


int main()
{
    int N, K;
    cin >> N >> K;
    vector<string> S(N);
    vector<lint> C(N);
    REP(i, N) cin >> S[i] >> C[i];
    vector<int> cntj(N), cnto(N), cnti(N);
    REP(i, N) for (auto c : S[i])
    {
        if (c == 'J') cntj[i]++;
        if (c == 'O') cnto[i]++;
        if (c == 'I') cnti[i]++;
    }

    vector<lint> cost(K * 3 + 1, 9e18);
    cost[0] = 0;
    REP(i, K * 3) if (cost[i] < cost[i + 1])
    {
        REP(j, N)
        {
            if (i + 100 < K) chmin(cost[i + cntj[j]], cost[i] + C[j]);
            else if (i >= K and i + 100 < K * 2) chmin(cost[i + cnto[j]], cost[i] + C[j]);
            else if (i >= K * 2 and i + 100 < K * 3) chmin(cost[i + cnti[j]], cost[i] + C[j]);
            else
            {
                int now = i;
                for (auto c : S[j])
                {
                    if (now < K and c == 'J') now++;
                    if (now >= K and now < K * 2 and c == 'O') now++;
                    if (now >= K * 2 and now < K * 3 and c == 'I') now++;
                }
                cost[now] = min(cost[now], cost[i] + C[j]);
            }
        }
    }
    cout << (cost.back() == 9e18 ? -1 : cost.back()) << '\n';
}
0