Submission #746360

# Submission time Handle Problem Language Result Execution time Memory
746360 2023-05-22T11:50:53 Z nguyentunglam Catfish Farm (IOI22_fish) C++17
100 / 100
446 ms 30728 KB
#include<bits/stdc++.h>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
using namespace std;
const int N = 1e5 + 10;
int order[N * 3];
vector<int> fish[N];
vector<long long> pref[N];
long long f[3][2][2][2];

long long calc(int h, int col) {
    if (h == -1 || col < 0 || fish[col].empty()) return 0;
    int idx = --upper_bound(fish[col].begin(), fish[col].end(), h) - fish[col].begin();
    return pref[col][idx];
}

long long max_weights(int n, int m, vector<int> X, vector<int> Y, vector<int> W) {

    for(int i = 0; i < n; i++) fish[i].push_back(0), pref[i].push_back(0);

    for(int i = 0; i < m; i++) order[i] = i;
    sort(order, order + m, [&] (const int &A, const int &B) {
         return Y[A] < Y[B];
         });

    for(int cur = 0; cur < m; cur++) {
        int i = order[cur];
        fish[X[i]].push_back(Y[i]);
        pref[X[i]].push_back(pref[X[i]].back() + W[i]);
    }

    for(int i = 0; i < n; i++) fish[i].push_back(n + 1);

    bool pre = 0;
    memset(f, -61, sizeof(f));
    f[0][0][0][0] = 0;
    for(int i = 0; i < n; i++) {
        bool cur = pre ^ 1;
        for(int &preh : fish[i]) {
            int h = preh - 1;
            long long g1 = calc(h, i - 1), g2 = calc(h, i), g3 = calc(h, i + 1);
            for(int x1 = 0; x1 < 3; x1++) for(int x2 = 0; x2 < 2; x2++) for(int x3 = 0; x3 < 2; x3++) {
                for(int y1 = 0; y1 < 3; y1++) for(int y2 = 0; y2 < 2; y2++) for(int y3 = 0; y3 < 2; y3++) {
                    bool ok = 1;
                    if (x2) ok &= y1 == 2;
                    if (y3) ok &= x1 == 1;

                    if (ok) {
                        f[x1][x2][x3][cur] = max(f[x1][x2][x3][cur], f[y1][y2][y3][pre] + x2 * g1 + x3 * g3 - (x1 > 0) * g2);
                    }
                }
            }
        }
        for(int x1 = 0; x1 < 3; x1++) for(int x2 = 0; x2 < 2; x2++) for(int x3 = 0; x3 < 2; x3++) f[x1][x2][x3][pre] = -1e18;
        pre = cur;
    }
    long long res = 0;
    for(int x1 = 0; x1 < 3; x1++) for(int x2 = 0; x2 < 2; x2++) for(int x3 = 0; x3 < 2; x3++) {
        res = max(res, f[x1][x2][x3][pre]);
    }
    return res;
}

#ifdef ngu
main() {

    freopen ("task.inp", "r", stdin);
    freopen ("task.out", "w", stdout);

    int n, m; cin >> n >> m;
    vector<int> x(m), y(m), w(m);
    for(int i = 0; i < m; i++) cin >> x[i] >> y[i] >> w[i];
    cout <<  max_weights(n, m, x, y, w);
}
#endif // ngu
# Verdict Execution time Memory Grader output
1 Correct 109 ms 14248 KB Output is correct
2 Correct 130 ms 15404 KB Output is correct
3 Correct 67 ms 11244 KB Output is correct
4 Correct 78 ms 11248 KB Output is correct
5 Correct 286 ms 23696 KB Output is correct
6 Correct 368 ms 26544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 181 ms 17644 KB Output is correct
3 Correct 264 ms 19240 KB Output is correct
4 Correct 142 ms 14400 KB Output is correct
5 Correct 149 ms 15528 KB Output is correct
6 Correct 4 ms 4996 KB Output is correct
7 Correct 4 ms 5056 KB Output is correct
8 Correct 4 ms 4948 KB Output is correct
9 Correct 4 ms 4948 KB Output is correct
10 Correct 61 ms 11244 KB Output is correct
11 Correct 67 ms 11244 KB Output is correct
12 Correct 113 ms 14440 KB Output is correct
13 Correct 135 ms 15772 KB Output is correct
14 Correct 136 ms 14480 KB Output is correct
15 Correct 149 ms 15248 KB Output is correct
16 Correct 116 ms 14508 KB Output is correct
17 Correct 131 ms 15508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 92 ms 11244 KB Output is correct
2 Correct 96 ms 11252 KB Output is correct
3 Correct 140 ms 12108 KB Output is correct
4 Correct 96 ms 12388 KB Output is correct
5 Correct 151 ms 14132 KB Output is correct
6 Correct 156 ms 14108 KB Output is correct
7 Correct 185 ms 14136 KB Output is correct
8 Correct 167 ms 14128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 4 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 4 ms 4948 KB Output is correct
10 Correct 5 ms 5148 KB Output is correct
11 Correct 4 ms 4948 KB Output is correct
12 Correct 4 ms 5076 KB Output is correct
13 Correct 3 ms 5004 KB Output is correct
14 Correct 4 ms 5076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 4 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 4 ms 4948 KB Output is correct
10 Correct 5 ms 5148 KB Output is correct
11 Correct 4 ms 4948 KB Output is correct
12 Correct 4 ms 5076 KB Output is correct
13 Correct 3 ms 5004 KB Output is correct
14 Correct 4 ms 5076 KB Output is correct
15 Correct 3 ms 4960 KB Output is correct
16 Correct 5 ms 5140 KB Output is correct
17 Correct 42 ms 7020 KB Output is correct
18 Correct 39 ms 7396 KB Output is correct
19 Correct 34 ms 7332 KB Output is correct
20 Correct 33 ms 7244 KB Output is correct
21 Correct 33 ms 7344 KB Output is correct
22 Correct 69 ms 9540 KB Output is correct
23 Correct 10 ms 5524 KB Output is correct
24 Correct 26 ms 6412 KB Output is correct
25 Correct 4 ms 5016 KB Output is correct
26 Correct 9 ms 5528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4948 KB Output is correct
6 Correct 4 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 3 ms 4948 KB Output is correct
9 Correct 4 ms 4948 KB Output is correct
10 Correct 5 ms 5148 KB Output is correct
11 Correct 4 ms 4948 KB Output is correct
12 Correct 4 ms 5076 KB Output is correct
13 Correct 3 ms 5004 KB Output is correct
14 Correct 4 ms 5076 KB Output is correct
15 Correct 3 ms 4960 KB Output is correct
16 Correct 5 ms 5140 KB Output is correct
17 Correct 42 ms 7020 KB Output is correct
18 Correct 39 ms 7396 KB Output is correct
19 Correct 34 ms 7332 KB Output is correct
20 Correct 33 ms 7244 KB Output is correct
21 Correct 33 ms 7344 KB Output is correct
22 Correct 69 ms 9540 KB Output is correct
23 Correct 10 ms 5524 KB Output is correct
24 Correct 26 ms 6412 KB Output is correct
25 Correct 4 ms 5016 KB Output is correct
26 Correct 9 ms 5528 KB Output is correct
27 Correct 6 ms 5268 KB Output is correct
28 Correct 159 ms 15588 KB Output is correct
29 Correct 228 ms 18884 KB Output is correct
30 Correct 220 ms 23744 KB Output is correct
31 Correct 227 ms 23736 KB Output is correct
32 Correct 234 ms 25396 KB Output is correct
33 Correct 244 ms 23776 KB Output is correct
34 Correct 236 ms 23852 KB Output is correct
35 Correct 96 ms 12600 KB Output is correct
36 Correct 219 ms 25024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 92 ms 11244 KB Output is correct
2 Correct 96 ms 11252 KB Output is correct
3 Correct 140 ms 12108 KB Output is correct
4 Correct 96 ms 12388 KB Output is correct
5 Correct 151 ms 14132 KB Output is correct
6 Correct 156 ms 14108 KB Output is correct
7 Correct 185 ms 14136 KB Output is correct
8 Correct 167 ms 14128 KB Output is correct
9 Correct 127 ms 14132 KB Output is correct
10 Correct 123 ms 13388 KB Output is correct
11 Correct 263 ms 21564 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 5000 KB Output is correct
14 Correct 4 ms 4948 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Correct 3 ms 5000 KB Output is correct
18 Correct 62 ms 11248 KB Output is correct
19 Correct 62 ms 11244 KB Output is correct
20 Correct 86 ms 11244 KB Output is correct
21 Correct 64 ms 11248 KB Output is correct
22 Correct 182 ms 15756 KB Output is correct
23 Correct 284 ms 21556 KB Output is correct
24 Correct 236 ms 21448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 109 ms 14248 KB Output is correct
2 Correct 130 ms 15404 KB Output is correct
3 Correct 67 ms 11244 KB Output is correct
4 Correct 78 ms 11248 KB Output is correct
5 Correct 286 ms 23696 KB Output is correct
6 Correct 368 ms 26544 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 181 ms 17644 KB Output is correct
9 Correct 264 ms 19240 KB Output is correct
10 Correct 142 ms 14400 KB Output is correct
11 Correct 149 ms 15528 KB Output is correct
12 Correct 4 ms 4996 KB Output is correct
13 Correct 4 ms 5056 KB Output is correct
14 Correct 4 ms 4948 KB Output is correct
15 Correct 4 ms 4948 KB Output is correct
16 Correct 61 ms 11244 KB Output is correct
17 Correct 67 ms 11244 KB Output is correct
18 Correct 113 ms 14440 KB Output is correct
19 Correct 135 ms 15772 KB Output is correct
20 Correct 136 ms 14480 KB Output is correct
21 Correct 149 ms 15248 KB Output is correct
22 Correct 116 ms 14508 KB Output is correct
23 Correct 131 ms 15508 KB Output is correct
24 Correct 92 ms 11244 KB Output is correct
25 Correct 96 ms 11252 KB Output is correct
26 Correct 140 ms 12108 KB Output is correct
27 Correct 96 ms 12388 KB Output is correct
28 Correct 151 ms 14132 KB Output is correct
29 Correct 156 ms 14108 KB Output is correct
30 Correct 185 ms 14136 KB Output is correct
31 Correct 167 ms 14128 KB Output is correct
32 Correct 3 ms 4948 KB Output is correct
33 Correct 4 ms 4948 KB Output is correct
34 Correct 3 ms 4948 KB Output is correct
35 Correct 3 ms 4948 KB Output is correct
36 Correct 3 ms 4948 KB Output is correct
37 Correct 4 ms 4948 KB Output is correct
38 Correct 3 ms 4948 KB Output is correct
39 Correct 3 ms 4948 KB Output is correct
40 Correct 4 ms 4948 KB Output is correct
41 Correct 5 ms 5148 KB Output is correct
42 Correct 4 ms 4948 KB Output is correct
43 Correct 4 ms 5076 KB Output is correct
44 Correct 3 ms 5004 KB Output is correct
45 Correct 4 ms 5076 KB Output is correct
46 Correct 3 ms 4960 KB Output is correct
47 Correct 5 ms 5140 KB Output is correct
48 Correct 42 ms 7020 KB Output is correct
49 Correct 39 ms 7396 KB Output is correct
50 Correct 34 ms 7332 KB Output is correct
51 Correct 33 ms 7244 KB Output is correct
52 Correct 33 ms 7344 KB Output is correct
53 Correct 69 ms 9540 KB Output is correct
54 Correct 10 ms 5524 KB Output is correct
55 Correct 26 ms 6412 KB Output is correct
56 Correct 4 ms 5016 KB Output is correct
57 Correct 9 ms 5528 KB Output is correct
58 Correct 6 ms 5268 KB Output is correct
59 Correct 159 ms 15588 KB Output is correct
60 Correct 228 ms 18884 KB Output is correct
61 Correct 220 ms 23744 KB Output is correct
62 Correct 227 ms 23736 KB Output is correct
63 Correct 234 ms 25396 KB Output is correct
64 Correct 244 ms 23776 KB Output is correct
65 Correct 236 ms 23852 KB Output is correct
66 Correct 96 ms 12600 KB Output is correct
67 Correct 219 ms 25024 KB Output is correct
68 Correct 127 ms 14132 KB Output is correct
69 Correct 123 ms 13388 KB Output is correct
70 Correct 263 ms 21564 KB Output is correct
71 Correct 3 ms 4948 KB Output is correct
72 Correct 3 ms 5000 KB Output is correct
73 Correct 4 ms 4948 KB Output is correct
74 Correct 3 ms 4948 KB Output is correct
75 Correct 3 ms 4948 KB Output is correct
76 Correct 3 ms 5000 KB Output is correct
77 Correct 62 ms 11248 KB Output is correct
78 Correct 62 ms 11244 KB Output is correct
79 Correct 86 ms 11244 KB Output is correct
80 Correct 64 ms 11248 KB Output is correct
81 Correct 182 ms 15756 KB Output is correct
82 Correct 284 ms 21556 KB Output is correct
83 Correct 236 ms 21448 KB Output is correct
84 Correct 318 ms 29328 KB Output is correct
85 Correct 325 ms 29556 KB Output is correct
86 Correct 388 ms 29932 KB Output is correct
87 Correct 361 ms 30716 KB Output is correct
88 Correct 3 ms 4948 KB Output is correct
89 Correct 446 ms 30728 KB Output is correct
90 Correct 311 ms 30016 KB Output is correct
91 Correct 282 ms 30128 KB Output is correct