結果
問題 | No.2808 Concentration |
ユーザー | Slephy |
提出日時 | 2024-07-12 23:52:16 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 154 ms / 2,000 ms |
コード長 | 7,722 bytes |
コンパイル時間 | 3,330 ms |
コンパイル使用メモリ | 259,488 KB |
実行使用メモリ | 15,344 KB |
最終ジャッジ日時 | 2024-07-12 23:52:29 |
合計ジャッジ時間 | 12,100 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 132 ms
15,280 KB |
testcase_01 | AC | 133 ms
15,204 KB |
testcase_02 | AC | 130 ms
15,104 KB |
testcase_03 | AC | 133 ms
15,272 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 1 ms
6,944 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 54 ms
8,432 KB |
testcase_08 | AC | 23 ms
6,944 KB |
testcase_09 | AC | 3 ms
6,940 KB |
testcase_10 | AC | 80 ms
10,484 KB |
testcase_11 | AC | 78 ms
10,228 KB |
testcase_12 | AC | 36 ms
6,944 KB |
testcase_13 | AC | 119 ms
14,520 KB |
testcase_14 | AC | 19 ms
6,940 KB |
testcase_15 | AC | 112 ms
14,404 KB |
testcase_16 | AC | 109 ms
14,200 KB |
testcase_17 | AC | 140 ms
14,880 KB |
testcase_18 | AC | 125 ms
15,252 KB |
testcase_19 | AC | 62 ms
9,076 KB |
testcase_20 | AC | 120 ms
14,872 KB |
testcase_21 | AC | 106 ms
13,740 KB |
testcase_22 | AC | 77 ms
10,100 KB |
testcase_23 | AC | 72 ms
9,844 KB |
testcase_24 | AC | 116 ms
14,444 KB |
testcase_25 | AC | 62 ms
9,076 KB |
testcase_26 | AC | 117 ms
14,248 KB |
testcase_27 | AC | 130 ms
15,168 KB |
testcase_28 | AC | 154 ms
15,144 KB |
testcase_29 | AC | 125 ms
15,136 KB |
testcase_30 | AC | 125 ms
15,136 KB |
testcase_31 | AC | 125 ms
15,204 KB |
testcase_32 | AC | 124 ms
15,236 KB |
testcase_33 | AC | 127 ms
15,104 KB |
testcase_34 | AC | 126 ms
15,244 KB |
testcase_35 | AC | 128 ms
15,144 KB |
testcase_36 | AC | 152 ms
15,168 KB |
testcase_37 | AC | 130 ms
15,144 KB |
testcase_38 | AC | 127 ms
15,164 KB |
testcase_39 | AC | 127 ms
15,340 KB |
testcase_40 | AC | 127 ms
15,208 KB |
testcase_41 | AC | 128 ms
15,252 KB |
testcase_42 | AC | 130 ms
15,276 KB |
testcase_43 | AC | 129 ms
15,244 KB |
testcase_44 | AC | 129 ms
15,100 KB |
testcase_45 | AC | 153 ms
15,344 KB |
testcase_46 | AC | 128 ms
15,168 KB |
testcase_47 | AC | 2 ms
6,940 KB |
testcase_48 | AC | 2 ms
6,940 KB |
testcase_49 | AC | 2 ms
6,940 KB |
testcase_50 | AC | 2 ms
6,940 KB |
testcase_51 | AC | 2 ms
6,940 KB |
testcase_52 | AC | 2 ms
6,944 KB |
testcase_53 | AC | 2 ms
6,944 KB |
testcase_54 | AC | 2 ms
6,940 KB |
testcase_55 | AC | 2 ms
6,940 KB |
testcase_56 | AC | 2 ms
6,940 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; const int INF = (int)1e9 + 1001010; const ll llINF = (long long)4e18 + 22000020; const string endn = "\n"; template <class T> inline auto vector2(size_t i, size_t j, const T &init = T()) {return vector(i, vector<T>(j, init));} const string ELM_SEP = " ", VEC_SEP = endn; template<class T> istream& operator >>(istream &i, vector<T> &A) {for(auto &I : A) {i >> I;} return i;} template<class T> ostream& operator <<(ostream &o, const vector<T> &A) {int i=A.size(); for(const auto &I : A){o << I << (--i ? ELM_SEP : "");} return o;} template<class T> ostream& operator <<(ostream &o, const vector<vector<T>> &A) {int i=A.size(); for(const auto &I : A){o << I << (--i ? VEC_SEP : "");} return o;} template<class T> vector<T>& operator ++(vector<T> &A, int n) {for(auto &I : A) {I++;} return A;} template<class T> vector<T>& operator --(vector<T> &A, int n) {for(auto &I : A) {I--;} return A;} template<class T, class U> bool chmax(T &a, const U &b) {return ((a < b) ? (a = b, true) : false);} template<class T, class U> bool chmin(T &a, const U &b) {return ((a > b) ? (a = b, true) : false);} ll floor(ll a, ll b){if (b < 0) a = -a, b = -b; if(a >= 0) return a / b; else return (a + 1) / b - 1;} ll ceil(ll a, ll b){if (b < 0) a = -a, b = -b; if(a > 0) return (a - 1) / b + 1; else return a / b;} ll bit(unsigned long long val, unsigned long long digit){return (val >> digit) & 1;} #ifdef DEBUG #include <cpp-dump/dump.hpp> #define dump(...) cpp_dump(__VA_ARGS__) namespace cp = cpp_dump; struct InitCppDump{ InitCppDump(){ if(!isatty(fileno(stderr))) CPP_DUMP_SET_OPTION(es_style, cpp_dump::es_style_t::no_es); CPP_DUMP_SET_OPTION(log_label_func, cp::log_label::line()); CPP_DUMP_SET_OPTION(max_iteration_count, 30); } } init_cpp_dump; #else #define dump(...) #endif // ================================== ここまでテンプレ ================================== // ACLの実装を一部改変したもの // == 変更点 == // internal::ceil_pow2 を埋め込み // add関数 を追加 // size関数 を追加 template <class S, S (*op)(S, S), S (*e)()> struct segtree { public: segtree() : segtree(0) {} explicit segtree(int n) : segtree(vector<S>(n, e())) {} explicit segtree(const vector<S>& v) : _n(int(v.size())) { log = 0; while((1U << log) < (unsigned int)(_n)) log++; _size = 1 << log; d = vector<S>(2 * _size, e()); for (int i = 0; i < _n; i++) d[_size + i] = v[i]; for (int i = _size - 1; i >= 1; i--) { update(i); } } size_t size() const { return _n; } void set(int p, S x) { assert(0 <= p && p < _n); p += _size; d[p] = x; for (int i = 1; i <= log; i++) update(p >> i); } void add(int p, S x){ assert(0 <= p && p < _n); p += _size; d[p] += x; for (int i = 1; i <= log; i++) update(p >> i); } S get(int p) const { assert(0 <= p && p < _n); return d[p + _size]; } S prod(int l, int r) const { assert(0 <= l && l <= r && r <= _n); S sml = e(), smr = e(); l += _size; r += _size; while (l < r) { if (l & 1) sml = op(sml, d[l++]); if (r & 1) smr = op(d[--r], smr); l >>= 1; r >>= 1; } return op(sml, smr); } S all_prod() const { return d[1]; } template <bool (*f)(S)> int max_right(int l) const { return max_right(l, [](S x) { return f(x); }); } template <class F> int max_right(int l, F f) const { assert(0 <= l && l <= _n); assert(f(e())); if (l == _n) return _n; l += _size; S sm = e(); do { while (l % 2 == 0) l >>= 1; if (!f(op(sm, d[l]))) { while (l < _size) { l = (2 * l); if (f(op(sm, d[l]))) { sm = op(sm, d[l]); l++; } } return l - _size; } sm = op(sm, d[l]); l++; } while ((l & -l) != l); return _n; } template <bool (*f)(S)> int min_left(int r) const { return min_left(r, [](S x) { return f(x); }); } template <class F> int min_left(int r, F f) const { assert(0 <= r && r <= _n); assert(f(e())); if (r == 0) return 0; r += _size; S sm = e(); do { r--; while (r > 1 && (r % 2)) r >>= 1; if (!f(op(d[r], sm))) { while (r < _size) { r = (2 * r + 1); if (f(op(d[r], sm))) { sm = op(d[r], sm); r--; } } return r + 1 - _size; } sm = op(d[r], sm); } while ((r & -r) != r); return 0; } friend ostream& operator<<(ostream &os, const segtree &st) { os << "["; for (int i = 0; i < st._n; i++) { if (i != 0) os << ", "; os << st.get(i); } os << "]"; return os; } private: int _n, _size, log; vector<S> d; void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); } }; template<class S> struct RangeSum { static S op(S l, S r){ return l + r; } static S e(){ return 0; } using Type = struct segtree<S, op, e>; }; template<class S> struct RangeMin { static S op(S l, S r){ return min(l, r); } static S e(){ return numeric_limits<S>::max(); } using Type = struct segtree<S, op, e>; }; template<class S> struct RangeMax { static S op(S l, S r){ return max(l, r); } static S e(){ return numeric_limits<S>::min(); } using Type = struct segtree<S, op, e>; }; // ex) RangeMin<int>::Type seg(10); template<class Judgement> ll binary_search_ll(ll ok, ll ng, Judgement judge){ auto need_continue = [&]() -> bool { if(ok > ng) return((__int128_t)ok - (__int128_t)ng > 1); else return ((__int128_t)ng - (__int128_t)ok > 1); }; while(need_continue()){ ll mid = ((__int128_t)ok + (__int128_t)ng) / 2; if(judge(mid)) ok = mid; else ng = mid; } return ok; }; int main(int argc, char *argv[]){ ios::sync_with_stdio(false); cin.tie(nullptr); ll n, s, h; cin >> n >> s >> h; vector<ll> x, y, z; for(int i = 0; i < n; i++){ ll tx, ty, tz; cin >> tx >> ty >> tz; ll len = ty - tx; if(len <= s){ x.push_back(tx); y.push_back(ty); z.push_back(tz); } } n = x.size(); dump(x); dump(y); dump(z); vector<ll> cz(n+1, 0); for(int i = 0; i < z.size(); i++) cz[i+1] = cz[i] + z[i]; RangeMax<ll>::Type dp_s(vector<ll>(n+1, 0)); dp_s.set(0, cz[n]); ll ans = 0; for(int i = 0; i < n; i++){ // i番目の授業の終わりと同時に寝る { ll from = ranges::lower_bound(x, y[i] - s) - x.begin(); ll max_val = dp_s.prod(from, i+1); ll this_ans = max_val - (cz[n] - cz[i+1]); chmax(ans, this_ans); ll to = ranges::lower_bound(x, y[i] + h) - x.begin(); dp_s.set(to, max(dp_s.get(to), max_val - (cz[to] - cz[i+1]))); dump(i, x[i], y[i], from, to, max_val, this_ans); } // i番目の授業を受けない if(i+1 < n){ dp_s.set(i+1, max(dp_s.get(i+1), dp_s.get(i) - z[i])); } dump(dp_s); } cout << ans << endl; return 0; }