結果

問題 No.974 最後の日までに
ユーザー msm1993
提出日時 2020-04-03 15:33:23
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 122 ms / 2,000 ms
コード長 2,158 bytes
コンパイル時間 1,263 ms
コンパイル使用メモリ 123,396 KB
実行使用メモリ 15,596 KB
最終ジャッジ日時 2024-07-03 00:45:50
合計ジャッジ時間 6,906 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

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;
/*
使scanfprintf
*/
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0