Submission #741868

# Submission time Handle Problem Language Result Execution time Memory
741868 2023-05-15T02:44:41 Z fanwen Catfish Farm (IOI22_fish) C++17
100 / 100
204 ms 44620 KB
#include <bits/stdc++.h>

using namespace std;

#define MASK(x) (1LL << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(x) (x).begin(), (x).end()

#define REP(i, n) for (int i = 0, _n = n; i < _n; ++i)
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define FORE(it, s) for (__typeof(s.begin()) it = (s).begin(); it != (s).end(); ++it)

template <class U, class V> bool maximize(U &A, const V &B) { return (A < B) ? (A = B, true) : false; }
template <class U, class V> bool minimize(U &A, const V &B) { return (A > B) ? (A = B, true) : false; }

long long max_weights(int numCol, int numCatfish, vector <int> cols, vector <int> rows, vector <int> weights) {
    vector <vector <pair <int, long long>>> atCol(numCol);
    REP(i, numCatfish) {
        atCol[cols[i]].push_back(make_pair(rows[i], weights[i]));
    }
    REP(i, numCol) {

        sort(ALL(atCol[i]));
        atCol[i].emplace_back(numCol, 0);
        long long pre = 0;
        for (auto &[_, x] : atCol[i]) {
            x += pre;
            pre = x;
        }
    }
    auto prefix_sum = [&] (int i, int cur) -> long long {
        assert(0 <= i && i < numCol);
        auto it = lower_bound(ALL(atCol[i]), make_pair(cur, -1ll));
        if(it != atCol[i].begin()) return prev(it) -> second;
        return 0;
    };
    vector <vector <vector <long long>>> dp(numCol, vector <vector <long long>>(2));
    REP(i, numCol) {
        dp[i][0].resize((int) atCol[i].size(), 0);
        dp[i][1].resize((int) atCol[i].size(), 0);
        long long Max = 0;
        if(i == 0) continue;
        for (int cur = (int) atCol[i].size() - 1, pre = (int) atCol[i - 1].size(); cur >= 0; cur--) {
            while(pre > 0 && atCol[i - 1][pre - 1].first >= atCol[i][cur].first) {
                pre--;
                maximize(Max, max(dp[i - 1][0][pre], dp[i - 1][1][pre]) + prefix_sum(i, atCol[i - 1][pre].first));
            }
            maximize(dp[i][0][cur], Max - prefix_sum(i, atCol[i][cur].first));
            // cout << i << " 0 " << atCol[i][cur].first << " " << Max << '\n';
        }
        Max = (i > 1 ? max(*max_element(ALL(dp[i - 2][0])), *max_element(ALL(dp[i - 2][1]))) : 0);
        for (int cur = 0, pre = -1; cur < (int) atCol[i].size(); ++cur) {
            while(pre + 1 < (int) atCol[i - 1].size() && atCol[i - 1][pre + 1].first <= atCol[i][cur].first) {
                pre++;
                maximize(Max, dp[i - 1][1][pre] - prefix_sum(i - 1, atCol[i - 1][pre].first));
            }
            // cout << cur << '\n';
            maximize(dp[i][1][cur], Max + prefix_sum(i - 1, atCol[i][cur].first));
            // cout << i << " 0 " << atCol[i][cur].first << " " << dp[i][1][cur] << '\n';
        }
    }

    return max(*max_element(ALL(dp[numCol - 1][0])), *max_element(ALL(dp[numCol - 1][1])));
}
# Verdict Execution time Memory Grader output
1 Correct 65 ms 23328 KB Output is correct
2 Correct 91 ms 27752 KB Output is correct
3 Correct 32 ms 20580 KB Output is correct
4 Correct 32 ms 20584 KB Output is correct
5 Correct 199 ms 43452 KB Output is correct
6 Correct 187 ms 44620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 108 ms 27448 KB Output is correct
3 Correct 141 ms 35104 KB Output is correct
4 Correct 61 ms 24380 KB Output is correct
5 Correct 73 ms 27812 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 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 30 ms 20580 KB Output is correct
11 Correct 30 ms 20528 KB Output is correct
12 Correct 69 ms 24544 KB Output is correct
13 Correct 80 ms 27768 KB Output is correct
14 Correct 66 ms 24488 KB Output is correct
15 Correct 75 ms 27080 KB Output is correct
16 Correct 64 ms 24492 KB Output is correct
17 Correct 75 ms 27052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 20564 KB Output is correct
2 Correct 30 ms 20616 KB Output is correct
3 Correct 53 ms 21072 KB Output is correct
4 Correct 52 ms 22732 KB Output is correct
5 Correct 99 ms 26700 KB Output is correct
6 Correct 76 ms 26052 KB Output is correct
7 Correct 83 ms 26592 KB Output is correct
8 Correct 82 ms 26676 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 1 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 340 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 1 ms 312 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 1 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 340 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 22 ms 3588 KB Output is correct
18 Correct 21 ms 4172 KB Output is correct
19 Correct 20 ms 4052 KB Output is correct
20 Correct 27 ms 4016 KB Output is correct
21 Correct 26 ms 4040 KB Output is correct
22 Correct 46 ms 7872 KB Output is correct
23 Correct 5 ms 980 KB Output is correct
24 Correct 16 ms 2560 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 4 ms 924 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 1 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 340 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 22 ms 3588 KB Output is correct
18 Correct 21 ms 4172 KB Output is correct
19 Correct 20 ms 4052 KB Output is correct
20 Correct 27 ms 4016 KB Output is correct
21 Correct 26 ms 4040 KB Output is correct
22 Correct 46 ms 7872 KB Output is correct
23 Correct 5 ms 980 KB Output is correct
24 Correct 16 ms 2560 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 4 ms 924 KB Output is correct
27 Correct 3 ms 980 KB Output is correct
28 Correct 108 ms 17844 KB Output is correct
29 Correct 179 ms 24864 KB Output is correct
30 Correct 145 ms 24208 KB Output is correct
31 Correct 146 ms 24164 KB Output is correct
32 Correct 156 ms 25292 KB Output is correct
33 Correct 149 ms 24420 KB Output is correct
34 Correct 153 ms 24268 KB Output is correct
35 Correct 57 ms 10076 KB Output is correct
36 Correct 155 ms 25624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 20564 KB Output is correct
2 Correct 30 ms 20616 KB Output is correct
3 Correct 53 ms 21072 KB Output is correct
4 Correct 52 ms 22732 KB Output is correct
5 Correct 99 ms 26700 KB Output is correct
6 Correct 76 ms 26052 KB Output is correct
7 Correct 83 ms 26592 KB Output is correct
8 Correct 82 ms 26676 KB Output is correct
9 Correct 86 ms 26416 KB Output is correct
10 Correct 62 ms 17144 KB Output is correct
11 Correct 139 ms 34156 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 1 ms 212 KB Output is correct
18 Correct 30 ms 20588 KB Output is correct
19 Correct 29 ms 20576 KB Output is correct
20 Correct 29 ms 20556 KB Output is correct
21 Correct 29 ms 20564 KB Output is correct
22 Correct 84 ms 27188 KB Output is correct
23 Correct 130 ms 34080 KB Output is correct
24 Correct 133 ms 34572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 23328 KB Output is correct
2 Correct 91 ms 27752 KB Output is correct
3 Correct 32 ms 20580 KB Output is correct
4 Correct 32 ms 20584 KB Output is correct
5 Correct 199 ms 43452 KB Output is correct
6 Correct 187 ms 44620 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 108 ms 27448 KB Output is correct
9 Correct 141 ms 35104 KB Output is correct
10 Correct 61 ms 24380 KB Output is correct
11 Correct 73 ms 27812 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 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 30 ms 20580 KB Output is correct
17 Correct 30 ms 20528 KB Output is correct
18 Correct 69 ms 24544 KB Output is correct
19 Correct 80 ms 27768 KB Output is correct
20 Correct 66 ms 24488 KB Output is correct
21 Correct 75 ms 27080 KB Output is correct
22 Correct 64 ms 24492 KB Output is correct
23 Correct 75 ms 27052 KB Output is correct
24 Correct 30 ms 20564 KB Output is correct
25 Correct 30 ms 20616 KB Output is correct
26 Correct 53 ms 21072 KB Output is correct
27 Correct 52 ms 22732 KB Output is correct
28 Correct 99 ms 26700 KB Output is correct
29 Correct 76 ms 26052 KB Output is correct
30 Correct 83 ms 26592 KB Output is correct
31 Correct 82 ms 26676 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 1 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 340 KB Output is correct
41 Correct 2 ms 468 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 328 KB Output is correct
44 Correct 1 ms 300 KB Output is correct
45 Correct 1 ms 312 KB Output is correct
46 Correct 1 ms 296 KB Output is correct
47 Correct 1 ms 468 KB Output is correct
48 Correct 22 ms 3588 KB Output is correct
49 Correct 21 ms 4172 KB Output is correct
50 Correct 20 ms 4052 KB Output is correct
51 Correct 27 ms 4016 KB Output is correct
52 Correct 26 ms 4040 KB Output is correct
53 Correct 46 ms 7872 KB Output is correct
54 Correct 5 ms 980 KB Output is correct
55 Correct 16 ms 2560 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 4 ms 924 KB Output is correct
58 Correct 3 ms 980 KB Output is correct
59 Correct 108 ms 17844 KB Output is correct
60 Correct 179 ms 24864 KB Output is correct
61 Correct 145 ms 24208 KB Output is correct
62 Correct 146 ms 24164 KB Output is correct
63 Correct 156 ms 25292 KB Output is correct
64 Correct 149 ms 24420 KB Output is correct
65 Correct 153 ms 24268 KB Output is correct
66 Correct 57 ms 10076 KB Output is correct
67 Correct 155 ms 25624 KB Output is correct
68 Correct 86 ms 26416 KB Output is correct
69 Correct 62 ms 17144 KB Output is correct
70 Correct 139 ms 34156 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 1 ms 212 KB Output is correct
77 Correct 30 ms 20588 KB Output is correct
78 Correct 29 ms 20576 KB Output is correct
79 Correct 29 ms 20556 KB Output is correct
80 Correct 29 ms 20564 KB Output is correct
81 Correct 84 ms 27188 KB Output is correct
82 Correct 130 ms 34080 KB Output is correct
83 Correct 133 ms 34572 KB Output is correct
84 Correct 196 ms 41256 KB Output is correct
85 Correct 204 ms 42748 KB Output is correct
86 Correct 195 ms 40900 KB Output is correct
87 Correct 203 ms 43136 KB Output is correct
88 Correct 1 ms 212 KB Output is correct
89 Correct 199 ms 42984 KB Output is correct
90 Correct 173 ms 43236 KB Output is correct
91 Correct 165 ms 43764 KB Output is correct