結果

問題 No.1029 JJOOII 3
ユーザー pekempeypekempey
提出日時 2020-04-17 22:36:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 871 bytes
コンパイル時間 1,607 ms
コンパイル使用メモリ 168,896 KB
実行使用メモリ 9,972 KB
最終ジャッジ日時 2023-07-27 01:32:29
合計ジャッジ時間 25,495 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,756 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 119 ms
4,376 KB
testcase_04 AC 395 ms
4,552 KB
testcase_05 AC 1,735 ms
5,152 KB
testcase_06 AC 1,271 ms
4,684 KB
testcase_07 AC 1,495 ms
4,896 KB
testcase_08 AC 1,767 ms
4,824 KB
testcase_09 AC 1,401 ms
4,952 KB
testcase_10 AC 1,555 ms
4,816 KB
testcase_11 AC 1,993 ms
5,460 KB
testcase_12 AC 1,007 ms
4,428 KB
testcase_13 AC 1,820 ms
5,364 KB
testcase_14 AC 1,884 ms
5,368 KB
testcase_15 AC 332 ms
4,560 KB
testcase_16 AC 3 ms
4,828 KB
testcase_17 AC 1,023 ms
5,344 KB
testcase_18 AC 1,711 ms
5,132 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 3 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 3 ms
4,384 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 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>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N, K; cin >> N >> K;
  vector<ll> dp(3 * K + 1, LLONG_MAX);
  dp[0] = 0;
  vector<string> S(N);
  vector<ll> C(N);
  rep(i, N) cin >> S[i] >> C[i];
  rep(i, 3 * K) if (dp[i] != LLONG_MAX) {
    rep(j, N) {
      int l = i;
      for (char c : S[j]) {
        if (l < K) {
          if (c == 'J') l++;
        } else if (l < 2 * K) {
          if (c == 'O') l++;
        } else if (l < 3 * K) {
          if (c == 'I') l++;
        }
      }
      dp[l] = min(dp[l], dp[i] + C[j]);
    }
  }
  if (dp[3 * K] == LLONG_MAX) {
    cout << -1 << endl;
  } else {
    cout << dp[3 * K] << endl;
  }
}
0