結果

問題 No.1029 JJOOII 3
ユーザー queeequeee
提出日時 2020-04-17 22:30:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 909 bytes
コンパイル時間 810 ms
コンパイル使用メモリ 76,900 KB
実行使用メモリ 92,428 KB
最終ジャッジ日時 2024-04-14 14:47:48
合計ジャッジ時間 20,318 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,764 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 198 ms
8,388 KB
testcase_04 AC 631 ms
21,960 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 <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 p[3*k][n];
  for(int i=0;i<3*k;i++) {
    for(int j=0;j<n;j++) {
      int u=i;
      for(char ch:s[j]) {
        if (ch == t[u]) u++;
        if (u == 3*k) break;
      }
      p[i][j]=u;
    }
  }

  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=p[i][j];
      ll cost = v[i] + c[j];
      if (v[u] > cost) {
        v[u] = cost;
      }
    }
  }
  /*
  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