Submission #953708

# Submission time Handle Problem Language Result Execution time Memory
953708 2024-03-26T14:02:22 Z tleSquared Catfish Farm (IOI22_fish) C++17
100 / 100
148 ms 60028 KB
#include "fish.h"

#include <bits/stdc++.h>
#define ll long long
#define INF 1e16
#define MAX 500005

using namespace std;

ll N, M;
ll up[MAX], down[MAX], sum[MAX], in[MAX], out[MAX];
vector<ll> X, Y, W;
vector<pair<ll, ll>> pos[MAX];

ll max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w)
{
    N = n, M = m;
    X.resize(M);
    Y.resize(N + M + 1);
    W.resize(M);
    for (ll i = 0; i < M; i++)
    {
        X[i] = x[i]+1;
        Y[i] = y[i]+1;
        W[i] = w[i];
    }
    for (ll i = 0; i < M; i++) pos[X[i]].push_back({Y[i], W[i]});
    for (ll i = 1; i <= N; i++) pos[i].push_back({N + 1, 0});
    for (ll i = 1; i <= N; i++) sort(pos[i].begin(), pos[i].end());

    ll cnt = 0;
    for (ll i = 1; i <= N; i++)
    {
        sum[++cnt] = pos[i][0].second;
        in[i] = cnt;
        Y[cnt] = pos[i][0].first;
        for(ll j = 1; j < pos[i].size(); ++j)
        {
            ++cnt;
            sum[cnt] = sum[cnt - 1] + pos[i][j].second;
            Y[cnt] = pos[i][j].first;
        }
        out[i] = cnt;
    }
    
    for(ll i = 0; i <= N; ++i) up[i] = down[i] = -INF;
    
    up[0] = down[0] = 0;
    Y[0] = -1;
    for(ll x = 1; x <= N; ++x)
    {
        ll k = in[x - 1], mx = -INF, p = -1;
        for (ll i = in[x]; i <= out[x]; ++i)
        {
            while(k <= out[x - 1] && Y[k] < Y[i])
            {
                mx = max(mx, up[k] - (k == in[x - 1] ? 0 : sum[k - 1]));
                p = k;
                k++;
            }
            
            up[i] = max(up[i], mx + (p == -1 ? 0 : sum[p]));
        }
        
        k = out[x - 1], mx = -INF, p = out[x];
        for(ll i = out[x]; i >= in[x]; --i)
        {
            while(k >= in[x - 1] && Y[k] > Y[i])
            {
                while(p >= in[x] && Y[k] <= Y[p]) --p;
                mx = max(mx, max(down[k], up[k]) + sum[p]);
                --k;
            }
            
            down[i] = max(down[i], mx - (i == in[x] ? 0 : sum[i - 1]));
            if(k >= in[x - 1] && Y[k] == Y[i]) down[i] = max(down[i], max(down[k], up[k]));
        }
        
        if(x < 2) continue;
        k = in[x - 2], mx = -INF, p = in[x - 1]; ll p2 = -1;
        for(ll i = in[x]; i <= out[x]; ++i)
        {
            while(k <= out[x - 2] && Y[k] <= Y[i])
            {
                mx = max(mx, max(up[k], down[k]));
                ++k;
            }
            while(p <= out[x - 1] && Y[p] < Y[i]) p2 = p++;
            up[i] = max(up[i], mx + (p2 == -1 ? 0 : sum[p2]));
        }
        
        k = out[x - 2], mx = -INF, p = out[x - 1];
        for(ll i = out[x]; i >= in[x]; --i)
        {
            while(k >= in[x - 2] && Y[k] > Y[i])
            {
                while(p >= in[x - 1] && Y[k] <= Y[p]) p--;
                mx = max(mx, max(up[k], down[k]) + (p == in[x - 1] - 1 ? 0 : sum[p]));
                --k;
            }
            up[i] = max(up[i], mx);
        }
    }
    
    ll res = 0;
    for(ll i = 0; i <= N + M; ++i) res = max(res, max(up[i], down[i]));
    return res;
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:37:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         for(ll j = 1; j < pos[i].size(); ++j)
      |                       ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 42 ms 31684 KB Output is correct
2 Correct 46 ms 37444 KB Output is correct
3 Correct 11 ms 26968 KB Output is correct
4 Correct 11 ms 27120 KB Output is correct
5 Correct 111 ms 57592 KB Output is correct
6 Correct 120 ms 59984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 21084 KB Output is correct
2 Correct 77 ms 40824 KB Output is correct
3 Correct 77 ms 47028 KB Output is correct
4 Correct 36 ms 33148 KB Output is correct
5 Correct 44 ms 37400 KB Output is correct
6 Correct 4 ms 21084 KB Output is correct
7 Correct 4 ms 21084 KB Output is correct
8 Correct 4 ms 21080 KB Output is correct
9 Correct 5 ms 21084 KB Output is correct
10 Correct 11 ms 26968 KB Output is correct
11 Correct 11 ms 26972 KB Output is correct
12 Correct 36 ms 33216 KB Output is correct
13 Correct 47 ms 37404 KB Output is correct
14 Correct 36 ms 32996 KB Output is correct
15 Correct 45 ms 36408 KB Output is correct
16 Correct 36 ms 33052 KB Output is correct
17 Correct 40 ms 36284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 26968 KB Output is correct
2 Correct 13 ms 26972 KB Output is correct
3 Correct 29 ms 29020 KB Output is correct
4 Correct 28 ms 30300 KB Output is correct
5 Correct 48 ms 38228 KB Output is correct
6 Correct 44 ms 37556 KB Output is correct
7 Correct 46 ms 38148 KB Output is correct
8 Correct 47 ms 38164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 21084 KB Output is correct
2 Correct 4 ms 21080 KB Output is correct
3 Correct 4 ms 21084 KB Output is correct
4 Correct 4 ms 21080 KB Output is correct
5 Correct 4 ms 21080 KB Output is correct
6 Correct 4 ms 21080 KB Output is correct
7 Correct 4 ms 21084 KB Output is correct
8 Correct 4 ms 21360 KB Output is correct
9 Correct 4 ms 21084 KB Output is correct
10 Correct 5 ms 21340 KB Output is correct
11 Correct 4 ms 21132 KB Output is correct
12 Correct 4 ms 21084 KB Output is correct
13 Correct 4 ms 21084 KB Output is correct
14 Correct 4 ms 21084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 21084 KB Output is correct
2 Correct 4 ms 21080 KB Output is correct
3 Correct 4 ms 21084 KB Output is correct
4 Correct 4 ms 21080 KB Output is correct
5 Correct 4 ms 21080 KB Output is correct
6 Correct 4 ms 21080 KB Output is correct
7 Correct 4 ms 21084 KB Output is correct
8 Correct 4 ms 21360 KB Output is correct
9 Correct 4 ms 21084 KB Output is correct
10 Correct 5 ms 21340 KB Output is correct
11 Correct 4 ms 21132 KB Output is correct
12 Correct 4 ms 21084 KB Output is correct
13 Correct 4 ms 21084 KB Output is correct
14 Correct 4 ms 21084 KB Output is correct
15 Correct 4 ms 21084 KB Output is correct
16 Correct 5 ms 21340 KB Output is correct
17 Correct 18 ms 24712 KB Output is correct
18 Correct 18 ms 25436 KB Output is correct
19 Correct 19 ms 25172 KB Output is correct
20 Correct 22 ms 25228 KB Output is correct
21 Correct 18 ms 25436 KB Output is correct
22 Correct 31 ms 29524 KB Output is correct
23 Correct 7 ms 21852 KB Output is correct
24 Correct 14 ms 23644 KB Output is correct
25 Correct 5 ms 21080 KB Output is correct
26 Correct 7 ms 21904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 21084 KB Output is correct
2 Correct 4 ms 21080 KB Output is correct
3 Correct 4 ms 21084 KB Output is correct
4 Correct 4 ms 21080 KB Output is correct
5 Correct 4 ms 21080 KB Output is correct
6 Correct 4 ms 21080 KB Output is correct
7 Correct 4 ms 21084 KB Output is correct
8 Correct 4 ms 21360 KB Output is correct
9 Correct 4 ms 21084 KB Output is correct
10 Correct 5 ms 21340 KB Output is correct
11 Correct 4 ms 21132 KB Output is correct
12 Correct 4 ms 21084 KB Output is correct
13 Correct 4 ms 21084 KB Output is correct
14 Correct 4 ms 21084 KB Output is correct
15 Correct 4 ms 21084 KB Output is correct
16 Correct 5 ms 21340 KB Output is correct
17 Correct 18 ms 24712 KB Output is correct
18 Correct 18 ms 25436 KB Output is correct
19 Correct 19 ms 25172 KB Output is correct
20 Correct 22 ms 25228 KB Output is correct
21 Correct 18 ms 25436 KB Output is correct
22 Correct 31 ms 29524 KB Output is correct
23 Correct 7 ms 21852 KB Output is correct
24 Correct 14 ms 23644 KB Output is correct
25 Correct 5 ms 21080 KB Output is correct
26 Correct 7 ms 21904 KB Output is correct
27 Correct 5 ms 21392 KB Output is correct
28 Correct 75 ms 43484 KB Output is correct
29 Correct 100 ms 51792 KB Output is correct
30 Correct 107 ms 51388 KB Output is correct
31 Correct 108 ms 51336 KB Output is correct
32 Correct 93 ms 52796 KB Output is correct
33 Correct 112 ms 51376 KB Output is correct
34 Correct 107 ms 51384 KB Output is correct
35 Correct 46 ms 31640 KB Output is correct
36 Correct 109 ms 53332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 26968 KB Output is correct
2 Correct 13 ms 26972 KB Output is correct
3 Correct 29 ms 29020 KB Output is correct
4 Correct 28 ms 30300 KB Output is correct
5 Correct 48 ms 38228 KB Output is correct
6 Correct 44 ms 37556 KB Output is correct
7 Correct 46 ms 38148 KB Output is correct
8 Correct 47 ms 38164 KB Output is correct
9 Correct 45 ms 38000 KB Output is correct
10 Correct 42 ms 34564 KB Output is correct
11 Correct 84 ms 49820 KB Output is correct
12 Correct 4 ms 21080 KB Output is correct
13 Correct 4 ms 21084 KB Output is correct
14 Correct 4 ms 21084 KB Output is correct
15 Correct 5 ms 21084 KB Output is correct
16 Correct 4 ms 21084 KB Output is correct
17 Correct 4 ms 21084 KB Output is correct
18 Correct 10 ms 26972 KB Output is correct
19 Correct 12 ms 27224 KB Output is correct
20 Correct 11 ms 27008 KB Output is correct
21 Correct 11 ms 27224 KB Output is correct
22 Correct 50 ms 38284 KB Output is correct
23 Correct 85 ms 49672 KB Output is correct
24 Correct 83 ms 50256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 31684 KB Output is correct
2 Correct 46 ms 37444 KB Output is correct
3 Correct 11 ms 26968 KB Output is correct
4 Correct 11 ms 27120 KB Output is correct
5 Correct 111 ms 57592 KB Output is correct
6 Correct 120 ms 59984 KB Output is correct
7 Correct 4 ms 21084 KB Output is correct
8 Correct 77 ms 40824 KB Output is correct
9 Correct 77 ms 47028 KB Output is correct
10 Correct 36 ms 33148 KB Output is correct
11 Correct 44 ms 37400 KB Output is correct
12 Correct 4 ms 21084 KB Output is correct
13 Correct 4 ms 21084 KB Output is correct
14 Correct 4 ms 21080 KB Output is correct
15 Correct 5 ms 21084 KB Output is correct
16 Correct 11 ms 26968 KB Output is correct
17 Correct 11 ms 26972 KB Output is correct
18 Correct 36 ms 33216 KB Output is correct
19 Correct 47 ms 37404 KB Output is correct
20 Correct 36 ms 32996 KB Output is correct
21 Correct 45 ms 36408 KB Output is correct
22 Correct 36 ms 33052 KB Output is correct
23 Correct 40 ms 36284 KB Output is correct
24 Correct 11 ms 26968 KB Output is correct
25 Correct 13 ms 26972 KB Output is correct
26 Correct 29 ms 29020 KB Output is correct
27 Correct 28 ms 30300 KB Output is correct
28 Correct 48 ms 38228 KB Output is correct
29 Correct 44 ms 37556 KB Output is correct
30 Correct 46 ms 38148 KB Output is correct
31 Correct 47 ms 38164 KB Output is correct
32 Correct 4 ms 21084 KB Output is correct
33 Correct 4 ms 21080 KB Output is correct
34 Correct 4 ms 21084 KB Output is correct
35 Correct 4 ms 21080 KB Output is correct
36 Correct 4 ms 21080 KB Output is correct
37 Correct 4 ms 21080 KB Output is correct
38 Correct 4 ms 21084 KB Output is correct
39 Correct 4 ms 21360 KB Output is correct
40 Correct 4 ms 21084 KB Output is correct
41 Correct 5 ms 21340 KB Output is correct
42 Correct 4 ms 21132 KB Output is correct
43 Correct 4 ms 21084 KB Output is correct
44 Correct 4 ms 21084 KB Output is correct
45 Correct 4 ms 21084 KB Output is correct
46 Correct 4 ms 21084 KB Output is correct
47 Correct 5 ms 21340 KB Output is correct
48 Correct 18 ms 24712 KB Output is correct
49 Correct 18 ms 25436 KB Output is correct
50 Correct 19 ms 25172 KB Output is correct
51 Correct 22 ms 25228 KB Output is correct
52 Correct 18 ms 25436 KB Output is correct
53 Correct 31 ms 29524 KB Output is correct
54 Correct 7 ms 21852 KB Output is correct
55 Correct 14 ms 23644 KB Output is correct
56 Correct 5 ms 21080 KB Output is correct
57 Correct 7 ms 21904 KB Output is correct
58 Correct 5 ms 21392 KB Output is correct
59 Correct 75 ms 43484 KB Output is correct
60 Correct 100 ms 51792 KB Output is correct
61 Correct 107 ms 51388 KB Output is correct
62 Correct 108 ms 51336 KB Output is correct
63 Correct 93 ms 52796 KB Output is correct
64 Correct 112 ms 51376 KB Output is correct
65 Correct 107 ms 51384 KB Output is correct
66 Correct 46 ms 31640 KB Output is correct
67 Correct 109 ms 53332 KB Output is correct
68 Correct 45 ms 38000 KB Output is correct
69 Correct 42 ms 34564 KB Output is correct
70 Correct 84 ms 49820 KB Output is correct
71 Correct 4 ms 21080 KB Output is correct
72 Correct 4 ms 21084 KB Output is correct
73 Correct 4 ms 21084 KB Output is correct
74 Correct 5 ms 21084 KB Output is correct
75 Correct 4 ms 21084 KB Output is correct
76 Correct 4 ms 21084 KB Output is correct
77 Correct 10 ms 26972 KB Output is correct
78 Correct 12 ms 27224 KB Output is correct
79 Correct 11 ms 27008 KB Output is correct
80 Correct 11 ms 27224 KB Output is correct
81 Correct 50 ms 38284 KB Output is correct
82 Correct 85 ms 49672 KB Output is correct
83 Correct 83 ms 50256 KB Output is correct
84 Correct 118 ms 54944 KB Output is correct
85 Correct 119 ms 56928 KB Output is correct
86 Correct 126 ms 57236 KB Output is correct
87 Correct 132 ms 59828 KB Output is correct
88 Correct 5 ms 21080 KB Output is correct
89 Correct 148 ms 60028 KB Output is correct
90 Correct 122 ms 58540 KB Output is correct
91 Correct 114 ms 58568 KB Output is correct