結果

問題 No.31 悪のミックスジュース
ユーザー simezi_tansimezi_tan
提出日時 2015-07-24 13:34:55
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,224 bytes
コンパイル時間 1,296 ms
コンパイル使用メモリ 152,416 KB
実行使用メモリ 7,576 KB
最終ジャッジ日時 2023-09-22 22:07:55
合計ジャッジ時間 4,675 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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 - 2 * a + v % 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