結果

問題 No.974 最後の日までに
ユーザー square1001square1001
提出日時 2020-01-17 21:52:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,386 ms / 2,000 ms
コード長 2,121 bytes
コンパイル時間 1,136 ms
コンパイル使用メモリ 89,856 KB
実行使用メモリ 65,160 KB
最終ジャッジ日時 2024-04-14 21:49:36
合計ジャッジ時間 52,747 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,366 ms
63,336 KB
testcase_01 AC 1,360 ms
63,500 KB
testcase_02 AC 1,357 ms
64,260 KB
testcase_03 AC 1,359 ms
63,268 KB
testcase_04 AC 1,365 ms
65,160 KB
testcase_05 AC 1,355 ms
64,172 KB
testcase_06 AC 1,363 ms
62,240 KB
testcase_07 AC 1,360 ms
62,880 KB
testcase_08 AC 1,357 ms
63,676 KB
testcase_09 AC 1,359 ms
64,980 KB
testcase_10 AC 1,361 ms
63,044 KB
testcase_11 AC 1,362 ms
63,388 KB
testcase_12 AC 1,365 ms
63,996 KB
testcase_13 AC 1,366 ms
63,848 KB
testcase_14 AC 1,361 ms
62,964 KB
testcase_15 AC 1,363 ms
63,836 KB
testcase_16 AC 1,362 ms
63,740 KB
testcase_17 AC 1,384 ms
64,252 KB
testcase_18 AC 1,379 ms
63,932 KB
testcase_19 AC 1,386 ms
62,984 KB
testcase_20 AC 1,382 ms
62,936 KB
testcase_21 AC 1,383 ms
63,236 KB
testcase_22 AC 1,385 ms
62,492 KB
testcase_23 AC 1,377 ms
64,356 KB
testcase_24 AC 1,385 ms
65,048 KB
testcase_25 AC 3 ms
6,944 KB
testcase_26 AC 3 ms
6,944 KB
testcase_27 AC 1,006 ms
42,004 KB
testcase_28 AC 1,365 ms
63,904 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 1,382 ms
62,700 KB
testcase_31 AC 2 ms
6,944 KB
testcase_32 AC 2 ms
6,940 KB
testcase_33 AC 804 ms
40,448 KB
testcase_34 AC 1,362 ms
63,756 KB
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 2 ms
6,940 KB
testcase_37 AC 1,380 ms
64,044 KB
testcase_38 AC 2 ms
6,944 KB
testcase_39 AC 2 ms
6,944 KB
testcase_40 AC 992 ms
42,372 KB
testcase_41 AC 1,362 ms
63,808 KB
testcase_42 AC 1,379 ms
63,812 KB
testcase_43 AC 1,385 ms
63,996 KB
testcase_44 AC 1,017 ms
42,620 KB
testcase_45 AC 814 ms
39,856 KB
testcase_46 AC 1 ms
6,944 KB
testcase_47 AC 2 ms
6,940 KB
testcase_48 AC 2 ms
6,944 KB
testcase_49 AC 2 ms
6,944 KB
testcase_50 AC 2 ms
6,944 KB
testcase_51 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const long long inf = 1LL << 62;
vector<string> enumerate(int N) {
	if (N == 0) return vector<string>({ "" });
	if (N == 1) return vector<string>({ "B" });
	vector<string> rpre1 = enumerate(N - 1);
	vector<string> rpre2 = enumerate(N - 2);
	vector<string> ans;
	for (string i : rpre1) {
		ans.push_back("B" + i);
	}
	for (string i : rpre2) {
		ans.push_back("AC" + i);
	}
	return ans;
}
vector<pair<long long, long long> > calc(int N, vector<long long> A, vector<long long> B, vector<long long> C) {
	// pair = (money, happiness)
	vector<string> ops = enumerate(N);
	vector<pair<long long, long long> > res;
	for (string i : ops) {
		long long money = 0, happiness = 0;
		for (int j = 0; j < N; ++j) {
			if (i[j] == 'B') money += A[j];
			if (i[j] == 'C') money -= C[j], happiness += B[j];
		}
		res.push_back(make_pair(money, happiness));
	}
	return res;
}
long long solve(int N, vector<long long> A, vector<long long> B, vector<long long> C, int sep) {
	vector<pair<long long, long long> > resl = calc(sep, vector<long long>(A.begin(), A.begin() + sep), vector<long long>(B.begin(), B.begin() + sep), vector<long long>(C.begin(), C.begin() + sep));
	vector<pair<long long, long long> > resr = calc(N - sep, vector<long long>(A.begin() + sep, A.end()), vector<long long>(B.begin() + sep, B.end()), vector<long long>(C.begin() + sep, C.end()));
	sort(resl.begin(), resl.end());
	sort(resr.begin(), resr.end());
	vector<long long> mx(resl.size() + 1, -inf);
	for (int i = resl.size() - 1; i >= 0; --i) {
		mx[i] = max(mx[i + 1], resl[i].second);
	}
	int ptr = resl.size();
	long long ans = -inf;
	for (int i = 0; i < resr.size(); ++i) {
		while (ptr != 0 && resr[i].first + resl[ptr - 1].first >= 0) --ptr;
		ans = max(ans, resr[i].second + mx[ptr]);
	}
	return ans;
}
int main() {
	int N;
	cin >> N;
	vector<long long> A(N), B(N), C(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i] >> B[i] >> C[i];
	}
	long long ans1 = solve(N, A, B, C, N / 2);
	long long ans2 = solve(N, A, B, C, N / 2 + 1);
	cout << max(ans1, ans2) << endl;
	return 0;
}
0