Submission #1076263

# Submission time Handle Problem Language Result Execution time Memory
1076263 2024-08-26T12:21:17 Z vjudge1 Catfish Farm (IOI22_fish) C++17
100 / 100
129 ms 25048 KB
#include "fish.h"

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;
using vll = vector<ll>;

struct AIB {
    int n;
    bool rev;
    vll V;

    AIB(int N, bool RV) : n(N + 1), rev(RV), V(N + 1, 0) {}

    void update(int p, ll v) {
        if(rev) p = n - p - 1;
        ++p;
        while(p < n) {
            V[p] = max(V[p], v);
            p += p & -p;
        }
    }

    ll query(int p) {
        if(rev) p = n - p - 1;
        ++p;
        ll re = 0;
        while(p) {
            re = max(re, V[p]);
            p -= p & -p;
        }
        return re;
    }
};

ll max_weights(int n, int m, vi X, vi Y, vi W) {
    vector<vector<ii> > A(n);
    for(int i = 0; i < m; ++i) 
        A[X[i]].push_back({Y[i], W[i]});
    for(int i = 0; i < n; ++i) {
        sort(A[i].begin(), A[i].end());
    }

    vll DP_tot(n, 0), DP0(n, 0), DP1(n, 0);

    AIB MaPre(n, 0), MaSuf(n, 1);

    ll re = 0;
    for(int i = 0; i < n; ++i) {
        ll rez_min = 0;
        if(i > 1) rez_min = DP_tot[i - 2];


        if(i + 1 < n) {
            for(auto [y, w] : A[i]) { /// urcam, facem 0
                ll re0 = rez_min;
                if(i && DP1[i - 1] > re0) re0 = DP1[i - 1];
                if(MaPre.query(y - 1) > re0) re0 = MaPre.query(y - 1);
                if(MaSuf.query(y + 1) > re0) re0 = MaSuf.query(y + 1);

                re0 += w;

                MaPre.update(y, re0);
                DP0[i] = max(DP0[i], re0);
            }
        }

        reverse(A[i].begin(), A[i].end());
        if(i) {
            for(auto [y, w] : A[i]) {
                ll re1 = rez_min;
                if(MaSuf.query(y + 1) > re1) re1 = MaSuf.query(y + 1);

                re1 += w;

                MaSuf.update(y, re1);
                MaPre.update(y, re1);
                DP1[i] = max(DP1[i], re1);
            }
        }

        DP_tot[i] = max(DP0[i], DP1[i]);
        if(i) DP_tot[i] = max(DP_tot[i], DP_tot[i - 1]);
        re = max(re, DP_tot[i]);
    }
    return re;
}
# Verdict Execution time Memory Grader output
1 Correct 26 ms 9932 KB Output is correct
2 Correct 34 ms 11464 KB Output is correct
3 Correct 4 ms 6488 KB Output is correct
4 Correct 4 ms 6492 KB Output is correct
5 Correct 110 ms 22600 KB Output is correct
6 Correct 117 ms 24656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 55 ms 13872 KB Output is correct
3 Correct 73 ms 16680 KB Output is correct
4 Correct 26 ms 10060 KB Output is correct
5 Correct 33 ms 11584 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 3 ms 6492 KB Output is correct
11 Correct 3 ms 6488 KB Output is correct
12 Correct 32 ms 10072 KB Output is correct
13 Correct 39 ms 11460 KB Output is correct
14 Correct 29 ms 10104 KB Output is correct
15 Correct 34 ms 11204 KB Output is correct
16 Correct 28 ms 10188 KB Output is correct
17 Correct 31 ms 11268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6748 KB Output is correct
2 Correct 4 ms 6580 KB Output is correct
3 Correct 23 ms 9816 KB Output is correct
4 Correct 16 ms 9308 KB Output is correct
5 Correct 38 ms 13812 KB Output is correct
6 Correct 39 ms 13148 KB Output is correct
7 Correct 39 ms 13636 KB Output is correct
8 Correct 37 ms 13744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 436 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 436 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 14 ms 2632 KB Output is correct
18 Correct 11 ms 2880 KB Output is correct
19 Correct 11 ms 2904 KB Output is correct
20 Correct 12 ms 2908 KB Output is correct
21 Correct 11 ms 2912 KB Output is correct
22 Correct 23 ms 5324 KB Output is correct
23 Correct 3 ms 856 KB Output is correct
24 Correct 9 ms 1884 KB Output is correct
25 Correct 1 ms 520 KB Output is correct
26 Correct 3 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 436 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 14 ms 2632 KB Output is correct
18 Correct 11 ms 2880 KB Output is correct
19 Correct 11 ms 2904 KB Output is correct
20 Correct 12 ms 2908 KB Output is correct
21 Correct 11 ms 2912 KB Output is correct
22 Correct 23 ms 5324 KB Output is correct
23 Correct 3 ms 856 KB Output is correct
24 Correct 9 ms 1884 KB Output is correct
25 Correct 1 ms 520 KB Output is correct
26 Correct 3 ms 856 KB Output is correct
27 Correct 2 ms 704 KB Output is correct
28 Correct 69 ms 12284 KB Output is correct
29 Correct 100 ms 16872 KB Output is correct
30 Correct 92 ms 16468 KB Output is correct
31 Correct 96 ms 16556 KB Output is correct
32 Correct 98 ms 17488 KB Output is correct
33 Correct 88 ms 16552 KB Output is correct
34 Correct 85 ms 16468 KB Output is correct
35 Correct 33 ms 6736 KB Output is correct
36 Correct 110 ms 17488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6748 KB Output is correct
2 Correct 4 ms 6580 KB Output is correct
3 Correct 23 ms 9816 KB Output is correct
4 Correct 16 ms 9308 KB Output is correct
5 Correct 38 ms 13812 KB Output is correct
6 Correct 39 ms 13148 KB Output is correct
7 Correct 39 ms 13636 KB Output is correct
8 Correct 37 ms 13744 KB Output is correct
9 Correct 42 ms 13404 KB Output is correct
10 Correct 37 ms 9044 KB Output is correct
11 Correct 80 ms 18000 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 4 ms 6584 KB Output is correct
19 Correct 4 ms 6492 KB Output is correct
20 Correct 4 ms 6492 KB Output is correct
21 Correct 4 ms 6492 KB Output is correct
22 Correct 45 ms 13248 KB Output is correct
23 Correct 73 ms 18004 KB Output is correct
24 Correct 84 ms 18508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 9932 KB Output is correct
2 Correct 34 ms 11464 KB Output is correct
3 Correct 4 ms 6488 KB Output is correct
4 Correct 4 ms 6492 KB Output is correct
5 Correct 110 ms 22600 KB Output is correct
6 Correct 117 ms 24656 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 55 ms 13872 KB Output is correct
9 Correct 73 ms 16680 KB Output is correct
10 Correct 26 ms 10060 KB Output is correct
11 Correct 33 ms 11584 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 6492 KB Output is correct
17 Correct 3 ms 6488 KB Output is correct
18 Correct 32 ms 10072 KB Output is correct
19 Correct 39 ms 11460 KB Output is correct
20 Correct 29 ms 10104 KB Output is correct
21 Correct 34 ms 11204 KB Output is correct
22 Correct 28 ms 10188 KB Output is correct
23 Correct 31 ms 11268 KB Output is correct
24 Correct 4 ms 6748 KB Output is correct
25 Correct 4 ms 6580 KB Output is correct
26 Correct 23 ms 9816 KB Output is correct
27 Correct 16 ms 9308 KB Output is correct
28 Correct 38 ms 13812 KB Output is correct
29 Correct 39 ms 13148 KB Output is correct
30 Correct 39 ms 13636 KB Output is correct
31 Correct 37 ms 13744 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 436 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 14 ms 2632 KB Output is correct
49 Correct 11 ms 2880 KB Output is correct
50 Correct 11 ms 2904 KB Output is correct
51 Correct 12 ms 2908 KB Output is correct
52 Correct 11 ms 2912 KB Output is correct
53 Correct 23 ms 5324 KB Output is correct
54 Correct 3 ms 856 KB Output is correct
55 Correct 9 ms 1884 KB Output is correct
56 Correct 1 ms 520 KB Output is correct
57 Correct 3 ms 856 KB Output is correct
58 Correct 2 ms 704 KB Output is correct
59 Correct 69 ms 12284 KB Output is correct
60 Correct 100 ms 16872 KB Output is correct
61 Correct 92 ms 16468 KB Output is correct
62 Correct 96 ms 16556 KB Output is correct
63 Correct 98 ms 17488 KB Output is correct
64 Correct 88 ms 16552 KB Output is correct
65 Correct 85 ms 16468 KB Output is correct
66 Correct 33 ms 6736 KB Output is correct
67 Correct 110 ms 17488 KB Output is correct
68 Correct 42 ms 13404 KB Output is correct
69 Correct 37 ms 9044 KB Output is correct
70 Correct 80 ms 18000 KB Output is correct
71 Correct 1 ms 348 KB Output is correct
72 Correct 1 ms 348 KB Output is correct
73 Correct 0 ms 348 KB Output is correct
74 Correct 1 ms 348 KB Output is correct
75 Correct 0 ms 348 KB Output is correct
76 Correct 0 ms 348 KB Output is correct
77 Correct 4 ms 6584 KB Output is correct
78 Correct 4 ms 6492 KB Output is correct
79 Correct 4 ms 6492 KB Output is correct
80 Correct 4 ms 6492 KB Output is correct
81 Correct 45 ms 13248 KB Output is correct
82 Correct 73 ms 18004 KB Output is correct
83 Correct 84 ms 18508 KB Output is correct
84 Correct 115 ms 22324 KB Output is correct
85 Correct 109 ms 21892 KB Output is correct
86 Correct 117 ms 24132 KB Output is correct
87 Correct 120 ms 24916 KB Output is correct
88 Correct 0 ms 348 KB Output is correct
89 Correct 129 ms 25048 KB Output is correct
90 Correct 105 ms 23380 KB Output is correct
91 Correct 103 ms 22864 KB Output is correct