結果

問題 No.31 悪のミックスジュース
ユーザー beetbeet
提出日時 2018-11-07 17:39:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,172 ms / 5,000 ms
コード長 974 bytes
コンパイル時間 2,174 ms
コンパイル使用メモリ 204,112 KB
実行使用メモリ 11,060 KB
最終ジャッジ日時 2023-10-12 17:23:21
合計ジャッジ時間 15,146 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
10,652 KB
testcase_01 AC 1,015 ms
10,652 KB
testcase_02 AC 1,026 ms
10,788 KB
testcase_03 AC 1,163 ms
11,000 KB
testcase_04 AC 1,166 ms
10,652 KB
testcase_05 AC 1,172 ms
10,768 KB
testcase_06 AC 8 ms
10,760 KB
testcase_07 AC 1,167 ms
10,768 KB
testcase_08 AC 1,170 ms
10,704 KB
testcase_09 AC 1,172 ms
10,752 KB
testcase_10 AC 123 ms
11,060 KB
testcase_11 AC 295 ms
10,768 KB
testcase_12 AC 808 ms
10,700 KB
testcase_13 AC 19 ms
10,712 KB
testcase_14 AC 1,131 ms
10,888 KB
testcase_15 AC 190 ms
10,760 KB
testcase_16 AC 396 ms
10,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
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;}

//INSERT ABOVE HERE
signed main(){
  const Int MAX = 1e6;
  const Int INF = 2e18;
  Int n,v;
  cin>>n>>v;
  vector<Int> c(n);
  for(Int i=0;i<n;i++) cin>>c[i];
  
  using P = pair<Int, Int>;
  vector<P> vp;
  for(Int i=0,s=0;i<n;i++){
    s+=c[i];
    vp.emplace_back(i+1,s);
  }
  
  vector<Int> dp(MAX,INF);
  dp[0]=0;
  for(Int i=0;i<n;i++)
    for(Int j=0;j+vp[i].first<MAX;j++)
      chmin(dp[j+vp[i].first],dp[j]+vp[i].second);  
      
  v-=min(v,n);
  Int ans=INF;
  for(Int j=0;j<MAX;j++){
    if(j>=v){
      chmin(ans,dp[j]);
      continue;
    }
    for(Int i=0;i<n;i++){
      Int d=(v-j+vp[i].first-1)/vp[i].first;
      chmin(ans,dp[j]+d*vp[i].second);
    }
  }
  
  for(Int i=0;i<n;i++) ans+=c[i];
  cout<<ans<<endl;
  return 0;
}
0