Submission #684671

# Submission time Handle Problem Language Result Execution time Memory
684671 2023-01-22T09:53:03 Z 79brue Catfish Farm (IOI22_fish) C++17
100 / 100
368 ms 40764 KB
#include "fish.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

struct segTree{
    ll tree[400002];

    void init(int i, int l, int r){
        tree[i] = -1e18;
        if(l==r) return;
        int m = (l+r)>>1;
        init(i*2, l, m);
        init(i*2+1, m+1, r);
    }

    void update(int i, int l, int r, int x, ll v){
        if(l==r){
            tree[i] = max(tree[i], v);
            return;
        }
        int m = (l+r)>>1;
        if(x<=m) update(i*2, l, m, x, v);
        else update(i*2+1, m+1, r, x, v);
        tree[i] = max(tree[i*2], tree[i*2+1]);
    }

    ll query(int i, int l, int r, int s, int e){
        if(r<s || e<l) return -1e18;
        if(s<=l && r<=e) return tree[i];
        int m = (l+r)>>1;
        return max(query(i*2, l, m, s, e), query(i*2+1, m+1, r, s, e));
    }
} treeL, treeR;

struct Point{
    int x, y;
    ll w;
    Point(){}
    Point(int x, int y, ll w): x(x), y(y), w(w){}
    bool operator<(const Point &r)const{
        if(x != r.x) return x < r.x;
        return y<r.y;
    }
};

int n, k;
ll DP[300002][2];
ll sum[100005];
vector<Point> vec[100005];
vector<Point> checkL[100005], checkR[100005];
ll ans;

ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W){
    n = N, k = M;
    for(int i=0; i<k; i++){
        vec[X[i]+1].push_back(Point(X[i]+1, Y[i]+1, W[i]));
        sum[X[i]+1] += W[i];
    }
    for(int i=0; i<=n; i++){
        sort(vec[i].begin(), vec[i].end());
        DP[i][0] = DP[i][1] = -1e18;
    }

    treeL.init(1, 0, n+1);
    treeR.init(1, 0, n+1);
    treeL.update(1, 0, n+1, 0, 0);

    for(int i=1; i<=n; i++){
        /// Checklist
        for(Point p: checkL[i]) treeL.update(1, 0, n+1, 0, p.w);
        for(Point p: checkR[i]) treeR.update(1, 0, n+1, n+1, p.w);

        /// DP[?][0] -> DP[i][1]
        {
            for(Point p: vec[i-1]){ /// max 계산
                treeL.update(1, 0, n+1, p.y, treeL.query(1, 0, n+1, 0, p.y-1) + p.w);
            }
            ll v = treeL.query(1, 0, n+1, 0, n+1);
            DP[i][1] = max(DP[i][1], v);
        }

        /// DP[?][1] -> DP[i][1] (with gap)
        if(i >= 3){
            ll v = DP[i-2][1] + sum[i-1];
            DP[i][1] = max(DP[i][1], v);
        }

        /// DP[?][1] -> DP[i][1] (with no gap)
        if(i >= 2){
            ll v = DP[i-1][1];
            DP[i][1] = max(DP[i][1], v);
        }

        /// DP[?][1] -> DP[i][0]
        {
            reverse(vec[i].begin(), vec[i].end());
            for(Point p: vec[i]){
                treeR.update(1, 0, n+1, p.y, treeR.query(1, 0, n+1, p.y+1, n+1) + p.w);
            }
            reverse(vec[i].begin(), vec[i].end());
            ll v = treeR.query(1, 0, n+1, 0, n+1);
            DP[i][0] = max(DP[i][0], v);
        }

        checkR[i+1].push_back(Point(i+1, n+1, DP[i][1]));
        checkL[i+2].push_back(Point(i+2, 0, DP[i][0]));
        ans = max({ans, DP[i][0], DP[i][1]});

//        printf("%d: %lld %lld\n", i, DP[i][0], DP[i][1]);
    }

    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 76 ms 23088 KB Output is correct
2 Correct 92 ms 24872 KB Output is correct
3 Correct 26 ms 19228 KB Output is correct
4 Correct 29 ms 19184 KB Output is correct
5 Correct 241 ms 36076 KB Output is correct
6 Correct 329 ms 39576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 131 ms 27632 KB Output is correct
3 Correct 159 ms 30520 KB Output is correct
4 Correct 79 ms 22972 KB Output is correct
5 Correct 92 ms 24848 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 4 ms 7356 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 4 ms 7252 KB Output is correct
10 Correct 27 ms 19280 KB Output is correct
11 Correct 27 ms 19180 KB Output is correct
12 Correct 87 ms 23040 KB Output is correct
13 Correct 91 ms 24884 KB Output is correct
14 Correct 78 ms 23004 KB Output is correct
15 Correct 87 ms 24384 KB Output is correct
16 Correct 80 ms 23056 KB Output is correct
17 Correct 89 ms 24380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 19256 KB Output is correct
2 Correct 28 ms 19232 KB Output is correct
3 Correct 59 ms 23072 KB Output is correct
4 Correct 49 ms 22348 KB Output is correct
5 Correct 89 ms 27080 KB Output is correct
6 Correct 98 ms 26524 KB Output is correct
7 Correct 90 ms 27084 KB Output is correct
8 Correct 87 ms 27088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 5 ms 7360 KB Output is correct
4 Correct 4 ms 7352 KB Output is correct
5 Correct 5 ms 7252 KB Output is correct
6 Correct 5 ms 7380 KB Output is correct
7 Correct 4 ms 7356 KB Output is correct
8 Correct 4 ms 7252 KB Output is correct
9 Correct 5 ms 7360 KB Output is correct
10 Correct 5 ms 7496 KB Output is correct
11 Correct 5 ms 7380 KB Output is correct
12 Correct 4 ms 7380 KB Output is correct
13 Correct 4 ms 7312 KB Output is correct
14 Correct 5 ms 7380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 5 ms 7360 KB Output is correct
4 Correct 4 ms 7352 KB Output is correct
5 Correct 5 ms 7252 KB Output is correct
6 Correct 5 ms 7380 KB Output is correct
7 Correct 4 ms 7356 KB Output is correct
8 Correct 4 ms 7252 KB Output is correct
9 Correct 5 ms 7360 KB Output is correct
10 Correct 5 ms 7496 KB Output is correct
11 Correct 5 ms 7380 KB Output is correct
12 Correct 4 ms 7380 KB Output is correct
13 Correct 4 ms 7312 KB Output is correct
14 Correct 5 ms 7380 KB Output is correct
15 Correct 6 ms 7380 KB Output is correct
16 Correct 6 ms 7416 KB Output is correct
17 Correct 25 ms 10068 KB Output is correct
18 Correct 27 ms 10676 KB Output is correct
19 Correct 24 ms 10580 KB Output is correct
20 Correct 23 ms 10564 KB Output is correct
21 Correct 24 ms 10564 KB Output is correct
22 Correct 47 ms 13664 KB Output is correct
23 Correct 9 ms 8004 KB Output is correct
24 Correct 21 ms 9300 KB Output is correct
25 Correct 5 ms 7344 KB Output is correct
26 Correct 8 ms 7880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Correct 5 ms 7360 KB Output is correct
4 Correct 4 ms 7352 KB Output is correct
5 Correct 5 ms 7252 KB Output is correct
6 Correct 5 ms 7380 KB Output is correct
7 Correct 4 ms 7356 KB Output is correct
8 Correct 4 ms 7252 KB Output is correct
9 Correct 5 ms 7360 KB Output is correct
10 Correct 5 ms 7496 KB Output is correct
11 Correct 5 ms 7380 KB Output is correct
12 Correct 4 ms 7380 KB Output is correct
13 Correct 4 ms 7312 KB Output is correct
14 Correct 5 ms 7380 KB Output is correct
15 Correct 6 ms 7380 KB Output is correct
16 Correct 6 ms 7416 KB Output is correct
17 Correct 25 ms 10068 KB Output is correct
18 Correct 27 ms 10676 KB Output is correct
19 Correct 24 ms 10580 KB Output is correct
20 Correct 23 ms 10564 KB Output is correct
21 Correct 24 ms 10564 KB Output is correct
22 Correct 47 ms 13664 KB Output is correct
23 Correct 9 ms 8004 KB Output is correct
24 Correct 21 ms 9300 KB Output is correct
25 Correct 5 ms 7344 KB Output is correct
26 Correct 8 ms 7880 KB Output is correct
27 Correct 6 ms 7884 KB Output is correct
28 Correct 110 ms 22112 KB Output is correct
29 Correct 195 ms 27376 KB Output is correct
30 Correct 191 ms 26844 KB Output is correct
31 Correct 194 ms 26852 KB Output is correct
32 Correct 157 ms 28220 KB Output is correct
33 Correct 208 ms 26860 KB Output is correct
34 Correct 210 ms 26892 KB Output is correct
35 Correct 65 ms 15388 KB Output is correct
36 Correct 179 ms 28696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 19256 KB Output is correct
2 Correct 28 ms 19232 KB Output is correct
3 Correct 59 ms 23072 KB Output is correct
4 Correct 49 ms 22348 KB Output is correct
5 Correct 89 ms 27080 KB Output is correct
6 Correct 98 ms 26524 KB Output is correct
7 Correct 90 ms 27084 KB Output is correct
8 Correct 87 ms 27088 KB Output is correct
9 Correct 118 ms 26800 KB Output is correct
10 Correct 98 ms 20328 KB Output is correct
11 Correct 160 ms 33112 KB Output is correct
12 Correct 4 ms 7252 KB Output is correct
13 Correct 4 ms 7352 KB Output is correct
14 Correct 4 ms 7252 KB Output is correct
15 Correct 4 ms 7380 KB Output is correct
16 Correct 4 ms 7356 KB Output is correct
17 Correct 4 ms 7380 KB Output is correct
18 Correct 29 ms 19252 KB Output is correct
19 Correct 32 ms 19292 KB Output is correct
20 Correct 30 ms 19288 KB Output is correct
21 Correct 28 ms 19276 KB Output is correct
22 Correct 145 ms 27148 KB Output is correct
23 Correct 156 ms 33116 KB Output is correct
24 Correct 180 ms 33636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 23088 KB Output is correct
2 Correct 92 ms 24872 KB Output is correct
3 Correct 26 ms 19228 KB Output is correct
4 Correct 29 ms 19184 KB Output is correct
5 Correct 241 ms 36076 KB Output is correct
6 Correct 329 ms 39576 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 131 ms 27632 KB Output is correct
9 Correct 159 ms 30520 KB Output is correct
10 Correct 79 ms 22972 KB Output is correct
11 Correct 92 ms 24848 KB Output is correct
12 Correct 4 ms 7380 KB Output is correct
13 Correct 4 ms 7356 KB Output is correct
14 Correct 4 ms 7380 KB Output is correct
15 Correct 4 ms 7252 KB Output is correct
16 Correct 27 ms 19280 KB Output is correct
17 Correct 27 ms 19180 KB Output is correct
18 Correct 87 ms 23040 KB Output is correct
19 Correct 91 ms 24884 KB Output is correct
20 Correct 78 ms 23004 KB Output is correct
21 Correct 87 ms 24384 KB Output is correct
22 Correct 80 ms 23056 KB Output is correct
23 Correct 89 ms 24380 KB Output is correct
24 Correct 27 ms 19256 KB Output is correct
25 Correct 28 ms 19232 KB Output is correct
26 Correct 59 ms 23072 KB Output is correct
27 Correct 49 ms 22348 KB Output is correct
28 Correct 89 ms 27080 KB Output is correct
29 Correct 98 ms 26524 KB Output is correct
30 Correct 90 ms 27084 KB Output is correct
31 Correct 87 ms 27088 KB Output is correct
32 Correct 4 ms 7380 KB Output is correct
33 Correct 4 ms 7252 KB Output is correct
34 Correct 5 ms 7360 KB Output is correct
35 Correct 4 ms 7352 KB Output is correct
36 Correct 5 ms 7252 KB Output is correct
37 Correct 5 ms 7380 KB Output is correct
38 Correct 4 ms 7356 KB Output is correct
39 Correct 4 ms 7252 KB Output is correct
40 Correct 5 ms 7360 KB Output is correct
41 Correct 5 ms 7496 KB Output is correct
42 Correct 5 ms 7380 KB Output is correct
43 Correct 4 ms 7380 KB Output is correct
44 Correct 4 ms 7312 KB Output is correct
45 Correct 5 ms 7380 KB Output is correct
46 Correct 6 ms 7380 KB Output is correct
47 Correct 6 ms 7416 KB Output is correct
48 Correct 25 ms 10068 KB Output is correct
49 Correct 27 ms 10676 KB Output is correct
50 Correct 24 ms 10580 KB Output is correct
51 Correct 23 ms 10564 KB Output is correct
52 Correct 24 ms 10564 KB Output is correct
53 Correct 47 ms 13664 KB Output is correct
54 Correct 9 ms 8004 KB Output is correct
55 Correct 21 ms 9300 KB Output is correct
56 Correct 5 ms 7344 KB Output is correct
57 Correct 8 ms 7880 KB Output is correct
58 Correct 6 ms 7884 KB Output is correct
59 Correct 110 ms 22112 KB Output is correct
60 Correct 195 ms 27376 KB Output is correct
61 Correct 191 ms 26844 KB Output is correct
62 Correct 194 ms 26852 KB Output is correct
63 Correct 157 ms 28220 KB Output is correct
64 Correct 208 ms 26860 KB Output is correct
65 Correct 210 ms 26892 KB Output is correct
66 Correct 65 ms 15388 KB Output is correct
67 Correct 179 ms 28696 KB Output is correct
68 Correct 118 ms 26800 KB Output is correct
69 Correct 98 ms 20328 KB Output is correct
70 Correct 160 ms 33112 KB Output is correct
71 Correct 4 ms 7252 KB Output is correct
72 Correct 4 ms 7352 KB Output is correct
73 Correct 4 ms 7252 KB Output is correct
74 Correct 4 ms 7380 KB Output is correct
75 Correct 4 ms 7356 KB Output is correct
76 Correct 4 ms 7380 KB Output is correct
77 Correct 29 ms 19252 KB Output is correct
78 Correct 32 ms 19292 KB Output is correct
79 Correct 30 ms 19288 KB Output is correct
80 Correct 28 ms 19276 KB Output is correct
81 Correct 145 ms 27148 KB Output is correct
82 Correct 156 ms 33116 KB Output is correct
83 Correct 180 ms 33636 KB Output is correct
84 Correct 244 ms 36440 KB Output is correct
85 Correct 241 ms 36624 KB Output is correct
86 Correct 366 ms 39780 KB Output is correct
87 Correct 368 ms 40668 KB Output is correct
88 Correct 4 ms 7356 KB Output is correct
89 Correct 347 ms 40764 KB Output is correct
90 Correct 214 ms 39028 KB Output is correct
91 Correct 210 ms 38684 KB Output is correct