結果

問題 No.31 悪のミックスジュース
ユーザー EmKjpEmKjp
提出日時 2015-02-23 21:29:27
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 266 ms / 5,000 ms
コード長 1,479 bytes
コンパイル時間 678 ms
コンパイル使用メモリ 80,760 KB
実行使用メモリ 18,824 KB
最終ジャッジ日時 2023-10-12 17:14:29
合計ジャッジ時間 4,316 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,356 KB
testcase_01 AC 234 ms
18,720 KB
testcase_02 AC 234 ms
18,604 KB
testcase_03 AC 261 ms
18,676 KB
testcase_04 AC 263 ms
18,804 KB
testcase_05 AC 261 ms
18,576 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 266 ms
18,760 KB
testcase_08 AC 261 ms
18,608 KB
testcase_09 AC 258 ms
18,724 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 73 ms
18,624 KB
testcase_12 AC 182 ms
18,824 KB
testcase_13 AC 12 ms
18,800 KB
testcase_14 AC 244 ms
18,776 KB
testcase_15 AC 51 ms
18,576 KB
testcase_16 AC 94 ms
18,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<numeric>
#include<functional>
#include<complex>

using namespace std;
#define BET(a,b,c) ((a)<=(b)&&(b)<(c))
#define FOR(i,n) for(int i=0,i##_end=(int(n));i<i##_end;i++)
#define SZ(x) (int)(x.size())
#define ALL(x) (x).begin(),(x).end()
#define MP make_pair
#define FOR_EACH(it,v) for(__typeof(v.begin()) it=v.begin(),it_end=v.end() ; it != it_end ; it++)
typedef vector<int> VI;
typedef vector<VI> VVI;

int main()
{
    int N, V;
    cin>>N>>V;
    VI C(N);
    FOR(i,N) cin>>C[i];
    vector<long long> S(N);
    S[0] = C[0];
    for(int i=1;i<N;i++) S[i] = S[i-1] + C[i];
    long long ans = S[N-1];
    V -= N;
    if(V > 0){
        int maxUnitIndex = 0;
        FOR(i,N) if(S[i] * (maxUnitIndex + 1) < S[maxUnitIndex] * (i+1)){
            maxUnitIndex = i;
        }
        long long upper = 1000000*2;
        if(upper < V){
            long long need = (V - upper) / (maxUnitIndex + 1);
            ans += need * S[maxUnitIndex];
            V   -= need * (maxUnitIndex+1);
        }
        vector<long long> dp(V + 1, 1LL<<60);
        dp[0] = 0;
        FOR(i,N) {
            FOR(j,V+1) if(j - (i+1) >= 0) {
                dp[j] = min(dp[j], dp[j-(i+1)] + S[i]);
            }
        }
        ans += dp[V];
    }
    cout<<ans<<endl;
    return 0;
}
0