結果
問題 | No.2957 Combo Deck Builder |
ユーザー |
|
提出日時 | 2024-10-29 18:53:09 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 188 ms / 1,000 ms |
コード長 | 9,283 bytes |
コンパイル時間 | 4,530 ms |
コンパイル使用メモリ | 262,996 KB |
最終ジャッジ日時 | 2025-02-25 01:22:57 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 38 |
ソースコード
#ifndef HIDDEN_IN_VS // 折りたたみ用// 警告の抑制#define _CRT_SECURE_NO_WARNINGS// ライブラリの読み込み#include <bits/stdc++.h>using namespace std;// 型名の短縮using ll = long long; using ull = unsigned long long; // -2^63 ~ 2^63 = 9e18(int は -2^31 ~ 2^31 = 2e9)using pii = pair<int, int>; using pll = pair<ll, ll>; using pil = pair<int, ll>; using pli = pair<ll, int>;using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using vvvvi = vector<vvvi>;using vl = vector<ll>; using vvl = vector<vl>; using vvvl = vector<vvl>; using vvvvl = vector<vvvl>;using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;using vc = vector<char>; using vvc = vector<vc>; using vvvc = vector<vvc>;using vd = vector<double>; using vvd = vector<vd>; using vvvd = vector<vvd>;template <class T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;using Graph = vvi;// 定数の定義const double PI = acos(-1);int DX[4] = { 1, 0, -1, 0 }; // 4 近傍(下,右,上,左)int DY[4] = { 0, 1, 0, -1 };int INF = 1001001001; ll INFL = 4004004003094073385LL; // (int)INFL = INF, (int)(-INFL) = -INF;// 入出力高速化struct fast_io { fast_io() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(18); } } fastIOtmp;// 汎用マクロの定義#define all(a) (a).begin(), (a).end()#define sz(x) ((int)(x).size())#define lbpos(a, x) (int)distance((a).begin(), std::lower_bound(all(a), (x)))#define ubpos(a, x) (int)distance((a).begin(), std::upper_bound(all(a), (x)))#define Yes(b) {cout << ((b) ? "Yes\n" : "No\n");}#define rep(i, n) for(int i = 0, i##_len = int(n); i < i##_len; ++i) // 0 から n-1 まで昇順#define repi(i, s, t) for(int i = int(s), i##_end = int(t); i <= i##_end; ++i) // s から t まで昇順#define repir(i, s, t) for(int i = int(s), i##_end = int(t); i >= i##_end; --i) // s から t まで降順#define repe(v, a) for(const auto& v : (a)) // a の全要素(変更不可能)#define repea(v, a) for(auto& v : (a)) // a の全要素(変更可能)#define repb(set, d) for(int set = 0, set##_ub = 1 << int(d); set < set##_ub; ++set) // d ビット全探索(昇順)#define repis(i, set) for(int i = lsb(set), bset##i = set; i < 32; bset##i -= 1 << i, i = lsb(bset##i)) // set の全要素(昇順)#define repp(a) sort(all(a)); for(bool a##_perm = true; a##_perm; a##_perm = next_permutation(all(a))) // a の順列全て(昇順)#define uniq(a) {sort(all(a)); (a).erase(unique(all(a)), (a).end());} // 重複除去#define EXIT(a) {cout << (a) << endl; exit(0);} // 強制終了#define inQ(x, y, u, l, d, r) ((u) <= (x) && (l) <= (y) && (x) < (d) && (y) < (r)) // 半開矩形内判定// 汎用関数の定義template <class T> inline ll powi(T n, int k) { ll v = 1; rep(i, k) v *= n; return v; }template <class T> inline bool chmax(T& M, const T& x) { if (M < x) { M = x; return true; } return false; } // 最大値を更新(更新されたら trueを返す)template <class T> inline bool chmin(T& m, const T& x) { if (m > x) { m = x; return true; } return false; } // 最小値を更新(更新されたら trueを返す)template <class T> inline T getb(T set, int i) { return (set >> i) & T(1); }template <class T> inline T smod(T n, T m) { n %= m; if (n < 0) n += m; return n; } // 非負mod// 演算子オーバーロードtemplate <class T, class U> inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }template <class T> inline istream& operator>>(istream& is, vector<T>& v) { repea(x, v) is >> x; return is; }template <class T> inline vector<T>& operator--(vector<T>& v) { repea(x, v) --x; return v; }template <class T> inline vector<T>& operator++(vector<T>& v) { repea(x, v) ++x; return v; }#endif // 折りたたみ用#if __has_include(<atcoder/all>)#include <atcoder/all>using namespace atcoder;#ifdef _MSC_VER#include "localACL.hpp"#endifusing mint = modint998244353;//using mint = static_modint<1000000009>;//using mint = modint; // mint::set_mod(m);namespace atcoder {inline istream& operator>>(istream& is, mint& x) { ll x_; is >> x_; x = x_; return is; }inline ostream& operator<<(ostream& os, const mint& x) { os << x.val(); return os; }}using vm = vector<mint>; using vvm = vector<vm>; using vvvm = vector<vvm>; using vvvvm = vector<vvvm>; using pim = pair<int, mint>;#endif#ifdef _MSC_VER // 手元環境(Visual Studio)#include "local.hpp"#else // 提出用(gcc)inline int popcount(int n) { return __builtin_popcount(n); }inline int popcount(ll n) { return __builtin_popcountll(n); }inline int lsb(int n) { return n != 0 ? __builtin_ctz(n) : 32; }inline int lsb(ll n) { return n != 0 ? __builtin_ctzll(n) : 64; }inline int msb(int n) { return n != 0 ? (31 - __builtin_clz(n)) : -1; }inline int msb(ll n) { return n != 0 ? (63 - __builtin_clzll(n)) : -1; }#define dump(...)#define dumpel(...)#define dump_list(v)#define dump_mat(v)#define input_from_file(f)#define output_to_file(f)#define Assert(b) { if (!(b)) { vc MLE(1<<30); EXIT(MLE.back()); } } // RE の代わりに MLE を出す#endif// 18:02 挑戦開始// 18:03 任意比較関数を定義してソートするやつかな?// 18:06 いや順序が壊れてるわ・・・// 18:09 区間スケジューリング問題にしてライブラリ使うのが楽かな?// 18:17 報酬が負だと壊れるわ・・・// 18:25 左右それぞれから区間スケジューリング問題して組み合わせる?// 18:33 サンプルは合ったけど全く自身がない.まあ提出! → 43WA// 18:35 resize() がまずかった? → 43WA// 18:37 やっぱ差分とらなきゃだめか?// 18:39 あ,重み降順でやってなかったわ・・・// 18:49 やっと実装できた.サンプルも合ったし提出! → 2RE// 18:52 コーナー対策OK.提出!//【流動区間スケジューリング問題(重み付き,一端指定,1 日拘束)】O(n log n)(の改変)/** 着手可能期間が [0..r[i]),拘束日数が 1,報酬が a[i] の n 個の仕事から得られる最大報酬を返す.*/template <class S, class T>vector<T> floating_interval_scheduling(const vector<S>& r, const vector<T>& a) {// verify : https://atcoder.jp/contests/tessoku-book/tasks/tessoku_book_dlint n = sz(r);// 区間を右端降順にソートする.vector<pair<S, T>> ra(n);rep(i, n) ra[i] = { r[i], a[i] };sort(all(ra), greater<pair<S, T>>());// 番兵ra.emplace_back(-1, 0);// 報酬の高い順に取り出せる順位キューpriority_queue<T> q;T res = 0;vector<T> res_all{ res };// now : 現在時刻S now = (S)INFL;// 時刻逆順にシミュレーションする.for (auto& [r, a] : ra) {// 時刻 r までは新しい仕事は無いので,溜まっている仕事を報酬の高い順に消化する.while (!q.empty() && now >= r) {auto a2 = q.top(); q.pop();res += a2;res_all.push_back(res);now--;}// 現在時刻を l まで進める.now = r - 1;// 新しく請け負えるようになった仕事 i を記録する.q.emplace(a);}return res_all;}//【max 可換モノイド】/* verify: https://atcoder.jp/contests/abl/tasks/abl_d */using S003 = int;S003 op003(S003 a, S003 b) { return max(a, b); }S003 e003() { return -1; }#define Max_monoid S003, op003, e003vl isp(vi r, vl s) {int n = sz(r);vector<pli> sr(n);rep(i, n) sr[i] = { s[i], r[i] };sort(all(sr), greater<pli>());dump(sr);vl res{ 0 };vi ini(n);iota(all(ini), 0);segtree<Max_monoid> seg(ini);rep(i, n) {auto [s, r] = sr[i];auto pos = seg.prod(0, r);if (pos == -1) continue;seg.set(pos, -1);res.push_back(res.back() + s);dump(seg);}res.resize(n + 1, -INFL);return res;}int main() {// input_from_file("input.txt");// output_to_file("output.txt");// dump(13 + 5 + 16 + 9 + 10 + 8 + (0 + 8 + 1 + 4 + 6 + 1)); // 81int n;cin >> n;vi c(n); vl x(n), y(n);rep(i, n) cin >> c[i] >> x[i] >> y[i];//ll fix = 0;//rep(i, n) {// if (c[i] == 0) {// fix += x[i];// }// else if (c[i] == n) {// fix += y[i];// }//}vl res_y;{vi r(n); vl a(n);rep(i, n) {r[i] = c[i];a[i] = max(y[i] - x[i], 0LL);}res_y = isp(r, a);}vl res_x;{vi r(n); vl a(n);rep(i, n) {r[i] = n - c[i];a[i] = max(x[i] - y[i], 0LL);}res_x = isp(r, a);}dump(res_y); dump(res_x);ll res = 0;repi(i, 0, n) chmax(res, res_y[i] + res_x[n - i]);rep(i, n) res += min(x[i], y[i]);EXIT(res);//vl d(n);//rep(i, n) {// d[i] = y[i] - x[i];// if (c[i] == 0) d[i] = x[i];//}//dump(d);//auto res = floating_interval_scheduling(c, d);//dump(res);//res += accumulate(all(x), 0LL);//EXIT(res);//vector<tuple<ll, ll, ll>> cxy(n);//rep(i, n) {// ll c, x, y;// cin >> c >> x >> y;// cxy[i] = { c, x, y };//}//sort(all(cxy), [&](tuple<ll, ll, ll> l, tuple<ll, ll, ll> r) {// auto [cl, xl, yl] = l;// auto [cr, xr, yr] = r;// ll maisuu = 0;// ll l2r = (maisuu >= cl ? xl : yl) + (maisuu + 1 >= cl ? xl : yl)//});}