結果

問題 No.31 悪のミックスジュース
ユーザー kotatsugamekotatsugame
提出日時 2021-01-11 05:52:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 139 ms / 5,000 ms
コード長 549 bytes
コンパイル時間 597 ms
コンパイル使用メモリ 66,444 KB
実行使用メモリ 11,756 KB
最終ジャッジ日時 2024-05-01 06:42:50
合計ジャッジ時間 2,843 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
11,664 KB
testcase_01 AC 122 ms
11,636 KB
testcase_02 AC 123 ms
11,560 KB
testcase_03 AC 137 ms
11,632 KB
testcase_04 AC 136 ms
11,612 KB
testcase_05 AC 135 ms
11,528 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 138 ms
11,756 KB
testcase_08 AC 139 ms
11,652 KB
testcase_09 AC 138 ms
11,748 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 41 ms
11,644 KB
testcase_12 AC 96 ms
11,628 KB
testcase_13 AC 11 ms
11,596 KB
testcase_14 AC 139 ms
11,600 KB
testcase_15 AC 31 ms
11,636 KB
testcase_16 AC 52 ms
11,628 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    6 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
using namespace std;
int N,V;
long S[101];
long dp[1<<20];
main()
{
	cin>>N>>V;
	for(int i=0;i<N;i++)
	{
		cin>>S[i];
		if(i)S[i]+=S[i-1];
	}
	if(N>=V)
	{
		cout<<S[N-1]<<endl;
		return 0;
	}
	int id=0;
	for(int i=0;i<N;i++)
	{
		if(S[id]*(i+1)>S[i]*(id+1))id=i;
	}
	for(int i=0;i<1<<20;i++)dp[i]=1e18;
	dp[0]=S[N-1];
	long ans=1e18;
	for(int i=0;i<1<<20;i++)
	{
		if(i<=V-N&&(V-N-i)%(id+1)==0)ans=min(ans,dp[i]+(V-N-i)/(id+1)*S[id]);
		for(int j=0;j<N&&i+j+1<1<<20;j++)dp[i+j+1]=min(dp[i+j+1],dp[i]+S[j]);
	}
	cout<<ans<<endl;
}
0