結果
問題 | No.2232 Miser's Gift |
ユーザー | k1suxu |
提出日時 | 2023-03-03 22:10:14 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 211 ms / 2,000 ms |
コード長 | 5,549 bytes |
コンパイル時間 | 2,956 ms |
コンパイル使用メモリ | 254,276 KB |
実行使用メモリ | 84,536 KB |
最終ジャッジ日時 | 2024-09-17 23:12:14 |
合計ジャッジ時間 | 11,810 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,812 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 205 ms
84,532 KB |
testcase_04 | AC | 206 ms
84,532 KB |
testcase_05 | AC | 22 ms
11,520 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 133 ms
6,944 KB |
testcase_08 | AC | 211 ms
84,488 KB |
testcase_09 | AC | 201 ms
84,480 KB |
testcase_10 | AC | 199 ms
84,532 KB |
testcase_11 | AC | 200 ms
84,536 KB |
testcase_12 | AC | 202 ms
84,532 KB |
testcase_13 | AC | 197 ms
84,404 KB |
testcase_14 | AC | 196 ms
84,408 KB |
testcase_15 | AC | 196 ms
84,532 KB |
testcase_16 | AC | 199 ms
84,528 KB |
testcase_17 | AC | 202 ms
84,532 KB |
testcase_18 | AC | 194 ms
84,532 KB |
testcase_19 | AC | 196 ms
84,532 KB |
testcase_20 | AC | 199 ms
84,532 KB |
testcase_21 | AC | 198 ms
84,404 KB |
testcase_22 | AC | 206 ms
84,528 KB |
testcase_23 | AC | 202 ms
84,536 KB |
testcase_24 | AC | 204 ms
84,532 KB |
testcase_25 | AC | 203 ms
84,404 KB |
testcase_26 | AC | 206 ms
84,416 KB |
testcase_27 | AC | 207 ms
84,532 KB |
testcase_28 | AC | 200 ms
84,536 KB |
testcase_29 | AC | 202 ms
84,408 KB |
testcase_30 | AC | 197 ms
84,532 KB |
testcase_31 | AC | 203 ms
84,400 KB |
testcase_32 | AC | 198 ms
84,532 KB |
testcase_33 | AC | 204 ms
84,532 KB |
testcase_34 | AC | 198 ms
84,404 KB |
testcase_35 | AC | 198 ms
84,400 KB |
testcase_36 | AC | 203 ms
84,528 KB |
testcase_37 | AC | 200 ms
84,408 KB |
testcase_38 | AC | 4 ms
6,944 KB |
testcase_39 | AC | 3 ms
6,944 KB |
testcase_40 | AC | 3 ms
6,944 KB |
testcase_41 | AC | 4 ms
6,944 KB |
testcase_42 | AC | 4 ms
6,940 KB |
testcase_43 | AC | 4 ms
6,940 KB |
testcase_44 | AC | 4 ms
6,940 KB |
testcase_45 | AC | 4 ms
6,940 KB |
testcase_46 | AC | 4 ms
6,944 KB |
testcase_47 | AC | 4 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,944 KB |
testcase_51 | AC | 1 ms
6,944 KB |
testcase_52 | AC | 2 ms
6,944 KB |
testcase_53 | AC | 2 ms
6,948 KB |
testcase_54 | AC | 2 ms
6,940 KB |
testcase_55 | AC | 2 ms
6,940 KB |
testcase_56 | AC | 2 ms
6,944 KB |
testcase_57 | AC | 1 ms
6,940 KB |
ソースコード
// #pragma GCC target("avx") // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < (int)n; i++) #define FOR(n) for(int i = 0; i < (int)n; i++) #define repi(i,a,b) for(int i = (int)a; i < (int)b; i++) #define all(x) x.begin(),x.end() //#define mp make_pair #define vi vector<int> #define vvi vector<vi> #define vvvi vector<vvi> #define vvvvi vector<vvvi> #define pii pair<int,int> #define vpii vector<pair<int,int>> template<typename T> void chmax(T &a, const T &b) {a = (a > b? a : b);} template<typename T> void chmin(T &a, const T &b) {a = (a < b? a : b);} using ll = long long; using ld = long double; using ull = unsigned long long; const ll INF = numeric_limits<long long>::max() / 2; const ld pi = 3.1415926535897932384626433832795028; const ll mod = 998244353; int dx[] = {1, 0, -1, 0, -1, -1, 1, 1}; int dy[] = {0, 1, 0, -1, -1, 1, -1, 1}; #define int long long namespace internal { // @param n `0 <= n` // @return minimum non-negative `x` s.t. `n <= 2**x` int ceil_pow2(int n) { int x = 0; while ((1U << x) < (unsigned int)(n)) x++; return x; } // @param n `1 <= n` // @return minimum non-negative `x` s.t. `(n & (1 << x)) != 0` constexpr int bsf_constexpr(unsigned int n) { int x = 0; while (!(n & (1 << x))) x++; return x; } // @param n `1 <= n` // @return minimum non-negative `x` s.t. `(n & (1 << x)) != 0` int bsf(unsigned int n) { #ifdef _MSC_VER unsigned long index; _BitScanForward(&index, n); return index; #else return __builtin_ctz(n); #endif } } // namespace internal template <class S, S (*op)(S, S), S (*e)()> struct segtree { public: segtree() : segtree(0) {} explicit segtree(int n) : segtree(std::vector<S>(n, e())) {} explicit segtree(const std::vector<S>& v) : _n((int)v.size()) { log = internal::ceil_pow2(_n); size = 1 << log; d = std::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); } } 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); } 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; } private: int _n, size, log; std::vector<S> d; void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); } }; using S = int; S op(S x, S y) { return max(x, y); } S e() { return 0; } void solve() { int n, w; cin >> n >> w; vi weight(n), value(n); FOR(n) cin >> weight[i] >> value[i]; vvi dp(n+1, vi(w+1, 0)); rep(i, n) { rep(j, w+1) { if(j+weight[i] <= w) chmax(dp[i+1][j+weight[i]], dp[i][j] + value[i]); chmax(dp[i+1][j], dp[i][j]); } } // for(auto e : dp[n]) cout << e << " "; cout << "\n"; segtree<S, op, e> seg(dp[n]); repi(i, 1, w+1) { int fr = seg.prod(0, w-i+1), bc = seg.prod(w-i+1, w+1); cout << bc - fr + 1 << endl; } // vi used; // int mx_id = (int)(max_element(all(dp[n])) - dp[n].begin()); // for(int i = n; i >= 1; i--) { // if(dp[i][mx_id] == dp[i-1][mx_id - weight[i-1]] + value[i-1]) { // mx_id -= weight[i]; // } // } } signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); return 0; }