結果

問題 No.409 ダイエット
ユーザー sugim48sugim48
提出日時 2016-08-05 23:32:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 1,631 bytes
コンパイル時間 1,170 ms
コンパイル使用メモリ 105,240 KB
実行使用メモリ 14,440 KB
最終ジャッジ日時 2023-09-08 16:51:13
合計ジャッジ時間 5,943 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 2 ms
4,388 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,384 KB
testcase_18 AC 1 ms
4,384 KB
testcase_19 AC 2 ms
4,384 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 1 ms
4,388 KB
testcase_22 AC 1 ms
4,384 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,384 KB
testcase_27 AC 1 ms
4,384 KB
testcase_28 AC 2 ms
4,384 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,384 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 1 ms
4,384 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,384 KB
testcase_36 AC 2 ms
4,384 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 2 ms
4,384 KB
testcase_42 AC 2 ms
4,384 KB
testcase_43 AC 2 ms
4,384 KB
testcase_44 AC 2 ms
4,384 KB
testcase_45 AC 3 ms
4,380 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 2 ms
4,384 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 2 ms
4,384 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 2 ms
4,384 KB
testcase_52 AC 2 ms
4,384 KB
testcase_53 AC 2 ms
4,380 KB
testcase_54 AC 3 ms
4,384 KB
testcase_55 AC 24 ms
8,100 KB
testcase_56 AC 34 ms
8,364 KB
testcase_57 AC 49 ms
14,424 KB
testcase_58 AC 22 ms
7,096 KB
testcase_59 AC 29 ms
8,324 KB
testcase_60 AC 19 ms
6,988 KB
testcase_61 AC 43 ms
13,956 KB
testcase_62 AC 45 ms
13,624 KB
testcase_63 AC 42 ms
11,984 KB
testcase_64 AC 23 ms
7,276 KB
testcase_65 AC 42 ms
9,548 KB
testcase_66 AC 48 ms
13,192 KB
testcase_67 AC 36 ms
11,484 KB
testcase_68 AC 29 ms
8,144 KB
testcase_69 AC 42 ms
13,788 KB
testcase_70 AC 45 ms
11,904 KB
testcase_71 AC 26 ms
7,072 KB
testcase_72 AC 55 ms
14,024 KB
testcase_73 AC 51 ms
13,180 KB
testcase_74 AC 34 ms
11,432 KB
testcase_75 AC 53 ms
14,440 KB
testcase_76 AC 38 ms
12,004 KB
testcase_77 AC 25 ms
6,092 KB
testcase_78 AC 30 ms
10,852 KB
testcase_79 AC 24 ms
7,068 KB
testcase_80 AC 53 ms
13,048 KB
testcase_81 AC 49 ms
12,300 KB
testcase_82 AC 39 ms
12,660 KB
testcase_83 AC 41 ms
12,532 KB
testcase_84 AC 33 ms
7,700 KB
testcase_85 AC 5 ms
4,380 KB
testcase_86 AC 33 ms
7,936 KB
testcase_87 AC 46 ms
13,180 KB
testcase_88 AC 20 ms
5,732 KB
testcase_89 AC 36 ms
7,264 KB
testcase_90 AC 17 ms
4,756 KB
testcase_91 AC 38 ms
6,264 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:64:21: 警告: ‘ans’ may be used uninitialized [-Wmaybe-uninitialized]
   64 |         cout << W + ans << endl;
      |                     ^~~
main.cpp:44:12: 備考: ‘ans’ はここで定義されています
   44 |         ll ans;
      |            ^~~

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#include <random>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<int, ll> i_ll;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	int N; ll A, B, W;
	cin >> N >> A >> B >> W;
	vector<ll> D(N);
	for (ll& x: D) scanf("%lld", &x);
	N++; D.push_back(0);
	int M = 1;
	vector<i_ll> p; p.push_back(i_ll(0, 0));
	ll ans;
	for (ll i = 0; i < N; i++) {
		ll mi = p[0].second - B * i * p[0].first;
		if (M >= 2) mi = min(mi, p[1].second - B * i * p[1].first);
		ll lb = 0, ub = M - 1;
		while (ub - lb > 1) {
			ll mid = (lb + ub) / 2;
			ll x1 = p[mid].second - B * i * p[mid].first;
			ll x2 = p[mid + 1].second - B * i * p[mid + 1].first;
			if (x1 > x2) lb = mid;
			else ub = mid;
			mi = min(mi, min(x1, x2));
		}
		mi += i*(i+1)/2 * B - i * A + D[i];
		ans = mi;
		i_ll _p(i + 1, mi + i*(i+1)/2 * B + (i+1) * A);
		for (; M >= 2 && (p[M - 1].second - p[M - 2].second) * (_p.first - p[M - 1].first) >= (_p.second - p[M - 1].second) * (p[M - 1].first - p[M - 2].first); M--, p.pop_back());
		M++; p.push_back(_p);
		
	}
	cout << W + ans << endl;
}
0