結果

問題 No.31 悪のミックスジュース
ユーザー 古寺いろは古寺いろは
提出日時 2015-04-15 20:57:38
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 789 bytes
コンパイル時間 1,126 ms
コンパイル使用メモリ 146,356 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-12 17:14:51
合計ジャッジ時間 1,933 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define MAX 25000

long long dp[MAX];

int main() {
	int N, V;
	cin >> N >> V;
	vector<long long> C(N);
	for (int i = 0; i < N; i++)
	{
		cin >> C[i];
	}
	int best = 0;
	for (int i = 1; i < N; i++)
	{
		C[i] += C[i - 1];
		if (C[i] * (best + 1) <= C[best] * (i + 1)){
			best = i;
		}
	}

	long long ans = 0;
	ans += C[N - 1];
	V -= N;

	if (V > 20000){
		long long skip = (V - 20000) / (best + 1);
		V -= skip * (best + 1);
		ans += skip * C[best];
	}
	for (int i = 0; i < MAX; i++)
	{
		dp[i] = (long long)2e18;
	}
	dp[0] = 0;

	for (int i = 0; i < V; i++)
	{
		for (int j = 0; j < N; j++)
		{
			if (i + j + 1 >= MAX) continue;
			dp[i + j + 1] = min(dp[i + j + 1], dp[i] + C[j]);
		}
	}
	ans += dp[V];
	cout << ans << endl;
	cin >> ans;
}
0