Submission #892895

# Submission time Handle Problem Language Result Execution time Memory
892895 2023-12-26T06:38:44 Z Trisanu_Das Catfish Farm (IOI22_fish) C++17
100 / 100
250 ms 25224 KB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
vector<pair<int, int> > fishes[100005];
 
struct SegmentTree{
    ll tree[1 << 18];
    void init() {
        memset(tree, 0xcf, sizeof(tree));
    }
    void upd(int idx, int s, int e, int l, int r, ll val) {
        if (e < l || r < s) return;
        if (l <= s && e <= r) {
            tree[idx] = max(tree[idx], val);
            return;
        }
        int mid = (s + e) / 2;
        upd(2 * idx, s, mid, l, r, val);
        upd(2 * idx + 1, mid + 1, e, l, r, val);
    }
    ll qry(int idx, int s, int e, int x) {
        if (s == e) return tree[idx];
        int mid = (s + e) / 2;
        if (x <= mid) return max(tree[idx], qry(2 * idx, s, mid, x));
        return max(tree[idx], qry(2 * idx + 1, mid + 1, e, x));
    }
} st_up, st_down;
 
ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
    for (int i = 0; i < M; i++) fishes[X[i] + 1].push_back({Y[i] + 1, W[i]});
    ll till_now = 0;
    st_down.init();
    for (int i = 1; i <= N; i++) {
        sort(fishes[i].begin(), fishes[i].end());
        for (auto [j, w] : fishes[i])  st_up.upd(1, 0, N + 1, j + 1, N + 1, st_up.qry(1, 0, N + 1, j) + w);
        reverse(fishes[i].begin(), fishes[i].end());
        for (auto [j, w] : fishes[i]) st_down.upd(1, 0, N + 1, 0, j - 1, st_down.qry(1, 0, N + 1, j) + w);
        ll u_res = st_up.qry(1, 0, N + 1, N + 1), d_res = st_down.qry(1, 0, N + 1, 0);
        st_up.upd(1, 0, N + 1, 0, N + 1, d_res);
        st_down.upd(1, 0, N + 1, 0, N + 1, till_now);
        till_now = max(u_res, d_res);
    }
    return st_down.qry(1, 0, N + 1, 0);
}
# Verdict Execution time Memory Grader output
1 Correct 50 ms 9420 KB Output is correct
2 Correct 61 ms 11888 KB Output is correct
3 Correct 7 ms 6896 KB Output is correct
4 Correct 7 ms 6748 KB Output is correct
5 Correct 198 ms 22852 KB Output is correct
6 Correct 226 ms 24916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 95 ms 14792 KB Output is correct
3 Correct 116 ms 16820 KB Output is correct
4 Correct 50 ms 10720 KB Output is correct
5 Correct 61 ms 11720 KB Output is correct
6 Correct 1 ms 6744 KB Output is correct
7 Correct 1 ms 6744 KB Output is correct
8 Correct 2 ms 6748 KB Output is correct
9 Correct 1 ms 6748 KB Output is correct
10 Correct 7 ms 6728 KB Output is correct
11 Correct 8 ms 6900 KB Output is correct
12 Correct 55 ms 10992 KB Output is correct
13 Correct 63 ms 11808 KB Output is correct
14 Correct 50 ms 10976 KB Output is correct
15 Correct 56 ms 11472 KB Output is correct
16 Correct 52 ms 11076 KB Output is correct
17 Correct 56 ms 11468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 6744 KB Output is correct
2 Correct 8 ms 6744 KB Output is correct
3 Correct 32 ms 10760 KB Output is correct
4 Correct 24 ms 9308 KB Output is correct
5 Correct 60 ms 13772 KB Output is correct
6 Correct 51 ms 13136 KB Output is correct
7 Correct 55 ms 13768 KB Output is correct
8 Correct 56 ms 13868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 1 ms 6744 KB Output is correct
9 Correct 1 ms 6748 KB Output is correct
10 Correct 2 ms 7004 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 1 ms 6744 KB Output is correct
9 Correct 1 ms 6748 KB Output is correct
10 Correct 2 ms 7004 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
15 Correct 1 ms 6748 KB Output is correct
16 Correct 2 ms 7004 KB Output is correct
17 Correct 21 ms 9560 KB Output is correct
18 Correct 18 ms 9308 KB Output is correct
19 Correct 17 ms 9308 KB Output is correct
20 Correct 17 ms 9304 KB Output is correct
21 Correct 16 ms 9308 KB Output is correct
22 Correct 40 ms 11896 KB Output is correct
23 Correct 5 ms 7256 KB Output is correct
24 Correct 13 ms 8284 KB Output is correct
25 Correct 2 ms 6748 KB Output is correct
26 Correct 6 ms 7356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 1 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 1 ms 6744 KB Output is correct
9 Correct 1 ms 6748 KB Output is correct
10 Correct 2 ms 7004 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
15 Correct 1 ms 6748 KB Output is correct
16 Correct 2 ms 7004 KB Output is correct
17 Correct 21 ms 9560 KB Output is correct
18 Correct 18 ms 9308 KB Output is correct
19 Correct 17 ms 9308 KB Output is correct
20 Correct 17 ms 9304 KB Output is correct
21 Correct 16 ms 9308 KB Output is correct
22 Correct 40 ms 11896 KB Output is correct
23 Correct 5 ms 7256 KB Output is correct
24 Correct 13 ms 8284 KB Output is correct
25 Correct 2 ms 6748 KB Output is correct
26 Correct 6 ms 7356 KB Output is correct
27 Correct 3 ms 7000 KB Output is correct
28 Correct 95 ms 18844 KB Output is correct
29 Correct 145 ms 23364 KB Output is correct
30 Correct 152 ms 22880 KB Output is correct
31 Correct 156 ms 22924 KB Output is correct
32 Correct 122 ms 23908 KB Output is correct
33 Correct 152 ms 22744 KB Output is correct
34 Correct 158 ms 22928 KB Output is correct
35 Correct 49 ms 13196 KB Output is correct
36 Correct 142 ms 23552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 6744 KB Output is correct
2 Correct 8 ms 6744 KB Output is correct
3 Correct 32 ms 10760 KB Output is correct
4 Correct 24 ms 9308 KB Output is correct
5 Correct 60 ms 13772 KB Output is correct
6 Correct 51 ms 13136 KB Output is correct
7 Correct 55 ms 13768 KB Output is correct
8 Correct 56 ms 13868 KB Output is correct
9 Correct 65 ms 13532 KB Output is correct
10 Correct 48 ms 12520 KB Output is correct
11 Correct 115 ms 18012 KB Output is correct
12 Correct 1 ms 6744 KB Output is correct
13 Correct 1 ms 6732 KB Output is correct
14 Correct 1 ms 6744 KB Output is correct
15 Correct 1 ms 6748 KB Output is correct
16 Correct 1 ms 6748 KB Output is correct
17 Correct 1 ms 6724 KB Output is correct
18 Correct 7 ms 6748 KB Output is correct
19 Correct 8 ms 6748 KB Output is correct
20 Correct 8 ms 6748 KB Output is correct
21 Correct 9 ms 7000 KB Output is correct
22 Correct 79 ms 13436 KB Output is correct
23 Correct 98 ms 18004 KB Output is correct
24 Correct 121 ms 18708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 9420 KB Output is correct
2 Correct 61 ms 11888 KB Output is correct
3 Correct 7 ms 6896 KB Output is correct
4 Correct 7 ms 6748 KB Output is correct
5 Correct 198 ms 22852 KB Output is correct
6 Correct 226 ms 24916 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 95 ms 14792 KB Output is correct
9 Correct 116 ms 16820 KB Output is correct
10 Correct 50 ms 10720 KB Output is correct
11 Correct 61 ms 11720 KB Output is correct
12 Correct 1 ms 6744 KB Output is correct
13 Correct 1 ms 6744 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
15 Correct 1 ms 6748 KB Output is correct
16 Correct 7 ms 6728 KB Output is correct
17 Correct 8 ms 6900 KB Output is correct
18 Correct 55 ms 10992 KB Output is correct
19 Correct 63 ms 11808 KB Output is correct
20 Correct 50 ms 10976 KB Output is correct
21 Correct 56 ms 11472 KB Output is correct
22 Correct 52 ms 11076 KB Output is correct
23 Correct 56 ms 11468 KB Output is correct
24 Correct 9 ms 6744 KB Output is correct
25 Correct 8 ms 6744 KB Output is correct
26 Correct 32 ms 10760 KB Output is correct
27 Correct 24 ms 9308 KB Output is correct
28 Correct 60 ms 13772 KB Output is correct
29 Correct 51 ms 13136 KB Output is correct
30 Correct 55 ms 13768 KB Output is correct
31 Correct 56 ms 13868 KB Output is correct
32 Correct 1 ms 6748 KB Output is correct
33 Correct 1 ms 6748 KB Output is correct
34 Correct 1 ms 6748 KB Output is correct
35 Correct 1 ms 6748 KB Output is correct
36 Correct 1 ms 6748 KB Output is correct
37 Correct 2 ms 6748 KB Output is correct
38 Correct 1 ms 6748 KB Output is correct
39 Correct 1 ms 6744 KB Output is correct
40 Correct 1 ms 6748 KB Output is correct
41 Correct 2 ms 7004 KB Output is correct
42 Correct 2 ms 6748 KB Output is correct
43 Correct 2 ms 6748 KB Output is correct
44 Correct 2 ms 6748 KB Output is correct
45 Correct 2 ms 6748 KB Output is correct
46 Correct 1 ms 6748 KB Output is correct
47 Correct 2 ms 7004 KB Output is correct
48 Correct 21 ms 9560 KB Output is correct
49 Correct 18 ms 9308 KB Output is correct
50 Correct 17 ms 9308 KB Output is correct
51 Correct 17 ms 9304 KB Output is correct
52 Correct 16 ms 9308 KB Output is correct
53 Correct 40 ms 11896 KB Output is correct
54 Correct 5 ms 7256 KB Output is correct
55 Correct 13 ms 8284 KB Output is correct
56 Correct 2 ms 6748 KB Output is correct
57 Correct 6 ms 7356 KB Output is correct
58 Correct 3 ms 7000 KB Output is correct
59 Correct 95 ms 18844 KB Output is correct
60 Correct 145 ms 23364 KB Output is correct
61 Correct 152 ms 22880 KB Output is correct
62 Correct 156 ms 22924 KB Output is correct
63 Correct 122 ms 23908 KB Output is correct
64 Correct 152 ms 22744 KB Output is correct
65 Correct 158 ms 22928 KB Output is correct
66 Correct 49 ms 13196 KB Output is correct
67 Correct 142 ms 23552 KB Output is correct
68 Correct 65 ms 13532 KB Output is correct
69 Correct 48 ms 12520 KB Output is correct
70 Correct 115 ms 18012 KB Output is correct
71 Correct 1 ms 6744 KB Output is correct
72 Correct 1 ms 6732 KB Output is correct
73 Correct 1 ms 6744 KB Output is correct
74 Correct 1 ms 6748 KB Output is correct
75 Correct 1 ms 6748 KB Output is correct
76 Correct 1 ms 6724 KB Output is correct
77 Correct 7 ms 6748 KB Output is correct
78 Correct 8 ms 6748 KB Output is correct
79 Correct 8 ms 6748 KB Output is correct
80 Correct 9 ms 7000 KB Output is correct
81 Correct 79 ms 13436 KB Output is correct
82 Correct 98 ms 18004 KB Output is correct
83 Correct 121 ms 18708 KB Output is correct
84 Correct 185 ms 23088 KB Output is correct
85 Correct 185 ms 22176 KB Output is correct
86 Correct 220 ms 24984 KB Output is correct
87 Correct 228 ms 25212 KB Output is correct
88 Correct 1 ms 6748 KB Output is correct
89 Correct 250 ms 25224 KB Output is correct
90 Correct 160 ms 23888 KB Output is correct
91 Correct 140 ms 23120 KB Output is correct