結果

問題 No.31 悪のミックスジュース
ユーザー simezi_tansimezi_tan
提出日時 2015-07-24 13:37:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 50 ms / 5,000 ms
コード長 1,229 bytes
コンパイル時間 1,209 ms
コンパイル使用メモリ 152,640 KB
実行使用メモリ 7,600 KB
最終ジャッジ日時 2023-10-12 17:18:31
合計ジャッジ時間 2,584 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
7,272 KB
testcase_01 AC 45 ms
7,388 KB
testcase_02 AC 45 ms
7,404 KB
testcase_03 AC 50 ms
7,320 KB
testcase_04 AC 49 ms
7,284 KB
testcase_05 AC 49 ms
7,320 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 49 ms
7,340 KB
testcase_08 AC 50 ms
7,348 KB
testcase_09 AC 50 ms
7,340 KB
testcase_10 AC 1 ms
4,352 KB
testcase_11 AC 15 ms
7,396 KB
testcase_12 AC 33 ms
7,480 KB
testcase_13 AC 6 ms
7,348 KB
testcase_14 AC 48 ms
7,404 KB
testcase_15 AC 12 ms
7,320 KB
testcase_16 AC 19 ms
7,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

const int MX = 500000;
int n, v;
ll dp[MX + 10000], c[110];

int main(){
	cin >> n >> v;
	rep(i, n) cin >> c[i + 1], c[i + 1] += c[i];
	
	vector<pair<ll, ll>> p;
	rep(i, n) p.pb(mp(i + 1ll, c[i + 1]));
	sort(all(p), [](pair<ll, ll> a, pair<ll, ll> b){
		return a.second * b.first < b.second * a.first;
	});
	
	if(v <= n){
		cout << c[n] << endl;
		return 0;
	}
	v -= n;
	
	rep(i, MX + 10000) dp[i] = 1e18; dp[0] = 0;
	rep(i, MX){
		for(int j = 1; j <= n; j++) dp[i + j] = min(dp[i + j], dp[i] + c[j]);
	}
	
	if(v <= MX) cout << dp[v] + c[n] << endl;
	else{
		//assert(0);
		ll a = p[0].first, b = p[0].second;
		int x = MX - MX % a + v % a - a;
		assert((v - x) % a == 0);
		cout << dp[x] + (v - x) / a * b + c[n] << endl;
	}
	
	//rep(i, n + 1) cerr<<c[i]<<(i==n?"\n":" ");
	
	return 0;
}
0