結果

問題 No.1029 JJOOII 3
ユーザー risujirohrisujiroh
提出日時 2020-04-17 22:19:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 894 bytes
コンパイル時間 2,154 ms
コンパイル使用メモリ 201,332 KB
実行使用メモリ 13,884 KB
最終ジャッジ日時 2024-04-14 14:34:54
合計ジャッジ時間 21,587 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,884 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 195 ms
6,940 KB
testcase_04 AC 625 ms
6,940 KB
testcase_05 TLE -
testcase_06 TLE -
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;

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1;

auto chmin = [](auto&& a, auto b) { return b < a ? a = b, 1 : 0; };

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  string t = string(k, 'J') + string(k, 'O') + string(k, 'I');
  int m = t.size();
  vector dp(m + 1, inf<long long>);
  dp[m] = 0;
  vector<string> s(n);
  vector<int> cost(n);
  for (int i = 0; i < n; ++i) {
    cin >> s[i] >> cost[i];
  }
  for (int j = m; j--; ) {
    for (int i = 0; i < n; ++i) {
      int ptr = j;
      for (char c : s[i]) {
        if (ptr < m) {
          ptr += c == t[ptr];
        }
      }
      chmin(dp[j], cost[i] + dp[ptr]);
    }
  }
  if (dp[0] >= inf<long long>) {
    dp[0] = -1;
  }
  cout << dp[0] << '\n';
}
0