Submission #751686

# Submission time Handle Problem Language Result Execution time Memory
751686 2023-06-01T08:06:44 Z He_Huanglu Catfish Farm (IOI22_fish) C++17
100 / 100
386 ms 40608 KB
#include <bits/stdc++.h>
#define ii pair<int, int>
#define fi first
#define se second
using namespace std;

const int N = 1e5 + 5;
long long f[3][2][2], g[3][2][2], res;
ii p[3][2][2], t[3][3];
vector <long long> col[N], pref[N], _h[N];

ii check(int i, int j, int k) {
    ii ret = t[0][i];
    if(!ret.fi) ret.fi = t[1][j].fi;
    else if(ret.fi == 2 && j) return {1e9, 1e9};
    if(!ret.se) ret.se = t[2][k].se;
    else if(ret.se == 1 && k) return {1e9, 1e9};
    return ret;
}

long long cal(int c, int h) {
    if(c < 0 || col[c].empty()) return 0;
    int it = lower_bound(_h[c].begin(), _h[c].end(), h) - _h[c].begin();
    return pref[c][it];
}

long long max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) {
    t[0][2] = {1, 2};
    t[0][0].fi = 2; t[0][1].se = 1;
    t[1][1].fi = 1; t[2][1].se = 2;
    for(int i = 0; i < m; i++) col[x[i]].push_back(i);
    for(int c = 0; c < n; c++) {
        col[c].push_back(m);
        y.push_back(n), w.push_back(0);
        m++;
        sort(col[c].begin(), col[c].end(), [&] (int i, int j) {
            return y[i] < y[j];
        });
        pref[c].push_back(0);
        for(int i : col[c]) {
            pref[c].push_back(pref[c].back() + w[i]);
            _h[c].push_back(y[i]);
        }
    }
    for(int x1 = 0; x1 < 3; x1++) for(int x2 = 0; x2 < 2; x2++) for(int x3 = 0; x3 < 2; x3++)
        p[x1][x2][x3] = check(x1, x2, x3);
    for(int c = 0; c < n; c++) {
        for(int i : col[c]) {
            long long v1 = cal(c - 1, y[i]), v2 = cal(c, y[i]), v3 = cal(c + 1, y[i]);
            for(int x1 = 0; x1 < 3; x1++) for(int x2 = 0; x2 < 2; x2++) for(int x3 = 0; x3 < 2; x3++) {
                long long v = v1 * x2 + v3 * x3 - v2 * (x1 < 2);
                for(int y1 = 0; y1 < 3; y1++) for(int y2 = 0; y2 < 2; y2++) for(int y3 = 0; y3 < 2; y3++) {
                    if(p[x1][x2][x3].fi == 1e9 || p[y1][y2][y3].se == 1e9) continue;
                    if(p[x1][x2][x3].fi && p[x1][x2][x3].fi != p[y1][y2][y3].se) continue ;
                    if(x2 != (y1 % 2))continue ;
                    if((y3 == 1 && x1 != 0) || (y3 == 0 && x1 == 0)) continue;
                    f[x1][x2][x3] = max(f[x1][x2][x3], g[y1][y2][y3] + v);
                }
            }
        }
        for(int x1 = 0; x1 < 3; x1++) for(int x2 = 0; x2 < 2; x2++) for(int x3 = 0; x3 < 2; x3++)
            g[x1][x2][x3] = f[x1][x2][x3],
            f[x1][x2][x3] = 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, g[x1][x2][x3]);
    return res;
}

//main () {
//    cin.tie(0)->sync_with_stdio(0);
//    if(fopen("task.inp", "r")) {
//        freopen("task.inp", "r", stdin);
//        freopen("wa.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) << "\n";
//}
# Verdict Execution time Memory Grader output
1 Correct 126 ms 20616 KB Output is correct
2 Correct 160 ms 23976 KB Output is correct
3 Correct 74 ms 17476 KB Output is correct
4 Correct 69 ms 17468 KB Output is correct
5 Correct 331 ms 39312 KB Output is correct
6 Correct 374 ms 40608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 204 ms 26948 KB Output is correct
3 Correct 267 ms 30492 KB Output is correct
4 Correct 130 ms 21632 KB Output is correct
5 Correct 165 ms 24024 KB Output is correct
6 Correct 4 ms 7252 KB Output is correct
7 Correct 5 ms 7252 KB Output is correct
8 Correct 4 ms 7348 KB Output is correct
9 Correct 4 ms 7252 KB Output is correct
10 Correct 66 ms 17516 KB Output is correct
11 Correct 63 ms 17476 KB Output is correct
12 Correct 123 ms 21748 KB Output is correct
13 Correct 147 ms 23884 KB Output is correct
14 Correct 130 ms 22012 KB Output is correct
15 Correct 167 ms 23776 KB Output is correct
16 Correct 174 ms 22112 KB Output is correct
17 Correct 143 ms 23676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 17444 KB Output is correct
2 Correct 70 ms 17436 KB Output is correct
3 Correct 109 ms 19504 KB Output is correct
4 Correct 101 ms 19552 KB Output is correct
5 Correct 171 ms 23076 KB Output is correct
6 Correct 162 ms 22404 KB Output is correct
7 Correct 162 ms 22956 KB Output is correct
8 Correct 164 ms 23100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7340 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 4 ms 7352 KB Output is correct
5 Correct 4 ms 7240 KB Output is correct
6 Correct 4 ms 7348 KB Output is correct
7 Correct 4 ms 7344 KB Output is correct
8 Correct 4 ms 7244 KB Output is correct
9 Correct 5 ms 7352 KB Output is correct
10 Correct 7 ms 7508 KB Output is correct
11 Correct 5 ms 7380 KB Output is correct
12 Correct 5 ms 7360 KB Output is correct
13 Correct 4 ms 7252 KB Output is correct
14 Correct 5 ms 7380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7340 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 4 ms 7352 KB Output is correct
5 Correct 4 ms 7240 KB Output is correct
6 Correct 4 ms 7348 KB Output is correct
7 Correct 4 ms 7344 KB Output is correct
8 Correct 4 ms 7244 KB Output is correct
9 Correct 5 ms 7352 KB Output is correct
10 Correct 7 ms 7508 KB Output is correct
11 Correct 5 ms 7380 KB Output is correct
12 Correct 5 ms 7360 KB Output is correct
13 Correct 4 ms 7252 KB Output is correct
14 Correct 5 ms 7380 KB Output is correct
15 Correct 4 ms 7380 KB Output is correct
16 Correct 6 ms 7508 KB Output is correct
17 Correct 46 ms 10568 KB Output is correct
18 Correct 43 ms 11232 KB Output is correct
19 Correct 47 ms 10996 KB Output is correct
20 Correct 45 ms 11104 KB Output is correct
21 Correct 41 ms 10976 KB Output is correct
22 Correct 79 ms 14788 KB Output is correct
23 Correct 12 ms 8020 KB Output is correct
24 Correct 31 ms 9476 KB Output is correct
25 Correct 6 ms 7364 KB Output is correct
26 Correct 11 ms 7892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7340 KB Output is correct
3 Correct 4 ms 7252 KB Output is correct
4 Correct 4 ms 7352 KB Output is correct
5 Correct 4 ms 7240 KB Output is correct
6 Correct 4 ms 7348 KB Output is correct
7 Correct 4 ms 7344 KB Output is correct
8 Correct 4 ms 7244 KB Output is correct
9 Correct 5 ms 7352 KB Output is correct
10 Correct 7 ms 7508 KB Output is correct
11 Correct 5 ms 7380 KB Output is correct
12 Correct 5 ms 7360 KB Output is correct
13 Correct 4 ms 7252 KB Output is correct
14 Correct 5 ms 7380 KB Output is correct
15 Correct 4 ms 7380 KB Output is correct
16 Correct 6 ms 7508 KB Output is correct
17 Correct 46 ms 10568 KB Output is correct
18 Correct 43 ms 11232 KB Output is correct
19 Correct 47 ms 10996 KB Output is correct
20 Correct 45 ms 11104 KB Output is correct
21 Correct 41 ms 10976 KB Output is correct
22 Correct 79 ms 14788 KB Output is correct
23 Correct 12 ms 8020 KB Output is correct
24 Correct 31 ms 9476 KB Output is correct
25 Correct 6 ms 7364 KB Output is correct
26 Correct 11 ms 7892 KB Output is correct
27 Correct 8 ms 7744 KB Output is correct
28 Correct 201 ms 25228 KB Output is correct
29 Correct 291 ms 29612 KB Output is correct
30 Correct 285 ms 29524 KB Output is correct
31 Correct 276 ms 29740 KB Output is correct
32 Correct 262 ms 33168 KB Output is correct
33 Correct 273 ms 29504 KB Output is correct
34 Correct 285 ms 29508 KB Output is correct
35 Correct 118 ms 16468 KB Output is correct
36 Correct 290 ms 31384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 17444 KB Output is correct
2 Correct 70 ms 17436 KB Output is correct
3 Correct 109 ms 19504 KB Output is correct
4 Correct 101 ms 19552 KB Output is correct
5 Correct 171 ms 23076 KB Output is correct
6 Correct 162 ms 22404 KB Output is correct
7 Correct 162 ms 22956 KB Output is correct
8 Correct 164 ms 23100 KB Output is correct
9 Correct 162 ms 23492 KB Output is correct
10 Correct 130 ms 19260 KB Output is correct
11 Correct 247 ms 31316 KB Output is correct
12 Correct 4 ms 7252 KB Output is correct
13 Correct 5 ms 7252 KB Output is correct
14 Correct 4 ms 7352 KB Output is correct
15 Correct 4 ms 7252 KB Output is correct
16 Correct 4 ms 7348 KB Output is correct
17 Correct 5 ms 7252 KB Output is correct
18 Correct 69 ms 17468 KB Output is correct
19 Correct 65 ms 17404 KB Output is correct
20 Correct 70 ms 17476 KB Output is correct
21 Correct 76 ms 17440 KB Output is correct
22 Correct 172 ms 24788 KB Output is correct
23 Correct 261 ms 31348 KB Output is correct
24 Correct 335 ms 31788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 126 ms 20616 KB Output is correct
2 Correct 160 ms 23976 KB Output is correct
3 Correct 74 ms 17476 KB Output is correct
4 Correct 69 ms 17468 KB Output is correct
5 Correct 331 ms 39312 KB Output is correct
6 Correct 374 ms 40608 KB Output is correct
7 Correct 4 ms 7252 KB Output is correct
8 Correct 204 ms 26948 KB Output is correct
9 Correct 267 ms 30492 KB Output is correct
10 Correct 130 ms 21632 KB Output is correct
11 Correct 165 ms 24024 KB Output is correct
12 Correct 4 ms 7252 KB Output is correct
13 Correct 5 ms 7252 KB Output is correct
14 Correct 4 ms 7348 KB Output is correct
15 Correct 4 ms 7252 KB Output is correct
16 Correct 66 ms 17516 KB Output is correct
17 Correct 63 ms 17476 KB Output is correct
18 Correct 123 ms 21748 KB Output is correct
19 Correct 147 ms 23884 KB Output is correct
20 Correct 130 ms 22012 KB Output is correct
21 Correct 167 ms 23776 KB Output is correct
22 Correct 174 ms 22112 KB Output is correct
23 Correct 143 ms 23676 KB Output is correct
24 Correct 67 ms 17444 KB Output is correct
25 Correct 70 ms 17436 KB Output is correct
26 Correct 109 ms 19504 KB Output is correct
27 Correct 101 ms 19552 KB Output is correct
28 Correct 171 ms 23076 KB Output is correct
29 Correct 162 ms 22404 KB Output is correct
30 Correct 162 ms 22956 KB Output is correct
31 Correct 164 ms 23100 KB Output is correct
32 Correct 4 ms 7252 KB Output is correct
33 Correct 4 ms 7340 KB Output is correct
34 Correct 4 ms 7252 KB Output is correct
35 Correct 4 ms 7352 KB Output is correct
36 Correct 4 ms 7240 KB Output is correct
37 Correct 4 ms 7348 KB Output is correct
38 Correct 4 ms 7344 KB Output is correct
39 Correct 4 ms 7244 KB Output is correct
40 Correct 5 ms 7352 KB Output is correct
41 Correct 7 ms 7508 KB Output is correct
42 Correct 5 ms 7380 KB Output is correct
43 Correct 5 ms 7360 KB Output is correct
44 Correct 4 ms 7252 KB Output is correct
45 Correct 5 ms 7380 KB Output is correct
46 Correct 4 ms 7380 KB Output is correct
47 Correct 6 ms 7508 KB Output is correct
48 Correct 46 ms 10568 KB Output is correct
49 Correct 43 ms 11232 KB Output is correct
50 Correct 47 ms 10996 KB Output is correct
51 Correct 45 ms 11104 KB Output is correct
52 Correct 41 ms 10976 KB Output is correct
53 Correct 79 ms 14788 KB Output is correct
54 Correct 12 ms 8020 KB Output is correct
55 Correct 31 ms 9476 KB Output is correct
56 Correct 6 ms 7364 KB Output is correct
57 Correct 11 ms 7892 KB Output is correct
58 Correct 8 ms 7744 KB Output is correct
59 Correct 201 ms 25228 KB Output is correct
60 Correct 291 ms 29612 KB Output is correct
61 Correct 285 ms 29524 KB Output is correct
62 Correct 276 ms 29740 KB Output is correct
63 Correct 262 ms 33168 KB Output is correct
64 Correct 273 ms 29504 KB Output is correct
65 Correct 285 ms 29508 KB Output is correct
66 Correct 118 ms 16468 KB Output is correct
67 Correct 290 ms 31384 KB Output is correct
68 Correct 162 ms 23492 KB Output is correct
69 Correct 130 ms 19260 KB Output is correct
70 Correct 247 ms 31316 KB Output is correct
71 Correct 4 ms 7252 KB Output is correct
72 Correct 5 ms 7252 KB Output is correct
73 Correct 4 ms 7352 KB Output is correct
74 Correct 4 ms 7252 KB Output is correct
75 Correct 4 ms 7348 KB Output is correct
76 Correct 5 ms 7252 KB Output is correct
77 Correct 69 ms 17468 KB Output is correct
78 Correct 65 ms 17404 KB Output is correct
79 Correct 70 ms 17476 KB Output is correct
80 Correct 76 ms 17440 KB Output is correct
81 Correct 172 ms 24788 KB Output is correct
82 Correct 261 ms 31348 KB Output is correct
83 Correct 335 ms 31788 KB Output is correct
84 Correct 349 ms 37636 KB Output is correct
85 Correct 349 ms 37580 KB Output is correct
86 Correct 386 ms 38568 KB Output is correct
87 Correct 385 ms 39472 KB Output is correct
88 Correct 4 ms 7348 KB Output is correct
89 Correct 376 ms 39348 KB Output is correct
90 Correct 362 ms 39204 KB Output is correct
91 Correct 375 ms 39680 KB Output is correct