結果

問題 No.31 悪のミックスジュース
ユーザー dnishdnish
提出日時 2018-06-14 16:14:43
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 959 bytes
コンパイル時間 1,533 ms
コンパイル使用メモリ 166,296 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-12 17:20:44
合計ジャッジ時間 2,395 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 4 ms
4,348 KB
testcase_02 AC 3 ms
4,348 KB
testcase_03 AC 4 ms
4,352 KB
testcase_04 AC 4 ms
4,348 KB
testcase_05 AC 4 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 4 ms
4,352 KB
testcase_08 AC 4 ms
4,352 KB
testcase_09 AC 4 ms
4,348 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 2 ms
4,352 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 3 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#define REP(i,n,N) for(ll i=(n); i<(N); i++)
#define RREP(i,n,N) for(ll i=(N-1); i>=n; i--)
#define CK(n,a,b) (a)<=(n)&&(n)<(b)
#define ALL(v) (v).begin(),(v).end()
#define p(s) cout<<(s)<<endl
typedef long long ll;
using namespace std;
const ll inf =1e18;

ll N,V;

int main(){
    while(cin>>N>>V){
        ll ans=0;
        ll C[110] = {};
        ll sum[110] = {};
        ll dp[20210] = {};
        REP(i,0,N){
            cin>>C[i];
            sum[i+1] = sum[i]+C[i];
        }
        ll x=1;
        V-=N;
        if(N>=V){
            cout<<sum[N]<<endl;
            continue;
        }
        REP(i,2,N+1){
            if(x*sum[i]<i*sum[x]) x=i;
        }
        REP(i,0,min(20200LL,V)+1) {
            dp[i]=inf;
            if((V-i)%x==0) dp[i]=(V-i)/x*sum[x];
        }
        RREP(i,0,min(20000LL,V)+1) {
            REP(j,1,N+1) dp[i]=min(dp[i],dp[i+j]+sum[j]);
        }
        cout<<dp[0]+sum[N]<<endl;

    }

}
0