結果

問題 No.1029 JJOOII 3
ユーザー risujirohrisujiroh
提出日時 2020-04-17 22:30:13
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 76 ms / 2,000 ms
コード長 1,345 bytes
コンパイル時間 2,254 ms
コンパイル使用メモリ 203,944 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-14 14:47:26
合計ジャッジ時間 4,712 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 6 ms
6,944 KB
testcase_04 AC 15 ms
6,944 KB
testcase_05 AC 66 ms
6,944 KB
testcase_06 AC 48 ms
6,940 KB
testcase_07 AC 59 ms
6,944 KB
testcase_08 AC 62 ms
6,940 KB
testcase_09 AC 55 ms
6,940 KB
testcase_10 AC 56 ms
6,944 KB
testcase_11 AC 71 ms
6,944 KB
testcase_12 AC 38 ms
6,940 KB
testcase_13 AC 71 ms
6,940 KB
testcase_14 AC 72 ms
6,944 KB
testcase_15 AC 49 ms
6,940 KB
testcase_16 AC 56 ms
6,944 KB
testcase_17 AC 66 ms
6,940 KB
testcase_18 AC 66 ms
6,940 KB
testcase_19 AC 1 ms
6,944 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 2 ms
6,944 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 2 ms
6,940 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 2 ms
6,940 KB
testcase_31 AC 3 ms
6,940 KB
testcase_32 AC 76 ms
6,944 KB
testcase_33 AC 76 ms
6,940 KB
testcase_34 AC 76 ms
6,944 KB
testcase_35 AC 76 ms
6,940 KB
testcase_36 AC 75 ms
6,944 KB
testcase_37 AC 2 ms
6,944 KB
testcase_38 AC 2 ms
6,940 KB
testcase_39 AC 2 ms
6,940 KB
testcase_40 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

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);
  vector<array<int, 3>> cnt(n);
  for (int i = 0; i < n; ++i) {
    cin >> s[i] >> cost[i];
    cnt[i][0] = count(begin(s[i]), end(s[i]), 'J');
    cnt[i][1] = count(begin(s[i]), end(s[i]), 'O');
    cnt[i][2] = count(begin(s[i]), end(s[i]), 'I');
  }
  for (int j = m; j--; ) {
    for (int i = 0; i < n; ++i) {
      int ptr = j;
      if (j >= 2 * k) {
        ptr = min(ptr + cnt[i][2], m);
      } else if (k <= j and j < 2 * k and j + cnt[i][1] < 2 * k) {
        ptr += cnt[i][1];
      } else if (j < k and j + cnt[i][0] < k) {
        ptr += cnt[i][0];
      } else {
        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