結果

問題 No.31 悪のミックスジュース
ユーザー ktgktg
提出日時 2016-10-18 02:34:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,753 bytes
コンパイル時間 589 ms
コンパイル使用メモリ 73,676 KB
実行使用メモリ 4,368 KB
最終ジャッジ日時 2023-10-12 17:19:32
合計ジャッジ時間 1,365 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

//#include <bits/stdc++.h>
#include <assert.h>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <iterator>
#include <unistd.h>

using namespace std;

typedef signed long long ll;

#define pp(...) (void)printf(__VA_ARGS__)
#define For(x,to) for(x=0;x<(to);x++)
#define ForAuto(x,arr) for(auto& x:arr)
#define ForBeginEnd(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define All(a) (a.begin()),(a.end())
#define Zeros(a) memset(a,0,sizeof(a))
#define Minus(a) memset(a,0xff,sizeof(a))

#define PI 3.14159265
#define EPS (1e-10)
#define EPS_eq(a,b) (abs((a)-(b)) < EPS)

#pragma GCC diagnostic ignored "-Wconversion"

//#define int long long
//#define INF 1000*1000

int dxy[] = {0, 1, 0, -1, 0};

typedef pair<int, int> P;

void pp_int(int x){ printf("%d\n", x); };

int i,j,k;

ll M = 100000009;

//ios::sync_with_stdio(false);

//-------------------------------------------------

ll INF = 1ll<<60;
ll C[300];
ll SUM[300];
ll dp[20500];

signed main() {
    ll N,V;
    cin>>N>>V;
    for(int i=1;i<=N;i++){
        cin>>C[i];
        SUM[i] = SUM[i-1] + C[i];
    }
    if(V<=N){
        cout<<SUM[N]<<endl;
        return 0;
    }
    V-=N;
    ll x=1;
    for(ll i=2;i<=N;i++){
        if(SUM[x]*i>SUM[i]*x){
            x=i;
        }
    }
    for(ll i=0;i<20500;i++){
        if((V-i)%x==0){
            dp[i] = (V-i)/x*SUM[x];
        }else{
            dp[i] = INF;
        }
    }
    for(int i=20000;i>=0;i--){
        for(int j=1;j<=N;j++){
            dp[i] = min(dp[i], dp[i + j] + SUM[j]);
        }
    }
    cout<<SUM[N]+dp[0]<<endl;
    return 0;
}
0