Submission #642054

# Submission time Handle Problem Language Result Execution time Memory
642054 2022-09-18T11:09:58 Z dykw Catfish Farm (IOI22_fish) C++17
100 / 100
139 ms 20420 KB
#include "fish.h"

#include <bits/stdc++.h>

using i64 = long long;

i64 max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {
	std::vector<std::vector<int>> pos(N);
    for (int i = 0; i < M; ++i) {
        pos[X[i]].push_back(i);
    }
    for (int i = 0; i < N; ++i) {
        std::sort(pos[i].begin(), pos[i].end(), [&](int lhs, int rhs) {
            return Y[lhs] < Y[rhs];
        });
    }
    auto chmax = [](i64 &x, i64 y) {
        x = std::max(x, y);
    };
    i64 ans = 0;
    std::vector<i64> f(M), g(M), max_f(N), max_g(N);
    for (int i = 0; i < N; ++i) {
        if (i > 0) {
            max_f[i] = max_g[i] = std::max(max_f[i - 1], max_g[i - 1]);
        }
        int len = pos[i].size(), len_1 = i > 0 ? pos[i - 1].size() : 0, p = 0;
        i64 val;
        if (i < N - 1) {
            val = i > 0 ? max_g[i - 1] : 0;
            if (i > 1) {
                chmax(val, max_f[i - 2]);
            }
            for (int j = 0; j < len; ++j) {
                if (j > 0) {
                    f[pos[i][j]] = f[pos[i][j - 1]] + W[pos[i][j]];
                }
                for (; p < len_1 && Y[pos[i - 1][p]] < Y[pos[i][j]]; ++p) {
                    chmax(val, f[pos[i - 1][p]]);
                }
                chmax(f[pos[i][j]], val + W[pos[i][j]]);
                chmax(max_f[i], f[pos[i][j]]);
                chmax(ans, f[pos[i][j]]);
            }
        }
        if (i > 0) {
            p = len_1 - 1, val = i > 1 ? max_f[i - 2] : 0;
            for (int j = len - 1; j >= 0; --j) {
                if (j < len - 1) {
                    g[pos[i][j]] = g[pos[i][j + 1]] + W[pos[i][j]];
                }
                for (; p >= 0 && Y[pos[i - 1][p]] > Y[pos[i][j]]; --p) {
                    chmax(val, g[pos[i - 1][p]]);
                }
                chmax(g[pos[i][j]], val + W[pos[i][j]]);
                chmax(max_g[i], g[pos[i][j]]);
                chmax(ans, g[pos[i][j]]);
            }
        }
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 38 ms 8244 KB Output is correct
2 Correct 40 ms 9304 KB Output is correct
3 Correct 3 ms 4180 KB Output is correct
4 Correct 3 ms 4180 KB Output is correct
5 Correct 128 ms 18100 KB Output is correct
6 Correct 130 ms 19468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 71 ms 12448 KB Output is correct
3 Correct 78 ms 13768 KB Output is correct
4 Correct 33 ms 8096 KB Output is correct
5 Correct 41 ms 9356 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 3 ms 4180 KB Output is correct
11 Correct 3 ms 4180 KB Output is correct
12 Correct 41 ms 8188 KB Output is correct
13 Correct 49 ms 9376 KB Output is correct
14 Correct 33 ms 8112 KB Output is correct
15 Correct 41 ms 9056 KB Output is correct
16 Correct 34 ms 8256 KB Output is correct
17 Correct 38 ms 9016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4180 KB Output is correct
2 Correct 3 ms 4180 KB Output is correct
3 Correct 26 ms 8320 KB Output is correct
4 Correct 18 ms 6832 KB Output is correct
5 Correct 44 ms 11284 KB Output is correct
6 Correct 42 ms 11856 KB Output is correct
7 Correct 55 ms 11980 KB Output is correct
8 Correct 47 ms 11936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 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 1 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 1 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 224 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 17 ms 2876 KB Output is correct
18 Correct 18 ms 2976 KB Output is correct
19 Correct 15 ms 3004 KB Output is correct
20 Correct 16 ms 3028 KB Output is correct
21 Correct 16 ms 2952 KB Output is correct
22 Correct 35 ms 5664 KB Output is correct
23 Correct 3 ms 680 KB Output is correct
24 Correct 11 ms 2004 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 3 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 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 224 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 17 ms 2876 KB Output is correct
18 Correct 18 ms 2976 KB Output is correct
19 Correct 15 ms 3004 KB Output is correct
20 Correct 16 ms 3028 KB Output is correct
21 Correct 16 ms 2952 KB Output is correct
22 Correct 35 ms 5664 KB Output is correct
23 Correct 3 ms 680 KB Output is correct
24 Correct 11 ms 2004 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 3 ms 724 KB Output is correct
27 Correct 2 ms 596 KB Output is correct
28 Correct 79 ms 11168 KB Output is correct
29 Correct 114 ms 15348 KB Output is correct
30 Correct 122 ms 15016 KB Output is correct
31 Correct 116 ms 14964 KB Output is correct
32 Correct 117 ms 15224 KB Output is correct
33 Correct 115 ms 14964 KB Output is correct
34 Correct 115 ms 14616 KB Output is correct
35 Correct 42 ms 6564 KB Output is correct
36 Correct 114 ms 15116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4180 KB Output is correct
2 Correct 3 ms 4180 KB Output is correct
3 Correct 26 ms 8320 KB Output is correct
4 Correct 18 ms 6832 KB Output is correct
5 Correct 44 ms 11284 KB Output is correct
6 Correct 42 ms 11856 KB Output is correct
7 Correct 55 ms 11980 KB Output is correct
8 Correct 47 ms 11936 KB Output is correct
9 Correct 44 ms 11856 KB Output is correct
10 Correct 50 ms 8448 KB Output is correct
11 Correct 86 ms 15880 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 3 ms 4180 KB Output is correct
19 Correct 4 ms 4176 KB Output is correct
20 Correct 3 ms 4144 KB Output is correct
21 Correct 3 ms 4180 KB Output is correct
22 Correct 52 ms 10952 KB Output is correct
23 Correct 92 ms 16056 KB Output is correct
24 Correct 93 ms 16284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 8244 KB Output is correct
2 Correct 40 ms 9304 KB Output is correct
3 Correct 3 ms 4180 KB Output is correct
4 Correct 3 ms 4180 KB Output is correct
5 Correct 128 ms 18100 KB Output is correct
6 Correct 130 ms 19468 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 71 ms 12448 KB Output is correct
9 Correct 78 ms 13768 KB Output is correct
10 Correct 33 ms 8096 KB Output is correct
11 Correct 41 ms 9356 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 3 ms 4180 KB Output is correct
17 Correct 3 ms 4180 KB Output is correct
18 Correct 41 ms 8188 KB Output is correct
19 Correct 49 ms 9376 KB Output is correct
20 Correct 33 ms 8112 KB Output is correct
21 Correct 41 ms 9056 KB Output is correct
22 Correct 34 ms 8256 KB Output is correct
23 Correct 38 ms 9016 KB Output is correct
24 Correct 3 ms 4180 KB Output is correct
25 Correct 3 ms 4180 KB Output is correct
26 Correct 26 ms 8320 KB Output is correct
27 Correct 18 ms 6832 KB Output is correct
28 Correct 44 ms 11284 KB Output is correct
29 Correct 42 ms 11856 KB Output is correct
30 Correct 55 ms 11980 KB Output is correct
31 Correct 47 ms 11936 KB Output is correct
32 Correct 1 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 1 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 224 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 17 ms 2876 KB Output is correct
49 Correct 18 ms 2976 KB Output is correct
50 Correct 15 ms 3004 KB Output is correct
51 Correct 16 ms 3028 KB Output is correct
52 Correct 16 ms 2952 KB Output is correct
53 Correct 35 ms 5664 KB Output is correct
54 Correct 3 ms 680 KB Output is correct
55 Correct 11 ms 2004 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 3 ms 724 KB Output is correct
58 Correct 2 ms 596 KB Output is correct
59 Correct 79 ms 11168 KB Output is correct
60 Correct 114 ms 15348 KB Output is correct
61 Correct 122 ms 15016 KB Output is correct
62 Correct 116 ms 14964 KB Output is correct
63 Correct 117 ms 15224 KB Output is correct
64 Correct 115 ms 14964 KB Output is correct
65 Correct 115 ms 14616 KB Output is correct
66 Correct 42 ms 6564 KB Output is correct
67 Correct 114 ms 15116 KB Output is correct
68 Correct 44 ms 11856 KB Output is correct
69 Correct 50 ms 8448 KB Output is correct
70 Correct 86 ms 15880 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 0 ms 212 KB Output is correct
73 Correct 1 ms 212 KB Output is correct
74 Correct 0 ms 212 KB Output is correct
75 Correct 0 ms 212 KB Output is correct
76 Correct 0 ms 212 KB Output is correct
77 Correct 3 ms 4180 KB Output is correct
78 Correct 4 ms 4176 KB Output is correct
79 Correct 3 ms 4144 KB Output is correct
80 Correct 3 ms 4180 KB Output is correct
81 Correct 52 ms 10952 KB Output is correct
82 Correct 92 ms 16056 KB Output is correct
83 Correct 93 ms 16284 KB Output is correct
84 Correct 129 ms 18536 KB Output is correct
85 Correct 130 ms 19072 KB Output is correct
86 Correct 135 ms 19884 KB Output is correct
87 Correct 139 ms 20420 KB Output is correct
88 Correct 0 ms 212 KB Output is correct
89 Correct 138 ms 20276 KB Output is correct
90 Correct 127 ms 19500 KB Output is correct
91 Correct 116 ms 18608 KB Output is correct