結果

問題 No.31 悪のミックスジュース
ユーザー kyuridenamidakyuridenamida
提出日時 2016-02-11 10:02:39
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 1,064 bytes
コンパイル時間 1,232 ms
コンパイル使用メモリ 144,724 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-10-12 17:24:01
合計ジャッジ時間 2,077 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#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;
	}
}
0