結果

問題 No.31 悪のミックスジュース
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2017-02-21 22:59:29
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,210 bytes
コンパイル時間 2,015 ms
コンパイル使用メモリ 160,400 KB
実行使用メモリ 17,480 KB
最終ジャッジ日時 2023-08-28 23:45:29
合計ジャッジ時間 7,817 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:89:8: warning: ‘tmp’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  printf("%lld\n", ans + tmp);
  ~~~~~~^~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;	

ll n, v;
ll c[110];
//tie(pri, sum, cnt) pri = sum / cnt, sum := cntリットルの値段 
vector<tuple<double, ll, ll>> s;
//dp[i][j] := sのi番目まで使って、合計リットルをjにするときの最小の値段
ll dp[110][11010];
int main(void){
	cin >> n >> v;
	v -= n; //すべてを1Lずつつかう
	rep(i, n) cin >> c[i];
	ll sum = 0;
	rep(i, n){
		sum += c[i];
		int cnt = i + 1;
		s.pb(make_tuple((double)sum / cnt, sum, cnt));
	}
	sort(all(s));

	ll ans = sum; 
	/*
	rep(i, n){
		if(v <= n * n) break;
		double pri; ll sum, cnt;
		tie(pri, sum, cnt) = s[i];
		// printf("%f %lld %lld\n", pri, sum, cnt);
		if(v - (v / cnt) * cnt >= 0){
			v -= (v / cnt) * cnt;
			ans += sum * (v / cnt);
		}
	}
	*/

	if(v < 0){
		printf("%lld\n", ans);
		return 0;
	}
	// printf("%lld %lld\n", v, ans);

	{
		double pri; ll sum, cnt;
		tie(pri, sum, cnt) = s[0];
		// printf("yy\n");
		//cnt L で sum 円
		ll pack = v / cnt;
		if(v - pack * cnt >= 0){
			// printf("k\n");
			v -= pack * cnt;
			ans += sum * pack;
		}
	}

	// printf("%lld %lld\n", v, ans);
	// printf("%lld v %lld\n", ans, v);

	rep(i, 110)rep(j, 11010) dp[i][j] = INFF;
	dp[0][0] = 0;
	rep(i, n)rep(j, n * n)rep(k, n * n){
		if(dp[i][j] == INFF) continue;
		double pri; ll sum, cnt;
		tie(pri, sum, cnt) = s[i];
		int d = j + cnt * k; // cnt リットルのものを k 個買う
		if(d <= n * n){
			chmin(dp[i + 1][d], dp[i][j] + sum * k);
			// printf("dp[%d][%d]=%lld dp[%d][%d]=%lld\n", i+1,d,dp[i + 1][d],i,j,dp[i][j] + sum * k);
		}
	}
	ll tmp;
	reps(i, v, 11010) chmin(tmp, dp[n][i]);
	printf("%lld\n", ans + tmp);
	return 0;
}
0