結果

問題 No.31 悪のミックスジュース
ユーザー kriii
提出日時 2014-12-15 01:01:18
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 639 bytes
コンパイル時間 179 ms
コンパイル使用メモリ 23,040 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-14 15:49:46
合計ジャッジ時間 863 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:7:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    7 |         scanf ("%d %lld",&N,&V);
      |         ~~~~~~^~~~~~~~~~~~~~~~~
main.cpp:8:38: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |         for (int i=1;i<=N;i++) scanf ("%lld",&C[i]), C[i] += C[i-1];
      |                                ~~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

int N; long long V,C[101],D[10001];

int main()
{
	scanf ("%d %lld",&N,&V);
	for (int i=1;i<=N;i++) scanf ("%lld",&C[i]), C[i] += C[i-1];

	int x = 1;
	for (int i=2;i<=N;i++) if (C[x] * i > C[i] * x) x = i;
	for (int i=1;i<=10000;i++){
		D[i] = 1e18;
		for (int j=1;j<=N;j++) if (i >= j){
			if (D[i] > D[i-j] + C[j])
				D[i] = D[i-j] + C[j];
		}
	}

	long long ans = 1e18;
	V -= N;
	if (V <= 0) ans = C[N];
	for (int i=0;i<=10000;i++) if (i <= V){
		int r = (V - i + x - 1) / x;
		long long w = C[N] + D[i] + C[x] * r;
		if (ans > w)
			ans = w;
	}
	printf ("%lld\n",ans);

	return 0;
}
0