Submission #1072852

# Submission time Handle Problem Language Result Execution time Memory
1072852 2024-08-24T05:48:34 Z hotboy2703 Catfish Farm (IOI22_fish) C++17
100 / 100
123 ms 39580 KB
#include "fish.h"

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MP make_pair
#define fi first
#define se second
#define pll pair <ll,ll>
#define sz(a) (ll((a).size()))
#define BIT(mask,i) (((mask) >> (i))&1LL)
#define MASK(i) (1LL<<(i)) 
ll n,m;
const ll MAXN = 1e5+100;
const ll INF = 1e18;
struct fish{
    ll y,w,v0,v1;
    bool operator < (const fish &p)const {
        return y < p.y;
    }
};
vector <fish> dp[MAXN];
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W) {
    n=N,m=M;
    for (ll i = 0;i < m;i ++){
        dp[X[i]+1].push_back({Y[i],W[i],0,0});
    }
    for (ll i = 0;i <= n+1;i ++){
        dp[i].push_back({-1,0,0,0});
        sort(dp[i].begin(),dp[i].end());
        if (dp[i].back().y != n - 1)dp[i].push_back({n-1,0,0,0});
    }
    for (ll i = 2;i <= n;i ++){
        // cout<<"COL "<<i<<endl;
        dp[i-2][0].v1 = dp[i-1][0].v0;
        ll ptr = 0;
        ll max1 = -INF;
        ll sum = 0;
        for (auto &x:dp[i-1]){
            while (dp[i-2][ptr].y < x.y){
                max1 = max(max1,dp[i-2][ptr].v1 - sum);
                ptr++;
            }
            sum += x.w;
            x.v1 = max1 + sum;
            // cout<<"V1 "<<x.y<<' '<<x.v1<<'\n';
        }
        dp[i].back().v0 = dp[i-2].back().v1;
        sum = 0;
        for (auto &x:dp[i]){
            sum += x.w;
            x.v0 += sum;
        }
        ptr = sz(dp[i])-1;
        max1 = -INF;
        for (ll j = sz(dp[i+1])-2;j >= 0;j --){
            auto &x = dp[i+1][j];
            while (dp[i][ptr].y > x.y){
                sum -= dp[i][ptr].w;
                max1 = max(max1,dp[i][ptr].v0);
                ptr--;
            }
            x.v0 = max1 - sum;
            // cout<<"V0 "<<x.y<<' '<<x.v0<<'\n';
        }
        dp[i-1].back().v1 = max({dp[i-1].back().v1,dp[i-2].back().v1,dp[i][0].v0});
        // cout<<"V1 "<<dp[i-1].back().v1<<'\n';
    }
    return max(dp[n-1].back().v1,dp[n+1][0].v0);
}
# Verdict Execution time Memory Grader output
1 Correct 32 ms 15552 KB Output is correct
2 Correct 37 ms 17600 KB Output is correct
3 Correct 10 ms 10588 KB Output is correct
4 Correct 10 ms 10584 KB Output is correct
5 Correct 102 ms 33440 KB Output is correct
6 Correct 123 ms 38740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 53 ms 21424 KB Output is correct
3 Correct 85 ms 25000 KB Output is correct
4 Correct 31 ms 15548 KB Output is correct
5 Correct 36 ms 17848 KB Output is correct
6 Correct 2 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2648 KB Output is correct
10 Correct 9 ms 10584 KB Output is correct
11 Correct 10 ms 10584 KB Output is correct
12 Correct 34 ms 15508 KB Output is correct
13 Correct 36 ms 17844 KB Output is correct
14 Correct 32 ms 15480 KB Output is correct
15 Correct 34 ms 16988 KB Output is correct
16 Correct 35 ms 15628 KB Output is correct
17 Correct 36 ms 17076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 10588 KB Output is correct
2 Correct 9 ms 10588 KB Output is correct
3 Correct 28 ms 15700 KB Output is correct
4 Correct 22 ms 14424 KB Output is correct
5 Correct 42 ms 21468 KB Output is correct
6 Correct 39 ms 20820 KB Output is correct
7 Correct 39 ms 21332 KB Output is correct
8 Correct 42 ms 21328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2792 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 2 ms 2908 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 2 ms 2908 KB Output is correct
13 Correct 2 ms 2652 KB Output is correct
14 Correct 2 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2792 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 2 ms 2908 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 2 ms 2908 KB Output is correct
13 Correct 2 ms 2652 KB Output is correct
14 Correct 2 ms 2908 KB Output is correct
15 Correct 1 ms 2792 KB Output is correct
16 Correct 2 ms 2908 KB Output is correct
17 Correct 13 ms 6152 KB Output is correct
18 Correct 17 ms 7160 KB Output is correct
19 Correct 16 ms 7284 KB Output is correct
20 Correct 15 ms 7260 KB Output is correct
21 Correct 13 ms 7260 KB Output is correct
22 Correct 26 ms 11352 KB Output is correct
23 Correct 4 ms 3556 KB Output is correct
24 Correct 9 ms 5236 KB Output is correct
25 Correct 2 ms 2908 KB Output is correct
26 Correct 4 ms 3420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2792 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 2 ms 2908 KB Output is correct
11 Correct 1 ms 2652 KB Output is correct
12 Correct 2 ms 2908 KB Output is correct
13 Correct 2 ms 2652 KB Output is correct
14 Correct 2 ms 2908 KB Output is correct
15 Correct 1 ms 2792 KB Output is correct
16 Correct 2 ms 2908 KB Output is correct
17 Correct 13 ms 6152 KB Output is correct
18 Correct 17 ms 7160 KB Output is correct
19 Correct 16 ms 7284 KB Output is correct
20 Correct 15 ms 7260 KB Output is correct
21 Correct 13 ms 7260 KB Output is correct
22 Correct 26 ms 11352 KB Output is correct
23 Correct 4 ms 3556 KB Output is correct
24 Correct 9 ms 5236 KB Output is correct
25 Correct 2 ms 2908 KB Output is correct
26 Correct 4 ms 3420 KB Output is correct
27 Correct 3 ms 3160 KB Output is correct
28 Correct 53 ms 22348 KB Output is correct
29 Correct 88 ms 29452 KB Output is correct
30 Correct 86 ms 28500 KB Output is correct
31 Correct 94 ms 28568 KB Output is correct
32 Correct 78 ms 30632 KB Output is correct
33 Correct 82 ms 28500 KB Output is correct
34 Correct 79 ms 28568 KB Output is correct
35 Correct 33 ms 13660 KB Output is correct
36 Correct 79 ms 30748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 10588 KB Output is correct
2 Correct 9 ms 10588 KB Output is correct
3 Correct 28 ms 15700 KB Output is correct
4 Correct 22 ms 14424 KB Output is correct
5 Correct 42 ms 21468 KB Output is correct
6 Correct 39 ms 20820 KB Output is correct
7 Correct 39 ms 21332 KB Output is correct
8 Correct 42 ms 21328 KB Output is correct
9 Correct 47 ms 21268 KB Output is correct
10 Correct 38 ms 14672 KB Output is correct
11 Correct 74 ms 26772 KB Output is correct
12 Correct 2 ms 2648 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 2 ms 2652 KB Output is correct
17 Correct 1 ms 2652 KB Output is correct
18 Correct 11 ms 10588 KB Output is correct
19 Correct 10 ms 10620 KB Output is correct
20 Correct 10 ms 10584 KB Output is correct
21 Correct 10 ms 10588 KB Output is correct
22 Correct 42 ms 19548 KB Output is correct
23 Correct 81 ms 26704 KB Output is correct
24 Correct 73 ms 27156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 15552 KB Output is correct
2 Correct 37 ms 17600 KB Output is correct
3 Correct 10 ms 10588 KB Output is correct
4 Correct 10 ms 10584 KB Output is correct
5 Correct 102 ms 33440 KB Output is correct
6 Correct 123 ms 38740 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 53 ms 21424 KB Output is correct
9 Correct 85 ms 25000 KB Output is correct
10 Correct 31 ms 15548 KB Output is correct
11 Correct 36 ms 17848 KB Output is correct
12 Correct 2 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2648 KB Output is correct
16 Correct 9 ms 10584 KB Output is correct
17 Correct 10 ms 10584 KB Output is correct
18 Correct 34 ms 15508 KB Output is correct
19 Correct 36 ms 17844 KB Output is correct
20 Correct 32 ms 15480 KB Output is correct
21 Correct 34 ms 16988 KB Output is correct
22 Correct 35 ms 15628 KB Output is correct
23 Correct 36 ms 17076 KB Output is correct
24 Correct 10 ms 10588 KB Output is correct
25 Correct 9 ms 10588 KB Output is correct
26 Correct 28 ms 15700 KB Output is correct
27 Correct 22 ms 14424 KB Output is correct
28 Correct 42 ms 21468 KB Output is correct
29 Correct 39 ms 20820 KB Output is correct
30 Correct 39 ms 21332 KB Output is correct
31 Correct 42 ms 21328 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 1 ms 2652 KB Output is correct
34 Correct 1 ms 2792 KB Output is correct
35 Correct 1 ms 2652 KB Output is correct
36 Correct 1 ms 2652 KB Output is correct
37 Correct 1 ms 2652 KB Output is correct
38 Correct 1 ms 2652 KB Output is correct
39 Correct 1 ms 2652 KB Output is correct
40 Correct 1 ms 2652 KB Output is correct
41 Correct 2 ms 2908 KB Output is correct
42 Correct 1 ms 2652 KB Output is correct
43 Correct 2 ms 2908 KB Output is correct
44 Correct 2 ms 2652 KB Output is correct
45 Correct 2 ms 2908 KB Output is correct
46 Correct 1 ms 2792 KB Output is correct
47 Correct 2 ms 2908 KB Output is correct
48 Correct 13 ms 6152 KB Output is correct
49 Correct 17 ms 7160 KB Output is correct
50 Correct 16 ms 7284 KB Output is correct
51 Correct 15 ms 7260 KB Output is correct
52 Correct 13 ms 7260 KB Output is correct
53 Correct 26 ms 11352 KB Output is correct
54 Correct 4 ms 3556 KB Output is correct
55 Correct 9 ms 5236 KB Output is correct
56 Correct 2 ms 2908 KB Output is correct
57 Correct 4 ms 3420 KB Output is correct
58 Correct 3 ms 3160 KB Output is correct
59 Correct 53 ms 22348 KB Output is correct
60 Correct 88 ms 29452 KB Output is correct
61 Correct 86 ms 28500 KB Output is correct
62 Correct 94 ms 28568 KB Output is correct
63 Correct 78 ms 30632 KB Output is correct
64 Correct 82 ms 28500 KB Output is correct
65 Correct 79 ms 28568 KB Output is correct
66 Correct 33 ms 13660 KB Output is correct
67 Correct 79 ms 30748 KB Output is correct
68 Correct 47 ms 21268 KB Output is correct
69 Correct 38 ms 14672 KB Output is correct
70 Correct 74 ms 26772 KB Output is correct
71 Correct 2 ms 2648 KB Output is correct
72 Correct 1 ms 2652 KB Output is correct
73 Correct 1 ms 2652 KB Output is correct
74 Correct 1 ms 2652 KB Output is correct
75 Correct 2 ms 2652 KB Output is correct
76 Correct 1 ms 2652 KB Output is correct
77 Correct 11 ms 10588 KB Output is correct
78 Correct 10 ms 10620 KB Output is correct
79 Correct 10 ms 10584 KB Output is correct
80 Correct 10 ms 10588 KB Output is correct
81 Correct 42 ms 19548 KB Output is correct
82 Correct 81 ms 26704 KB Output is correct
83 Correct 73 ms 27156 KB Output is correct
84 Correct 101 ms 32188 KB Output is correct
85 Correct 102 ms 32276 KB Output is correct
86 Correct 112 ms 38740 KB Output is correct
87 Correct 112 ms 39580 KB Output is correct
88 Correct 2 ms 2652 KB Output is correct
89 Correct 108 ms 39576 KB Output is correct
90 Correct 102 ms 36688 KB Output is correct
91 Correct 101 ms 36944 KB Output is correct