結果

問題 No.31 悪のミックスジュース
ユーザー chocoruskchocorusk
提出日時 2019-03-31 12:09:28
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,192 bytes
コンパイル時間 881 ms
コンパイル使用メモリ 98,676 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-12 17:23:23
合計ジャッジ時間 1,709 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;

int main()
{
    int n; ll v; cin>>n>>v;
    v-=n;
    ll c[101], s[101];
    s[0]=0;
    int ind[101];
    for(int i=1; i<=n; i++){
        cin>>c[i];
        s[i]=s[i-1]+c[i];
        ind[i]=i;
    }
    if(v<=0){
        cout<<s[n]<<endl;
        return 0;
    }
    sort(ind+1, ind+n+1, [&](int i, int j){ return s[i]*(ll)j<s[j]*(ll)i;});
    int m=ind[1];
    ll dp[10001];
    fill(dp, dp+1+n*n, 1e18);
    dp[0]=0;
    for(int i=1; i<=n; i++){
        for(int j=0; j<=n*n-i; j++){
            dp[j+i]=min(dp[j+i], dp[j]+s[i]);
        }
    }
    ll ans=1e18;
    for(int j=0; j<=n*n; j++){
        if(v<=j) ans=min(ans, dp[j]);
        else ans=min(ans, dp[j]+(v-(ll)j+(ll)m-1)/(ll)m*s[m]);
    }
    cout<<ans+s[n]<<endl;
    return 0;
}
0