結果
問題 |
No.31 悪のミックスジュース
|
ユーザー |
![]() |
提出日時 | 2016-02-11 10:02:39 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 6 ms / 5,000 ms |
コード長 | 1,064 bytes |
コンパイル時間 | 1,387 ms |
コンパイル使用メモリ | 158,312 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-14 15:56:40 |
合計ジャッジ時間 | 2,068 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int (i) = 0 ; (i) < (int)(n) ; (i)++) #define REP(i,a,b) for(int (i) = a ; (int)(i) <= (int)(b) ; (i)++) #define all(n) (n).begin(),(n).end() typedef vector<int> Vi; typedef vector<Vi> VVi; typedef pair<int,int> Pii; typedef vector<Pii> VPii; long long INF = 1e18; int N; long long C[100]; long long dp[10010]; long long solve(int V){ for(int i = 1 ; i < N ; i++) C[i] += C[i-1]; for(int i = 0 ; i < 10010 ; i++) dp[i] = INF; dp[0] = 0; for(int i = 0 ; i < N ; i++){ for(int j = 0 ; j+i+1 <= 10000 ; j++) dp[j+i+1] = min(dp[j+i+1],dp[j] + C[i]); } long long ans = 1e18; for(int i = 0 ; i < N ; i++){ for(int j = 0 ; j <= min(10000,V) ; j++){ if( (V - j) % (i+1) == 0 ){ ans = min(ans,dp[j]+(V-j)/(i+1)*C[i]); } } } return ans; } int main(){ int V; cin >> N >> V; rep(i,N) cin >> C[i]; if( V <= N ){ cout << accumulate(C,C+N,0ll) << endl; }else{ V -= N; long long pre = accumulate(C,C+N,0ll); long long ans = solve(V); cout << pre+ans << endl; } }