結果

問題 No.1029 JJOOII 3
ユーザー beetbeet
提出日時 2020-04-17 21:30:09
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,385 bytes
コンパイル時間 2,190 ms
コンパイル使用メモリ 200,072 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-14 13:04:50
合計ジャッジ時間 4,560 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,812 KB
testcase_01 AC 4 ms
6,812 KB
testcase_02 AC 4 ms
6,816 KB
testcase_03 AC 6 ms
6,940 KB
testcase_04 AC 11 ms
6,944 KB
testcase_05 AC 38 ms
6,940 KB
testcase_06 AC 27 ms
6,940 KB
testcase_07 AC 35 ms
6,944 KB
testcase_08 AC 37 ms
6,940 KB
testcase_09 AC 32 ms
6,944 KB
testcase_10 AC 35 ms
6,940 KB
testcase_11 AC 39 ms
6,940 KB
testcase_12 AC 23 ms
6,940 KB
testcase_13 AC 41 ms
6,940 KB
testcase_14 AC 42 ms
6,948 KB
testcase_15 AC 29 ms
6,940 KB
testcase_16 AC 33 ms
6,940 KB
testcase_17 AC 40 ms
6,940 KB
testcase_18 AC 40 ms
6,940 KB
testcase_19 WA -
testcase_20 AC 3 ms
6,940 KB
testcase_21 AC 4 ms
6,944 KB
testcase_22 AC 4 ms
6,940 KB
testcase_23 AC 4 ms
6,944 KB
testcase_24 AC 4 ms
6,940 KB
testcase_25 AC 4 ms
6,944 KB
testcase_26 AC 3 ms
6,940 KB
testcase_27 AC 4 ms
6,940 KB
testcase_28 AC 4 ms
6,944 KB
testcase_29 AC 3 ms
6,940 KB
testcase_30 AC 4 ms
6,940 KB
testcase_31 AC 5 ms
6,940 KB
testcase_32 AC 44 ms
6,940 KB
testcase_33 AC 46 ms
6,940 KB
testcase_34 AC 47 ms
6,940 KB
testcase_35 AC 46 ms
6,944 KB
testcase_36 AC 44 ms
6,940 KB
testcase_37 WA -
testcase_38 AC 3 ms
6,940 KB
testcase_39 WA -
testcase_40 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';

//INSERT ABOVE HERE
const Int MAX = 1e5+100;
const Int INF = 1e18;
Int dp[4][MAX];

Int cnt[4][100]={};

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  for(Int i=0;i<4;i++)
    for(Int j=0;j<MAX;j++)
      dp[i][j]=INF;

  Int n,k;
  cin>>n>>k;

  vector<string> ss(n);
  vector<Int> cs(n);
  for(Int i=0;i<n;i++) cin>>ss[i]>>cs[i];

  string B="JOI$";
  for(Int i=0;i<3;i++)
    for(Int p=0;p<n;p++)
      for(char c:ss[p])
        if(c==B[i]) cnt[i][p]++;

  dp[0][0]=0;
  for(Int i=0;i<3;i++){
    for(Int j=0;j<k;j++){
      for(Int p=0;p<n;p++){
        if(j+cnt[i][p]<k){
          chmin(dp[i][j+cnt[i][p]],dp[i][j]+cs[p]);
        }else{
          Int need=k-j,start=0;
          for(char c:ss[p]){
            if(c==B[i]) need--;
            if(need<=0 and c==B[i+1]) start++;
          }
          if(need>0){
            cout<<j<<" "<<k<<endl;
            cout<<cnt[i][p]<<endl;
            cout<<B[i]<<' '<<ss[p]<<endl;
          }
          assert(need<=0);
          chmin(dp[i+1][start],dp[i][j]+cs[p]);
        }
      }
    }
  }

  Int ans=dp[3][0];
  if(ans==INF) ans=-1;
  cout<<ans<<newl;
  return 0;
}
0