結果

問題 No.974 最後の日までに
ユーザー msm1993msm1993
提出日時 2020-04-03 15:33:23
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 133 ms / 2,000 ms
コード長 2,158 bytes
コンパイル時間 1,233 ms
コンパイル使用メモリ 122,272 KB
実行使用メモリ 17,548 KB
最終ジャッジ日時 2023-09-15 23:30:17
合計ジャッジ時間 9,472 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
15,744 KB
testcase_01 AC 112 ms
16,156 KB
testcase_02 AC 110 ms
16,012 KB
testcase_03 AC 110 ms
15,192 KB
testcase_04 AC 112 ms
16,520 KB
testcase_05 AC 110 ms
16,816 KB
testcase_06 AC 112 ms
17,136 KB
testcase_07 AC 112 ms
15,656 KB
testcase_08 AC 111 ms
15,092 KB
testcase_09 AC 112 ms
16,688 KB
testcase_10 AC 112 ms
15,316 KB
testcase_11 AC 111 ms
17,088 KB
testcase_12 AC 111 ms
16,584 KB
testcase_13 AC 112 ms
16,512 KB
testcase_14 AC 113 ms
15,776 KB
testcase_15 AC 112 ms
16,116 KB
testcase_16 AC 110 ms
16,012 KB
testcase_17 AC 127 ms
16,412 KB
testcase_18 AC 127 ms
15,236 KB
testcase_19 AC 126 ms
16,512 KB
testcase_20 AC 127 ms
17,112 KB
testcase_21 AC 126 ms
15,608 KB
testcase_22 AC 126 ms
17,228 KB
testcase_23 AC 128 ms
16,144 KB
testcase_24 AC 125 ms
16,840 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 87 ms
12,636 KB
testcase_28 AC 116 ms
16,272 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 133 ms
15,360 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 70 ms
10,280 KB
testcase_34 AC 120 ms
15,200 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 130 ms
17,548 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 1 ms
4,376 KB
testcase_40 AC 76 ms
12,308 KB
testcase_41 AC 101 ms
16,328 KB
testcase_42 AC 131 ms
16,164 KB
testcase_43 AC 131 ms
16,064 KB
testcase_44 AC 97 ms
13,044 KB
testcase_45 AC 79 ms
10,148 KB
testcase_46 AC 1 ms
4,376 KB
testcase_47 AC 1 ms
4,376 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 2 ms
4,380 KB
testcase_50 AC 1 ms
4,380 KB
testcase_51 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
//constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

ll W;
vector<ll> a, b, c;
vector<pair<ll, ll>> vp[2];
//好感度, お金
void dfs(ll now, ll end, ll love, ll money, int t) {
	if (now + 1 == end) {
		dfs(now + 1, end, love, money + a[now], t);
		return;
	}
	if (now == end) {
		vp[t].emplace_back(money, love);
		return;
	}
	dfs(now + 1, end, love, money + a[now], t);
	dfs(now + 2, end, love + b[now + 1], money - c[now + 1], t);
}
ll solve(ll h) {
	vp[0].clear();
	vp[1].clear();
	dfs(0, h, 0, 0, 0);
	dfs(h, W, 0, 0, 1);
	for (int i = 0; i < 2; i++) {
		sort(vp[i].begin(), vp[i].end());
		for (int j = (int)vp[i].size() - 2; j >= 0; j--) {
			chmax(vp[i][j].second, vp[i][j + 1].second);
		}
	}
	ll res = 0;
	for (int i = 0; i < vp[0].size(); i++) {
		auto itr = lower_bound(vp[1].begin(), vp[1].end(), make_pair(-vp[0][i].first,-INF));
		if (itr == vp[1].end()) continue;
		chmax(res, vp[0][i].second + itr->second);
	}
	return res;
}
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	scanf("%lld", &W);
	a.resize(W), b.resize(W), c.resize(W);
	for (int i = 0; i < W; i++) scanf("%lld %lld %lld", &a[i], &b[i], &c[i]);

	cout << max(solve(W / 2), solve(W / 2 + 1)) << endl;
	return 0;
	/*
		おまじないを使ったらscanfとprintf関連注意!!!!!!!!!!!!
	*/
}
0