結果

問題 No.1029 JJOOII 3
ユーザー queeequeee
提出日時 2020-04-17 22:30:00
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 909 bytes
コンパイル時間 735 ms
コンパイル使用メモリ 76,520 KB
実行使用メモリ 88,768 KB
最終ジャッジ日時 2024-10-03 14:05:12
合計ジャッジ時間 20,405 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 2 TLE * 7 -- * 29
権限があれば一括ダウンロードができます

ソースコード

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