結果

問題 No.31 悪のミックスジュース
ユーザー simezi_tansimezi_tan
提出日時 2015-07-23 10:19:00
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,190 bytes
コンパイル時間 1,309 ms
コンパイル使用メモリ 152,856 KB
実行使用メモリ 7,640 KB
最終ジャッジ日時 2023-09-22 21:35:37
合計ジャッジ時間 2,654 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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 + 1, 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 - a + v % a;
		cout << dp[x] + (v - x) / a * b + c[n] << endl;
	}
	
	//rep(i, n + 1) cerr<<c[i]<<(i==n?"\n":" ");
	
	return 0;
}
0