結果

問題 No.1029 JJOOII 3
ユーザー 👑 hitonanodehitonanode
提出日時 2020-04-20 01:53:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,017 bytes
コンパイル時間 2,503 ms
コンパイル使用メモリ 200,004 KB
実行使用メモリ 13,880 KB
最終ジャッジ日時 2024-04-16 00:27:50
合計ジャッジ時間 20,887 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 149 ms
5,376 KB
testcase_04 AC 492 ms
5,376 KB
testcase_05 TLE -
testcase_06 AC 1,991 ms
6,944 KB
testcase_07 TLE -
testcase_08 TLE -
testcase_09 TLE -
testcase_10 TLE -
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます

ソースコード

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)

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<lint> cost(K * 3 + 1, 9e18);
    cost[0] = 0;
    REP(i, K * 3)
    {
        if (cost[i] == 9e18)
        {
            puts("-1");
            return 0;
        }
        REP(j, N)
        {
            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() << '\n';
}
0