Submission #667032

# Submission time Handle Problem Language Result Execution time Memory
667032 2022-11-30T08:17:34 Z tatyam Catfish Farm (IOI22_fish) C++17
100 / 100
260 ms 23208 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void chmax(ll& a, ll b){ if(a < b) a = b; }

// range chmax・1 点取得 で O(M log N)
struct SegTree {
    ll n;
    vector<ll> seg;
    SegTree(ll n): n(n), seg(n * 2) {}
    void range_chmax(ll l, ll r, ll x) {
        l += n;
        r += n;
        while(l < r){
            if(l & 1) chmax(seg[l++], x);
            if(r & 1) chmax(seg[--r], x);
            l >>= 1; r >>= 1;
        }
    }
    ll operator[](ll i) const {
        i += n;
        ll x = 0;
        do chmax(x, seg[i]); while(i >>= 1);
        return x;
    }
};
ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
    vector fish(N, vector<pair<ll, ll>>{});
    for (ll i = 0; i < M; i++) {
        fish[X[i]].emplace_back(Y[i], W[i]);
    }
    for (auto& v : fish) sort(v.begin(), v.end());
    SegTree up(N + 1), down(N + 1);
    ll zero = 0;
    for(ll x = 0; x + 1 < N; x++) {
        for(auto [y, w] : fish[x]) {
            up.range_chmax(y + 1, N + 1, up[y] + w);
        }
        reverse(fish[x + 1].begin(), fish[x + 1].end());
        for(auto [y, w] : fish[x + 1]) {
            down.range_chmax(0, y + 1, down[y + 1] + w);
        }
        reverse(fish[x + 1].begin(), fish[x + 1].end());
        const ll zero_ = exchange(zero, down[0]);
        down.range_chmax(0, N + 1, max(up[N], zero_));
        up.range_chmax(0, N + 1, zero_);
    }
    return max({zero, down[0], up[N]});
}
# Verdict Execution time Memory Grader output
1 Correct 44 ms 8396 KB Output is correct
2 Correct 58 ms 9788 KB Output is correct
3 Correct 12 ms 5716 KB Output is correct
4 Correct 12 ms 5716 KB Output is correct
5 Correct 164 ms 17988 KB Output is correct
6 Correct 207 ms 20428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 86 ms 11964 KB Output is correct
3 Correct 111 ms 13764 KB Output is correct
4 Correct 44 ms 8400 KB Output is correct
5 Correct 54 ms 9768 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 17 ms 5716 KB Output is correct
11 Correct 13 ms 5716 KB Output is correct
12 Correct 51 ms 8528 KB Output is correct
13 Correct 62 ms 9764 KB Output is correct
14 Correct 49 ms 8556 KB Output is correct
15 Correct 60 ms 9528 KB Output is correct
16 Correct 47 ms 8620 KB Output is correct
17 Correct 53 ms 9404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 5808 KB Output is correct
2 Correct 13 ms 5716 KB Output is correct
3 Correct 38 ms 8180 KB Output is correct
4 Correct 28 ms 7864 KB Output is correct
5 Correct 54 ms 11388 KB Output is correct
6 Correct 53 ms 11340 KB Output is correct
7 Correct 54 ms 11380 KB Output is correct
8 Correct 63 ms 11368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 19 ms 2256 KB Output is correct
18 Correct 18 ms 2884 KB Output is correct
19 Correct 18 ms 2752 KB Output is correct
20 Correct 17 ms 2760 KB Output is correct
21 Correct 18 ms 2672 KB Output is correct
22 Correct 37 ms 5056 KB Output is correct
23 Correct 4 ms 724 KB Output is correct
24 Correct 12 ms 1620 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 4 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 19 ms 2256 KB Output is correct
18 Correct 18 ms 2884 KB Output is correct
19 Correct 18 ms 2752 KB Output is correct
20 Correct 17 ms 2760 KB Output is correct
21 Correct 18 ms 2672 KB Output is correct
22 Correct 37 ms 5056 KB Output is correct
23 Correct 4 ms 724 KB Output is correct
24 Correct 12 ms 1620 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 4 ms 724 KB Output is correct
27 Correct 2 ms 596 KB Output is correct
28 Correct 91 ms 13704 KB Output is correct
29 Correct 135 ms 17268 KB Output is correct
30 Correct 136 ms 16716 KB Output is correct
31 Correct 136 ms 16720 KB Output is correct
32 Correct 125 ms 18508 KB Output is correct
33 Correct 147 ms 16684 KB Output is correct
34 Correct 157 ms 16776 KB Output is correct
35 Correct 49 ms 8268 KB Output is correct
36 Correct 140 ms 18656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 5808 KB Output is correct
2 Correct 13 ms 5716 KB Output is correct
3 Correct 38 ms 8180 KB Output is correct
4 Correct 28 ms 7864 KB Output is correct
5 Correct 54 ms 11388 KB Output is correct
6 Correct 53 ms 11340 KB Output is correct
7 Correct 54 ms 11380 KB Output is correct
8 Correct 63 ms 11368 KB Output is correct
9 Correct 81 ms 11392 KB Output is correct
10 Correct 52 ms 8236 KB Output is correct
11 Correct 104 ms 15824 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 15 ms 5716 KB Output is correct
19 Correct 12 ms 5684 KB Output is correct
20 Correct 12 ms 5716 KB Output is correct
21 Correct 12 ms 5796 KB Output is correct
22 Correct 85 ms 10952 KB Output is correct
23 Correct 121 ms 18232 KB Output is correct
24 Correct 137 ms 18240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 8396 KB Output is correct
2 Correct 58 ms 9788 KB Output is correct
3 Correct 12 ms 5716 KB Output is correct
4 Correct 12 ms 5716 KB Output is correct
5 Correct 164 ms 17988 KB Output is correct
6 Correct 207 ms 20428 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 86 ms 11964 KB Output is correct
9 Correct 111 ms 13764 KB Output is correct
10 Correct 44 ms 8400 KB Output is correct
11 Correct 54 ms 9768 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 17 ms 5716 KB Output is correct
17 Correct 13 ms 5716 KB Output is correct
18 Correct 51 ms 8528 KB Output is correct
19 Correct 62 ms 9764 KB Output is correct
20 Correct 49 ms 8556 KB Output is correct
21 Correct 60 ms 9528 KB Output is correct
22 Correct 47 ms 8620 KB Output is correct
23 Correct 53 ms 9404 KB Output is correct
24 Correct 16 ms 5808 KB Output is correct
25 Correct 13 ms 5716 KB Output is correct
26 Correct 38 ms 8180 KB Output is correct
27 Correct 28 ms 7864 KB Output is correct
28 Correct 54 ms 11388 KB Output is correct
29 Correct 53 ms 11340 KB Output is correct
30 Correct 54 ms 11380 KB Output is correct
31 Correct 63 ms 11368 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 0 ms 212 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 19 ms 2256 KB Output is correct
49 Correct 18 ms 2884 KB Output is correct
50 Correct 18 ms 2752 KB Output is correct
51 Correct 17 ms 2760 KB Output is correct
52 Correct 18 ms 2672 KB Output is correct
53 Correct 37 ms 5056 KB Output is correct
54 Correct 4 ms 724 KB Output is correct
55 Correct 12 ms 1620 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 4 ms 724 KB Output is correct
58 Correct 2 ms 596 KB Output is correct
59 Correct 91 ms 13704 KB Output is correct
60 Correct 135 ms 17268 KB Output is correct
61 Correct 136 ms 16716 KB Output is correct
62 Correct 136 ms 16720 KB Output is correct
63 Correct 125 ms 18508 KB Output is correct
64 Correct 147 ms 16684 KB Output is correct
65 Correct 157 ms 16776 KB Output is correct
66 Correct 49 ms 8268 KB Output is correct
67 Correct 140 ms 18656 KB Output is correct
68 Correct 81 ms 11392 KB Output is correct
69 Correct 52 ms 8236 KB Output is correct
70 Correct 104 ms 15824 KB Output is correct
71 Correct 1 ms 212 KB Output is correct
72 Correct 1 ms 300 KB Output is correct
73 Correct 0 ms 212 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 0 ms 212 KB Output is correct
76 Correct 1 ms 212 KB Output is correct
77 Correct 15 ms 5716 KB Output is correct
78 Correct 12 ms 5684 KB Output is correct
79 Correct 12 ms 5716 KB Output is correct
80 Correct 12 ms 5796 KB Output is correct
81 Correct 85 ms 10952 KB Output is correct
82 Correct 121 ms 18232 KB Output is correct
83 Correct 137 ms 18240 KB Output is correct
84 Correct 167 ms 20296 KB Output is correct
85 Correct 165 ms 20988 KB Output is correct
86 Correct 260 ms 22476 KB Output is correct
87 Correct 230 ms 23208 KB Output is correct
88 Correct 1 ms 212 KB Output is correct
89 Correct 234 ms 23208 KB Output is correct
90 Correct 166 ms 23132 KB Output is correct
91 Correct 145 ms 22988 KB Output is correct