Submission #627122

# Submission time Handle Problem Language Result Execution time Memory
627122 2022-08-12T08:33:17 Z CodePlatina Catfish Farm (IOI22_fish) C++17
100 / 100
342 ms 24860 KB
#include "fish.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<long long, long long>
#define plll pair<long long, pll>
#define tiii tuple<int, int, int>
#define tiiii tuple<int, int, int, int>
#define ff first
#define ss second
#define ee ss.ff
#define rr ss.ss
#define DEBUG

using namespace std;

const long long INF = (long long)1e18 + 7;

struct SEG
{
    int N;
    long long ind[202020];
    long long qry(int l, int r)
    {
        long long ret = 0;
        for(int x = l + N, y = r + N; x != y; x >>= 1, y >>= 1)
        {
            if(x & 1) ret = max(ret, ind[x++]);
            if(y & 1) ret = max(ret, ind[--y]);
        }
        return ret;
    }
    void upd(int x, long long v)
    {
        x += N;
        ind[x] = max(ind[x], v);
        while(x >>= 1) ind[x] = max(ind[x << 1], ind[x << 1 | 1]);
    }
}dp[2];

long long max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W)
{
    vector<pii> A[N];
    for(int i = 0; i < M; ++i) A[X[i]].push_back({Y[i], W[i]});
    dp[0].N = dp[1].N = N + 1;
    for(int i = 0; i < N; ++i) sort(A[i].begin(), A[i].end());
    vector<pii> B[N];
    for(int i = 0; i < N; ++i) B[i] = A[i], reverse(B[i].begin(), B[i].end());

    for(int i = 1; i < N; ++i)
    {
        vector<pair<int, long long>> upd[3];
        long long ps = 0;
        for(auto [y, w] : A[i - 1])
        {
            ps = max(ps, dp[0].qry(0, y + 1)) + w;
            upd[0].push_back({y + 1, ps});
        }
        ps = 0;
        for(auto [y, w] : B[i])
        {
            ps = max(ps, dp[1].qry(y + 1, N + 1)) + w;
            upd[1].push_back({y, ps});
        }
        ps = 0;
        for(auto [y, w] : A[i])
        {
            ps += w;
            upd[2].push_back({y + 1, dp[1].qry(y + 1, N + 1) + ps});
        }
        upd[0].push_back({0, dp[1].qry(0, N + 1)});
        for(auto [x, v] : upd[0]) dp[0].upd(x, v);
        for(auto [x, v] : upd[1]) dp[1].upd(x, v);
        dp[1].upd(N, dp[0].qry(0, N + 1));
        for(auto [x, v] : upd[2]) dp[0].upd(x, v);

//        for(int i = 0; i <= N; ++i) cout << dp[0].qry(i, i + 1) << ' '; cout << endl;
//        for(int i = 0; i <= N; ++i) cout << dp[1].qry(i, i + 1) << ' '; cout << endl;
    }

    return max(dp[0].qry(0, N + 1), dp[1].qry(0, N + 1));
}
# Verdict Execution time Memory Grader output
1 Correct 57 ms 10468 KB Output is correct
2 Correct 71 ms 12216 KB Output is correct
3 Correct 20 ms 5080 KB Output is correct
4 Correct 21 ms 5080 KB Output is correct
5 Correct 222 ms 24772 KB Output is correct
6 Correct 296 ms 22088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 115 ms 17584 KB Output is correct
3 Correct 138 ms 20788 KB Output is correct
4 Correct 56 ms 10452 KB Output is correct
5 Correct 66 ms 12208 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 21 ms 5072 KB Output is correct
11 Correct 20 ms 5076 KB Output is correct
12 Correct 73 ms 13764 KB Output is correct
13 Correct 88 ms 15680 KB Output is correct
14 Correct 64 ms 11888 KB Output is correct
15 Correct 74 ms 12432 KB Output is correct
16 Correct 65 ms 11904 KB Output is correct
17 Correct 72 ms 13128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 5076 KB Output is correct
2 Correct 20 ms 5036 KB Output is correct
3 Correct 54 ms 9228 KB Output is correct
4 Correct 47 ms 8172 KB Output is correct
5 Correct 89 ms 13644 KB Output is correct
6 Correct 86 ms 13684 KB Output is correct
7 Correct 95 ms 13564 KB Output is correct
8 Correct 91 ms 13684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 20 ms 2216 KB Output is correct
18 Correct 20 ms 2516 KB Output is correct
19 Correct 20 ms 2376 KB Output is correct
20 Correct 24 ms 2380 KB Output is correct
21 Correct 26 ms 2440 KB Output is correct
22 Correct 41 ms 4428 KB Output is correct
23 Correct 5 ms 724 KB Output is correct
24 Correct 16 ms 1620 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 4 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 20 ms 2216 KB Output is correct
18 Correct 20 ms 2516 KB Output is correct
19 Correct 20 ms 2376 KB Output is correct
20 Correct 24 ms 2380 KB Output is correct
21 Correct 26 ms 2440 KB Output is correct
22 Correct 41 ms 4428 KB Output is correct
23 Correct 5 ms 724 KB Output is correct
24 Correct 16 ms 1620 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 4 ms 596 KB Output is correct
27 Correct 3 ms 724 KB Output is correct
28 Correct 106 ms 14088 KB Output is correct
29 Correct 170 ms 19432 KB Output is correct
30 Correct 174 ms 18784 KB Output is correct
31 Correct 178 ms 18784 KB Output is correct
32 Correct 142 ms 19420 KB Output is correct
33 Correct 173 ms 18876 KB Output is correct
34 Correct 180 ms 18140 KB Output is correct
35 Correct 62 ms 7140 KB Output is correct
36 Correct 168 ms 16504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 5076 KB Output is correct
2 Correct 20 ms 5036 KB Output is correct
3 Correct 54 ms 9228 KB Output is correct
4 Correct 47 ms 8172 KB Output is correct
5 Correct 89 ms 13644 KB Output is correct
6 Correct 86 ms 13684 KB Output is correct
7 Correct 95 ms 13564 KB Output is correct
8 Correct 91 ms 13684 KB Output is correct
9 Correct 109 ms 16716 KB Output is correct
10 Correct 73 ms 8268 KB Output is correct
11 Correct 160 ms 16416 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 22 ms 5076 KB Output is correct
19 Correct 24 ms 5084 KB Output is correct
20 Correct 21 ms 5076 KB Output is correct
21 Correct 23 ms 5080 KB Output is correct
22 Correct 120 ms 14864 KB Output is correct
23 Correct 154 ms 16480 KB Output is correct
24 Correct 177 ms 18148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 10468 KB Output is correct
2 Correct 71 ms 12216 KB Output is correct
3 Correct 20 ms 5080 KB Output is correct
4 Correct 21 ms 5080 KB Output is correct
5 Correct 222 ms 24772 KB Output is correct
6 Correct 296 ms 22088 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 115 ms 17584 KB Output is correct
9 Correct 138 ms 20788 KB Output is correct
10 Correct 56 ms 10452 KB Output is correct
11 Correct 66 ms 12208 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 21 ms 5072 KB Output is correct
17 Correct 20 ms 5076 KB Output is correct
18 Correct 73 ms 13764 KB Output is correct
19 Correct 88 ms 15680 KB Output is correct
20 Correct 64 ms 11888 KB Output is correct
21 Correct 74 ms 12432 KB Output is correct
22 Correct 65 ms 11904 KB Output is correct
23 Correct 72 ms 13128 KB Output is correct
24 Correct 21 ms 5076 KB Output is correct
25 Correct 20 ms 5036 KB Output is correct
26 Correct 54 ms 9228 KB Output is correct
27 Correct 47 ms 8172 KB Output is correct
28 Correct 89 ms 13644 KB Output is correct
29 Correct 86 ms 13684 KB Output is correct
30 Correct 95 ms 13564 KB Output is correct
31 Correct 91 ms 13684 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 2 ms 332 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 0 ms 212 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 20 ms 2216 KB Output is correct
49 Correct 20 ms 2516 KB Output is correct
50 Correct 20 ms 2376 KB Output is correct
51 Correct 24 ms 2380 KB Output is correct
52 Correct 26 ms 2440 KB Output is correct
53 Correct 41 ms 4428 KB Output is correct
54 Correct 5 ms 724 KB Output is correct
55 Correct 16 ms 1620 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 4 ms 596 KB Output is correct
58 Correct 3 ms 724 KB Output is correct
59 Correct 106 ms 14088 KB Output is correct
60 Correct 170 ms 19432 KB Output is correct
61 Correct 174 ms 18784 KB Output is correct
62 Correct 178 ms 18784 KB Output is correct
63 Correct 142 ms 19420 KB Output is correct
64 Correct 173 ms 18876 KB Output is correct
65 Correct 180 ms 18140 KB Output is correct
66 Correct 62 ms 7140 KB Output is correct
67 Correct 168 ms 16504 KB Output is correct
68 Correct 109 ms 16716 KB Output is correct
69 Correct 73 ms 8268 KB Output is correct
70 Correct 160 ms 16416 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 0 ms 212 KB Output is correct
73 Correct 0 ms 212 KB Output is correct
74 Correct 0 ms 212 KB Output is correct
75 Correct 0 ms 212 KB Output is correct
76 Correct 1 ms 212 KB Output is correct
77 Correct 22 ms 5076 KB Output is correct
78 Correct 24 ms 5084 KB Output is correct
79 Correct 21 ms 5076 KB Output is correct
80 Correct 23 ms 5080 KB Output is correct
81 Correct 120 ms 14864 KB Output is correct
82 Correct 154 ms 16480 KB Output is correct
83 Correct 177 ms 18148 KB Output is correct
84 Correct 225 ms 23948 KB Output is correct
85 Correct 226 ms 24364 KB Output is correct
86 Correct 319 ms 23624 KB Output is correct
87 Correct 312 ms 24000 KB Output is correct
88 Correct 1 ms 212 KB Output is correct
89 Correct 342 ms 24860 KB Output is correct
90 Correct 223 ms 19276 KB Output is correct
91 Correct 209 ms 18932 KB Output is correct