結果

問題 No.1029 JJOOII 3
ユーザー ChanyuhChanyuh
提出日時 2020-04-25 22:56:44
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 3,561 bytes
コンパイル時間 871 ms
コンパイル使用メモリ 107,336 KB
実行使用メモリ 207,588 KB
最終ジャッジ日時 2024-04-25 13:43:00
合計ジャッジ時間 26,654 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
22,796 KB
testcase_01 AC 4 ms
13,540 KB
testcase_02 AC 5 ms
19,820 KB
testcase_03 AC 66 ms
59,008 KB
testcase_04 WA -
testcase_05 AC 919 ms
198,408 KB
testcase_06 AC 1,162 ms
200,696 KB
testcase_07 AC 816 ms
196,152 KB
testcase_08 AC 1,070 ms
196,288 KB
testcase_09 AC 766 ms
194,480 KB
testcase_10 WA -
testcase_11 AC 1,088 ms
198,660 KB
testcase_12 AC 790 ms
192,380 KB
testcase_13 AC 796 ms
198,736 KB
testcase_14 AC 950 ms
200,776 KB
testcase_15 AC 67 ms
198,456 KB
testcase_16 AC 70 ms
190,612 KB
testcase_17 AC 741 ms
192,544 KB
testcase_18 WA -
testcase_19 AC 5 ms
19,824 KB
testcase_20 AC 898 ms
134,520 KB
testcase_21 AC 911 ms
130,420 KB
testcase_22 AC 1,079 ms
128,372 KB
testcase_23 AC 674 ms
130,428 KB
testcase_24 AC 897 ms
128,508 KB
testcase_25 AC 1,082 ms
134,516 KB
testcase_26 AC 1,412 ms
177,532 KB
testcase_27 AC 1,942 ms
189,820 KB
testcase_28 AC 620 ms
187,776 KB
testcase_29 AC 412 ms
183,672 KB
testcase_30 WA -
testcase_31 AC 561 ms
183,676 KB
testcase_32 TLE -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int n,k;
ll c[85];
vector<int> s[85];
int cnt[85][3];
ll mono[3][100010];
ll dp[3][85][100010];

void solve(){
  cin >> n >> k;
  rep(i,n){
    string s_;
    cin >> s_ >> c[i];
    s[i].resize(s_.size());
    rep(j,s_.size()){
      if(s_[j]=='J'){
        s[i][j]=0;
        cnt[i][0]+=1;
      }
      if(s_[j]=='O'){
        s[i][j]=1;
        cnt[i][1]+=1;
      }
      if(s_[j]=='I'){
        s[i][j]=2;
        cnt[i][2]+=1;
      }
    }
  }
  // rep(i,n){
  //   rep(p,3){
  //     cout << cnt[i][p] << " ";
  //   }
  //   cout << "" << endl;
  //}
  rep(p,3){
    rep(i,n+1){
      rep(j,k+1){
        dp[p][i][j]=INF;
      }
    }
  }
  rep(p,3){
    dp[p][0][0]=0;
    rep(i,n){
      rep(j,k+1){
        if(j-cnt[i][p]>=0)dp[p][i+1][j]=min(dp[p][i][j],dp[p][i+1][j-cnt[i][p]]+c[i]);
        else if(j==k) dp[p][i+1][j]=min(dp[p][i][j],dp[p][i+1][0]+c[i]);
        else dp[p][i+1][j]=dp[p][i][j];
      }
    }
  }
  // rep(p,3){
  //   rep(i,n+1){
  //     rep(j,k+1){
  //       cout << p << " " << i << " " << j << " " << dp[p][i][j] << endl;
  //     }
  //   }
  // }
  rep(p,3){
    rep(j,k+2){
      mono[p][j]=INF;
    }
  }
  rep(p,3){
    per(j,k+1){
      mono[p][j]=min(mono[p][j+1],dp[p][n][j]);
    }
  }
  // rep(p,3){
  //   rep(j,k+1){
  //     cout << p << " " << j << " " << mono[p][j] << endl;
  //   }
  // }
  ll ans=INF;
  rep(i1,n){
    int J_num=0;
    rep(t1,s[i1].size()){
      if(s[i1][t1]!=0) continue;
      J_num+=1;
      int O_num1=0;
      Per(t2,t1+1,s[i1].size()){
        if(s[i1][t2]!=1) continue;
        O_num1+=1;
        rep(i2,n){
          int O_num2=0;
          rep(t3,s[i2].size()){
            if(s[i2][t3]!=1) continue;
            O_num2+=1;
            int I_num=0;
            Per(t4,t3+1,s[i2].size()){
              if(s[i2][t4]!=2) continue;
              I_num+=1;
              ans=min(ans,c[i1]+c[i2]+mono[0][max(0,k-J_num)]+mono[1][max(0,k-O_num1-O_num2)]+mono[2][max(0,k-I_num)]);
            }
          }
        }
      }
    }
  }
  rep(i,n){
    int J_num=0;
    rep(t1,s[i].size()){
      if(s[i][t1]!=0) continue;
      J_num+=1;
      int I_num=0;
      Per(t2,t1+1,s[i].size()){
        if(s[i][t2]!=2) continue;
        I_num+=1;
        int O_num=0;
        Rep(t3,t1+1,t2){
          if(s[i][t3]==1) O_num+=1;
        }
        if(O_num>=k) ans=min(ans,c[i]+mono[0][max(0,k-J_num)]+mono[2][max(0,k-I_num)]);
      }
    }
  }
  if(ans<INF)cout << ans << endl;
  else cout << -1 << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}
0