結果

問題 No.31 悪のミックスジュース
ユーザー Yang33Yang33
提出日時 2018-04-10 17:42:05
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 14 ms / 5,000 ms
コード長 2,951 bytes
コンパイル時間 1,483 ms
コンパイル使用メモリ 168,484 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-10-12 17:20:22
合計ジャッジ時間 2,454 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e18;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/04/10  Problem: yukicoder 031  / Link: http://yukicoder.me/problems/no/031  ----- */
/* ------問題------

ミックスジュースが切れました。
ミックスジュースの原材料の表示は、順番に、果物 1,果物 2,…,果物 N となっています。
既存のそれぞれの果物の100%ジュースを混ぜてミックスジュースを V リットルだけ作りたいです。
果物 k の100%ジュースは 1 リットルパックのみが売られていて、1 パックあたり Ck 円です。
V リットルのミックスジュースを、原材料の表示を変更することなく作るための、最小コストを求めるプログラムを書いてください。
つまり、ミックスジュースにおいて果物 k が占める割合 pk は p1≥p2≥⋯≥pN となる必要があり、更に、使われない果物があってもいけません。
1 リットルパックを買い、その一部のみを使用することも可能です。

-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */


LL solve(LL left, VL& a) {
	// left リットルつくるときにかかる最小コスト、ただしany i, a[i]>=a[i+1]
	int N = SZ(a);
	VL sum(N + 1, 0);
	FOR(i, 0, N) {
		sum[i + 1] = sum[i] + a[i];
	}

	VL dp(10001, LINF);
	dp[0] = 0;
	FOR(i, 1, N + 1) {
		FOR(j, 0, 10001) {
			if (i + j <= 10000)
				dp[i + j] = min(dp[i + j], dp[j] + sum[i]);
		}
	}

	LL ret = LINF;
	FOR(i, 1, N + 1) {
		FOR(l, 0, 10001) {
			if (left - l >= 0 && (left - l) % i == 0) {
				int backet = (left - l) / i;
				ret = min(ret, dp[l] + sum[i] * backet);
			}
		}

	}


	return ret; // min state{left L作るのに必要なコスト}
}

LL N, V;

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	cin >> N >> V;
	VL a(N);
	LL sum = 0;
	FOR(i, 0, N) {
		cin >> a[i];
		sum += a[i];
	}
	if (N >= V) {
		cout << sum << endl;
	}
	else {
		cout << sum + solve(V - N, a) << endl;
	}


	return 0;
}
0