Submission #842620

# Submission time Handle Problem Language Result Execution time Memory
842620 2023-09-03T06:24:40 Z WLZ Catfish Farm (IOI22_fish) C++17
100 / 100
214 ms 76388 KB
#include <bits/stdc++.h>
using namespace std;

const long long INF = (long long) 1e18;

long long max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
    vector< vector< pair<int, long long> > > x(N + 1);
    for (int i = 0; i < M; i++) {
        x[X[i] + 1].push_back({Y[i], W[i]});
    }
    for (int i = 0; i <= N; i++) {
        x[i].push_back({-1, 0});
        sort(x[i].begin(), x[i].end());
        for (int j = 1; j < (int) x[i].size(); j++) x[i][j].second += x[i][j - 1].second;
    }
    vector< vector<int> > pos(N + 1);
    pos[0] = {0};
    for (int i = 1; i <= N; i++) {
        for (auto &p : x[i - 1]) pos[i].push_back(p.first + 1);
        if (i < N) for (auto &p : x[i + 1]) pos[i].push_back(p.first + 1);
        sort(pos[i].begin(), pos[i].end());
        pos[i].erase(unique(pos[i].begin(), pos[i].end()), pos[i].end());
    }
    vector< vector< vector<long long> > > dp(N + 1);
    dp[0] = {{0, 0}};
    for (int i = 1; i <= N; i++) {
        dp[i].assign((int) pos[i].size(), vector<long long>(2, -INF));
        int ptr_h = 0, ptr_k = 0, ptr_h_2 = 0;
        long long mx = -INF;
        for (int j = 0; j < (int) pos[i].size(); j++) {
            int h = pos[i][j];
            while (ptr_h < (int) pos[i - 1].size() && pos[i - 1][ptr_h] <= h) {
                while (ptr_k < (int) x[i - 1].size() && x[i - 1][ptr_k].first < pos[i - 1][ptr_h]) ptr_k++;
                mx = max(mx, dp[i - 1][ptr_h][0] - (ptr_k > 0 ? x[i - 1][ptr_k - 1].second : 0));
                ptr_h++;
            }
            while (ptr_h_2 < (int) x[i - 1].size() && x[i - 1][ptr_h_2].first < h) ptr_h_2++;
            dp[i][j][0] = max(mx + (ptr_h_2 > 0 ? x[i - 1][ptr_h_2 - 1].second : 0), dp[i - 1][0][1]);
        }
        ptr_h = (int) pos[i - 1].size() - 1, ptr_k = (int) x[i].size() - 1,
        ptr_h_2 = (int) x[i].size() - 1, mx = -INF;
        for (int j = (int) pos[i].size() - 1; j >= 0; j--) {
            int h = pos[i][j];
            while (ptr_h >= 0 && pos[i - 1][ptr_h] >= h) {
                while (ptr_k >= 0 && x[i][ptr_k].first >= pos[i - 1][ptr_h]) ptr_k--;
                mx = max(mx, dp[i - 1][ptr_h][0] + (ptr_k >= 0 ? x[i][ptr_k].second : 0));
                mx = max(mx, dp[i - 1][ptr_h][1] + (ptr_k >= 0 ? x[i][ptr_k].second : 0));
                ptr_h--;
            }
            while (ptr_h_2 >= 0 && x[i][ptr_h_2].first >= h) ptr_h_2--;
            dp[i][j][1] = mx - (ptr_h_2 >= 0 ? x[i][ptr_h_2].second : 0);
        }
    }
    long long ans = 0;
    for (int j = 0; j < (int) dp[N].size(); j++) ans = max({ans, dp[N][j][0], dp[N][j][1]});
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 75 ms 27176 KB Output is correct
2 Correct 72 ms 31428 KB Output is correct
3 Correct 29 ms 19796 KB Output is correct
4 Correct 30 ms 20016 KB Output is correct
5 Correct 184 ms 73276 KB Output is correct
6 Correct 210 ms 76388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 125 ms 41276 KB Output is correct
3 Correct 132 ms 48944 KB Output is correct
4 Correct 74 ms 27364 KB Output is correct
5 Correct 73 ms 31532 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 436 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 32 ms 19796 KB Output is correct
11 Correct 34 ms 19872 KB Output is correct
12 Correct 71 ms 32180 KB Output is correct
13 Correct 91 ms 37316 KB Output is correct
14 Correct 69 ms 29688 KB Output is correct
15 Correct 77 ms 32956 KB Output is correct
16 Correct 89 ms 29772 KB Output is correct
17 Correct 80 ms 32944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 20008 KB Output is correct
2 Correct 29 ms 19840 KB Output is correct
3 Correct 68 ms 24780 KB Output is correct
4 Correct 69 ms 24660 KB Output is correct
5 Correct 84 ms 32148 KB Output is correct
6 Correct 80 ms 31556 KB Output is correct
7 Correct 80 ms 32188 KB Output is correct
8 Correct 84 ms 32084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 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 856 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 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 856 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 21 ms 6536 KB Output is correct
18 Correct 19 ms 6916 KB Output is correct
19 Correct 18 ms 7004 KB Output is correct
20 Correct 20 ms 6580 KB Output is correct
21 Correct 17 ms 6492 KB Output is correct
22 Correct 36 ms 12628 KB Output is correct
23 Correct 5 ms 1884 KB Output is correct
24 Correct 17 ms 5152 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 5 ms 1884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 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 856 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 21 ms 6536 KB Output is correct
18 Correct 19 ms 6916 KB Output is correct
19 Correct 18 ms 7004 KB Output is correct
20 Correct 20 ms 6580 KB Output is correct
21 Correct 17 ms 6492 KB Output is correct
22 Correct 36 ms 12628 KB Output is correct
23 Correct 5 ms 1884 KB Output is correct
24 Correct 17 ms 5152 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 5 ms 1884 KB Output is correct
27 Correct 3 ms 1372 KB Output is correct
28 Correct 95 ms 31572 KB Output is correct
29 Correct 150 ms 48616 KB Output is correct
30 Correct 159 ms 54492 KB Output is correct
31 Correct 157 ms 54356 KB Output is correct
32 Correct 119 ms 41044 KB Output is correct
33 Correct 164 ms 55128 KB Output is correct
34 Correct 154 ms 54868 KB Output is correct
35 Correct 58 ms 20564 KB Output is correct
36 Correct 153 ms 54480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 20008 KB Output is correct
2 Correct 29 ms 19840 KB Output is correct
3 Correct 68 ms 24780 KB Output is correct
4 Correct 69 ms 24660 KB Output is correct
5 Correct 84 ms 32148 KB Output is correct
6 Correct 80 ms 31556 KB Output is correct
7 Correct 80 ms 32188 KB Output is correct
8 Correct 84 ms 32084 KB Output is correct
9 Correct 92 ms 37076 KB Output is correct
10 Correct 59 ms 23084 KB Output is correct
11 Correct 128 ms 45752 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 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 30 ms 19796 KB Output is correct
19 Correct 30 ms 19796 KB Output is correct
20 Correct 29 ms 19796 KB Output is correct
21 Correct 30 ms 19796 KB Output is correct
22 Correct 103 ms 38228 KB Output is correct
23 Correct 142 ms 53840 KB Output is correct
24 Correct 146 ms 56196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 27176 KB Output is correct
2 Correct 72 ms 31428 KB Output is correct
3 Correct 29 ms 19796 KB Output is correct
4 Correct 30 ms 20016 KB Output is correct
5 Correct 184 ms 73276 KB Output is correct
6 Correct 210 ms 76388 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 125 ms 41276 KB Output is correct
9 Correct 132 ms 48944 KB Output is correct
10 Correct 74 ms 27364 KB Output is correct
11 Correct 73 ms 31532 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 1 ms 436 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 32 ms 19796 KB Output is correct
17 Correct 34 ms 19872 KB Output is correct
18 Correct 71 ms 32180 KB Output is correct
19 Correct 91 ms 37316 KB Output is correct
20 Correct 69 ms 29688 KB Output is correct
21 Correct 77 ms 32956 KB Output is correct
22 Correct 89 ms 29772 KB Output is correct
23 Correct 80 ms 32944 KB Output is correct
24 Correct 32 ms 20008 KB Output is correct
25 Correct 29 ms 19840 KB Output is correct
26 Correct 68 ms 24780 KB Output is correct
27 Correct 69 ms 24660 KB Output is correct
28 Correct 84 ms 32148 KB Output is correct
29 Correct 80 ms 31556 KB Output is correct
30 Correct 80 ms 32188 KB Output is correct
31 Correct 84 ms 32084 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 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 856 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 604 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 21 ms 6536 KB Output is correct
49 Correct 19 ms 6916 KB Output is correct
50 Correct 18 ms 7004 KB Output is correct
51 Correct 20 ms 6580 KB Output is correct
52 Correct 17 ms 6492 KB Output is correct
53 Correct 36 ms 12628 KB Output is correct
54 Correct 5 ms 1884 KB Output is correct
55 Correct 17 ms 5152 KB Output is correct
56 Correct 1 ms 604 KB Output is correct
57 Correct 5 ms 1884 KB Output is correct
58 Correct 3 ms 1372 KB Output is correct
59 Correct 95 ms 31572 KB Output is correct
60 Correct 150 ms 48616 KB Output is correct
61 Correct 159 ms 54492 KB Output is correct
62 Correct 157 ms 54356 KB Output is correct
63 Correct 119 ms 41044 KB Output is correct
64 Correct 164 ms 55128 KB Output is correct
65 Correct 154 ms 54868 KB Output is correct
66 Correct 58 ms 20564 KB Output is correct
67 Correct 153 ms 54480 KB Output is correct
68 Correct 92 ms 37076 KB Output is correct
69 Correct 59 ms 23084 KB Output is correct
70 Correct 128 ms 45752 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 0 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 0 ms 348 KB Output is correct
77 Correct 30 ms 19796 KB Output is correct
78 Correct 30 ms 19796 KB Output is correct
79 Correct 29 ms 19796 KB Output is correct
80 Correct 30 ms 19796 KB Output is correct
81 Correct 103 ms 38228 KB Output is correct
82 Correct 142 ms 53840 KB Output is correct
83 Correct 146 ms 56196 KB Output is correct
84 Correct 199 ms 69592 KB Output is correct
85 Correct 195 ms 70764 KB Output is correct
86 Correct 204 ms 73420 KB Output is correct
87 Correct 213 ms 75844 KB Output is correct
88 Correct 0 ms 348 KB Output is correct
89 Correct 214 ms 75604 KB Output is correct
90 Correct 205 ms 70228 KB Output is correct
91 Correct 173 ms 62808 KB Output is correct