답안 #969654

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
969654 2024-04-25T12:23:13 Z vjudge1 메기 농장 (IOI22_fish) C++17
100 / 100
518 ms 43360 KB
#include "fish.h"

#include <bits/stdc++.h>
using namespace std;

const int64_t inf = 1e18;

class segtree_t {
   public:
    segtree_t *left, *right;
    int l, r, m;
    int64_t val;

    segtree_t(int l, int r) : l(l), r(r), m(l + r >> 1), val(-inf) {
        if (l == r) return;
        left = new segtree_t(l, m);
        right = new segtree_t(m + 1, r);
    }

    void Update(int s, int t, int64_t x) {
        if (r < s || l > t) return;
        if (s <= l && r <= t) {
            val = max(val, x);
            return;
        }
        left->Update(s, t, x);
        right->Update(s, t, x);
    }

    int64_t Get(int p) {
        if (l == r) return val;
        if (p <= m) return max(val, left->Get(p));
        return max(val, right->Get(p));
    }
};

long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W) {
    vector<int64_t> sum(N);
    vector<int> aback(N);
    for (int i = 0; i < M; i++) {
        sum[X[i]] += W[i];
        if (Y[i] == N - 1) aback[X[i]] = W[i];
    }

    const int64_t inf = 1e18;
    vector<vector<pair<int, int>>> event(N);
    for (int i = 0; i < M; i++) {
        event[X[i]].emplace_back(Y[i], W[i]);
    }
    for (int i = 0; i < N; i++) {
        event[i].emplace_back(0, 0);
        event[i].emplace_back(N - 2, 0);
        sort(event[i].begin(), event[i].end());
    }
    segtree_t *tree0 = new segtree_t(0, N);
    segtree_t *tree1 = new segtree_t(0, N);
    tree0->Update(0, N, 0);
    tree1->Update(N, N, 0);

    for (int i = 0; i < N; i++) {
        if (i + 1 < N) {
            for (auto [y, w] : event[i]) {
                tree0->Update(y + 1, N, tree0->Get(y) + w);
            }
        }
        reverse(event[i].begin(), event[i].end());
        if (i > 0) {
            for (auto [y, w] : event[i]) {
                if (y == N - 1) continue;
                tree1->Update(0, y, tree1->Get(y + 1) + w);
            }
        }
        if (i == 1) tree0->Update(0, 0, sum[0]);
        if (i + 2 < N) tree0->Update(0, 0, tree1->Get(0));
        if (i == N - 1) break;
        int64_t dpN1 = tree1->Get(N);
        int64_t dp01 = tree1->Get(0);
        tree1->Update(N, N, max(tree0->Get(N), tree0->Get(0)));
        if (i + 1 == N - 1) tree0->Update(N, N, tree0->Get(0) + sum[N - 1]);
        tree1->Update(N - 1, N - 1, dpN1 + aback[i + 1]);
        tree0->Update(0, 0, dp01);
    }

    return max(tree1->Get(0), max(tree0->Get(N), tree1->Get(N)));
}

Compilation message

fish.cpp: In constructor 'segtree_t::segtree_t(int, int)':
fish.cpp:14:47: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   14 |     segtree_t(int l, int r) : l(l), r(r), m(l + r >> 1), val(-inf) {
      |                                             ~~^~~
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:46:19: warning: unused variable 'inf' [-Wunused-variable]
   46 |     const int64_t inf = 1e18;
      |                   ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 117 ms 26056 KB Output is correct
2 Correct 141 ms 30776 KB Output is correct
3 Correct 90 ms 25688 KB Output is correct
4 Correct 89 ms 25864 KB Output is correct
5 Correct 270 ms 41664 KB Output is correct
6 Correct 485 ms 43088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 169 ms 31368 KB Output is correct
3 Correct 226 ms 35520 KB Output is correct
4 Correct 116 ms 27060 KB Output is correct
5 Correct 138 ms 30732 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 440 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 432 KB Output is correct
10 Correct 90 ms 25692 KB Output is correct
11 Correct 91 ms 25688 KB Output is correct
12 Correct 132 ms 27084 KB Output is correct
13 Correct 149 ms 30636 KB Output is correct
14 Correct 121 ms 27300 KB Output is correct
15 Correct 140 ms 30388 KB Output is correct
16 Correct 123 ms 27304 KB Output is correct
17 Correct 135 ms 30256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 109 ms 25684 KB Output is correct
2 Correct 92 ms 25868 KB Output is correct
3 Correct 105 ms 26524 KB Output is correct
4 Correct 109 ms 27996 KB Output is correct
5 Correct 165 ms 32212 KB Output is correct
6 Correct 146 ms 31648 KB Output is correct
7 Correct 143 ms 32084 KB Output is correct
8 Correct 141 ms 32188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 504 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 504 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 17 ms 1880 KB Output is correct
18 Correct 17 ms 2248 KB Output is correct
19 Correct 16 ms 2140 KB Output is correct
20 Correct 17 ms 2228 KB Output is correct
21 Correct 17 ms 2136 KB Output is correct
22 Correct 33 ms 3804 KB Output is correct
23 Correct 5 ms 600 KB Output is correct
24 Correct 13 ms 1288 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 4 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 504 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 17 ms 1880 KB Output is correct
18 Correct 17 ms 2248 KB Output is correct
19 Correct 16 ms 2140 KB Output is correct
20 Correct 17 ms 2228 KB Output is correct
21 Correct 17 ms 2136 KB Output is correct
22 Correct 33 ms 3804 KB Output is correct
23 Correct 5 ms 600 KB Output is correct
24 Correct 13 ms 1288 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 4 ms 604 KB Output is correct
27 Correct 4 ms 1116 KB Output is correct
28 Correct 101 ms 8600 KB Output is correct
29 Correct 170 ms 11604 KB Output is correct
30 Correct 173 ms 11248 KB Output is correct
31 Correct 159 ms 11232 KB Output is correct
32 Correct 125 ms 12372 KB Output is correct
33 Correct 171 ms 11088 KB Output is correct
34 Correct 166 ms 11092 KB Output is correct
35 Correct 52 ms 5148 KB Output is correct
36 Correct 152 ms 11892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 109 ms 25684 KB Output is correct
2 Correct 92 ms 25868 KB Output is correct
3 Correct 105 ms 26524 KB Output is correct
4 Correct 109 ms 27996 KB Output is correct
5 Correct 165 ms 32212 KB Output is correct
6 Correct 146 ms 31648 KB Output is correct
7 Correct 143 ms 32084 KB Output is correct
8 Correct 141 ms 32188 KB Output is correct
9 Correct 160 ms 32012 KB Output is correct
10 Correct 88 ms 18260 KB Output is correct
11 Correct 185 ms 36420 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 89 ms 25692 KB Output is correct
19 Correct 98 ms 25692 KB Output is correct
20 Correct 91 ms 25864 KB Output is correct
21 Correct 91 ms 25868 KB Output is correct
22 Correct 229 ms 31864 KB Output is correct
23 Correct 184 ms 36316 KB Output is correct
24 Correct 207 ms 37068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 117 ms 26056 KB Output is correct
2 Correct 141 ms 30776 KB Output is correct
3 Correct 90 ms 25688 KB Output is correct
4 Correct 89 ms 25864 KB Output is correct
5 Correct 270 ms 41664 KB Output is correct
6 Correct 485 ms 43088 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 169 ms 31368 KB Output is correct
9 Correct 226 ms 35520 KB Output is correct
10 Correct 116 ms 27060 KB Output is correct
11 Correct 138 ms 30732 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 440 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 432 KB Output is correct
16 Correct 90 ms 25692 KB Output is correct
17 Correct 91 ms 25688 KB Output is correct
18 Correct 132 ms 27084 KB Output is correct
19 Correct 149 ms 30636 KB Output is correct
20 Correct 121 ms 27300 KB Output is correct
21 Correct 140 ms 30388 KB Output is correct
22 Correct 123 ms 27304 KB Output is correct
23 Correct 135 ms 30256 KB Output is correct
24 Correct 109 ms 25684 KB Output is correct
25 Correct 92 ms 25868 KB Output is correct
26 Correct 105 ms 26524 KB Output is correct
27 Correct 109 ms 27996 KB Output is correct
28 Correct 165 ms 32212 KB Output is correct
29 Correct 146 ms 31648 KB Output is correct
30 Correct 143 ms 32084 KB Output is correct
31 Correct 141 ms 32188 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 504 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 17 ms 1880 KB Output is correct
49 Correct 17 ms 2248 KB Output is correct
50 Correct 16 ms 2140 KB Output is correct
51 Correct 17 ms 2228 KB Output is correct
52 Correct 17 ms 2136 KB Output is correct
53 Correct 33 ms 3804 KB Output is correct
54 Correct 5 ms 600 KB Output is correct
55 Correct 13 ms 1288 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 4 ms 604 KB Output is correct
58 Correct 4 ms 1116 KB Output is correct
59 Correct 101 ms 8600 KB Output is correct
60 Correct 170 ms 11604 KB Output is correct
61 Correct 173 ms 11248 KB Output is correct
62 Correct 159 ms 11232 KB Output is correct
63 Correct 125 ms 12372 KB Output is correct
64 Correct 171 ms 11088 KB Output is correct
65 Correct 166 ms 11092 KB Output is correct
66 Correct 52 ms 5148 KB Output is correct
67 Correct 152 ms 11892 KB Output is correct
68 Correct 160 ms 32012 KB Output is correct
69 Correct 88 ms 18260 KB Output is correct
70 Correct 185 ms 36420 KB Output is correct
71 Correct 1 ms 348 KB Output is correct
72 Correct 1 ms 348 KB Output is correct
73 Correct 1 ms 348 KB Output is correct
74 Correct 0 ms 348 KB Output is correct
75 Correct 0 ms 348 KB Output is correct
76 Correct 1 ms 348 KB Output is correct
77 Correct 89 ms 25692 KB Output is correct
78 Correct 98 ms 25692 KB Output is correct
79 Correct 91 ms 25864 KB Output is correct
80 Correct 91 ms 25868 KB Output is correct
81 Correct 229 ms 31864 KB Output is correct
82 Correct 184 ms 36316 KB Output is correct
83 Correct 207 ms 37068 KB Output is correct
84 Correct 297 ms 38980 KB Output is correct
85 Correct 322 ms 41228 KB Output is correct
86 Correct 518 ms 40372 KB Output is correct
87 Correct 430 ms 42992 KB Output is correct
88 Correct 1 ms 348 KB Output is correct
89 Correct 498 ms 43360 KB Output is correct
90 Correct 235 ms 41744 KB Output is correct
91 Correct 252 ms 41552 KB Output is correct