結果

問題 No.1029 JJOOII 3
ユーザー queeequeee
提出日時 2020-04-17 22:37:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 74 ms / 2,000 ms
コード長 1,140 bytes
コンパイル時間 891 ms
コンパイル使用メモリ 77,396 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-14 14:55:17
合計ジャッジ時間 3,197 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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 16 ms
6,944 KB
testcase_05 AC 63 ms
6,944 KB
testcase_06 AC 46 ms
6,940 KB
testcase_07 AC 56 ms
6,940 KB
testcase_08 AC 61 ms
6,940 KB
testcase_09 AC 52 ms
6,944 KB
testcase_10 AC 55 ms
6,944 KB
testcase_11 AC 67 ms
6,940 KB
testcase_12 AC 39 ms
6,940 KB
testcase_13 AC 67 ms
6,940 KB
testcase_14 AC 69 ms
6,940 KB
testcase_15 AC 49 ms
6,944 KB
testcase_16 AC 59 ms
6,944 KB
testcase_17 AC 61 ms
6,940 KB
testcase_18 AC 64 ms
6,940 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 3 ms
6,940 KB
testcase_21 AC 3 ms
6,940 KB
testcase_22 AC 3 ms
6,940 KB
testcase_23 AC 3 ms
6,940 KB
testcase_24 AC 3 ms
6,940 KB
testcase_25 AC 3 ms
6,940 KB
testcase_26 AC 3 ms
6,940 KB
testcase_27 AC 4 ms
6,940 KB
testcase_28 AC 3 ms
6,940 KB
testcase_29 AC 3 ms
6,944 KB
testcase_30 AC 3 ms
6,944 KB
testcase_31 AC 3 ms
6,944 KB
testcase_32 AC 74 ms
6,944 KB
testcase_33 AC 74 ms
6,940 KB
testcase_34 AC 73 ms
6,940 KB
testcase_35 AC 73 ms
6,944 KB
testcase_36 AC 74 ms
6,940 KB
testcase_37 AC 2 ms
6,940 KB
testcase_38 AC 2 ms
6,940 KB
testcase_39 AC 1 ms
6,944 KB
testcase_40 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cmath>
#include <queue>
#include <cassert>
using namespace std; typedef long long ll; const ll INF=1e18;

int main() {
  int n,k; cin>>n>>k;
  string t;
  for(int i=0;i<k;i++) t+="J";
  for(int i=0;i<k;i++) t+="O";
  for(int i=0;i<k;i++) t+="I";

  string s[n]; ll c[n];
  for(int i=0;i<n;i++) {
    cin>>s[i]>>c[i];
  }
  int st[n][3]; fill(st[0], st[n], 0);
  for(int i=0;i<n;i++) {
    for(char ch:s[i]) {
      st[i][0] += ch == 'J';
      st[i][1] += ch == 'O';
      st[i][2] += ch == 'I';
    }
  }

  ll v[3*k+1]; fill(v,v+3*k+1,INF); v[0]=0;
  for(int i=0;i<3*k;i++) {
    for(int j=0;j<n;j++) {
      int u;
      if (0 <= i && i<k-80) {
        u=i+st[j][0];
      } else if (k<=i && i<2*k-80) {
        u=i+st[j][1];
      } else if (2*k<=i && i<3*k-80) {
        u=i+st[j][2];
      } else {
        u=i;
        for(char ch:s[j]) {
          if (ch == t[u]) u++;
          if (u == 3*k) break;
        }
      }
      v[u] = min(v[u], v[i]+c[j]);
    }
  }
  /*
  for(int i=0;i<=3*k;i++) {
    cout<<v[i]<<" ";
  } cout<<endl;*/
  if (v[3*k] == INF) cout<<"-1"<<endl;
  else cout<<v[3*k]<<endl;
}
0