Submission #1068591

# Submission time Handle Problem Language Result Execution time Memory
1068591 2024-08-21T10:50:05 Z Unforgettablepl Catfish Farm (IOI22_fish) C++17
100 / 100
211 ms 49732 KB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;

long long max_weights(int N, int M,vector<int> X,vector<int> Y,
                      vector<int> W){
    vector DP(N+1,vector(2,0ll));
    vector<vector<pair<int,long long>>> pref(N+2);
    for(int i=0;i<=N+1;i++)pref[i].emplace_back(0,0);
    vector<vector<int>> special_points(N+2);
    for(int i=1;i<=N+1;i++)special_points[i].emplace_back(0);
    for(int i=1;i<=N+1;i++)special_points[i].emplace_back(N);
    vector transition1(2,vector(N+1,0ll));
    vector transition2(3,vector(N+1,0ll));
    vector transition3(3,vector(N+1,0ll));
    vector transition4(2,vector(N+1,0ll));
    for(int i=0;i<M;i++) {
        pref[X[i]+1].emplace_back(Y[i]+1,W[i]);
        special_points[X[i]+1].emplace_back(Y[i]);
    }
    for(int i=1;i<=N+1;i++) {
        sort(special_points[i].begin(),special_points[i].end());
        special_points[i].erase(unique(special_points[i].begin(),special_points[i].end()),special_points[i].end());
        sort(pref[i].begin(), pref[i].end());
        for(int j=1;j<pref[i].size();j++)pref[i][j].second+=pref[i][j-1].second;
    }
    auto getpref = [&](int i,int j) {
        auto iter = lower_bound(pref[i].begin(),pref[i].end(),make_pair(j+1,-1ll));
        iter--;
        return iter->second;
    };
    auto get_higher = [&](int i,int j) {
        return lower_bound(special_points[i].begin(),special_points[i].end(),j)-special_points[i].begin()-0;
    };
    auto get_lower = [&](int i,int j) {
        return upper_bound(special_points[i].begin(),special_points[i].end(),j)-special_points[i].begin()-1;
    };
    for(int i=2;i<=N;i++) {
        int tot = special_points[i].size()-1;
        for(int s=0;s<=tot;s++) {
            int j = special_points[i][s];
            if(i!=2)DP[s][1]=max(DP[s][1],-getpref(i,j)+transition1[0][get_higher(i-1,j)]);
            else DP[s][1]=max(DP[s][1],getpref(i,N)-getpref(i,j));
            if(i>2) {
                if(i!=3) {
                    DP[s][0]=max(DP[s][0],getpref(i-1,j)+transition2[0][get_lower(i-2,j)]);
                    DP[s][0]=max(DP[s][0],transition3[0][get_higher(i-2,j)]);
                }
                else DP[s][0]=max(DP[s][0],getpref(i-1,N));
            }
            if(i!=2)DP[s][0]=max(DP[s][0],getpref(i-1,j)+transition4[0][get_lower(i-1,j)]);
            else DP[s][0]=max(DP[s][0],getpref(i-1,j));
            transition1[1][s]=getpref(i+1,j)+max(DP[s][0],DP[s][1]);
            transition2[2][s]=max(DP[s][0],DP[s][1]);
            transition3[2][s]=getpref(i+1,j)+max(DP[s][0],DP[s][1]);
            transition4[1][s]=-getpref(i,j)+DP[s][0];
        }
        for(int j=tot-1;j>=0;j--)transition1[1][j]=max(transition1[1][j],transition1[1][j+1]);
        for(int j=1;j<=tot;j++)transition2[2][j]=max(transition2[2][j],transition2[2][j-1]);
        for(int j=tot-1;j>=0;j--)transition3[2][j]=max(transition3[2][j],transition3[2][j+1]);
        for(int j=1;j<=tot;j++)transition4[1][j]=max(transition4[1][j],transition4[1][j-1]);
        swap(transition1[0],transition1[1]);
        swap(transition2[0],transition2[1]);
        swap(transition2[1],transition2[2]);
        swap(transition3[0],transition3[1]);
        swap(transition3[1],transition3[2]);
        swap(transition4[0],transition4[1]);
    }
    long long ans = 0;
    for(int j=0;j<=N;j++)ans=max(ans,DP[j][0]);
    for(int j=0;j<=N;j++)ans=max(ans,DP[j][1]);
    return ans;
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:25:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |         for(int j=1;j<pref[i].size();j++)pref[i][j].second+=pref[i][j-1].second;
      |                     ~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 50 ms 27292 KB Output is correct
2 Correct 57 ms 32076 KB Output is correct
3 Correct 27 ms 25388 KB Output is correct
4 Correct 26 ms 25420 KB Output is correct
5 Correct 153 ms 45368 KB Output is correct
6 Correct 145 ms 49732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 87 ms 31124 KB Output is correct
3 Correct 106 ms 37956 KB Output is correct
4 Correct 50 ms 29848 KB Output is correct
5 Correct 69 ms 32068 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 440 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 30 ms 25408 KB Output is correct
11 Correct 26 ms 25420 KB Output is correct
12 Correct 64 ms 28724 KB Output is correct
13 Correct 82 ms 31944 KB Output is correct
14 Correct 55 ms 29076 KB Output is correct
15 Correct 61 ms 31812 KB Output is correct
16 Correct 57 ms 29012 KB Output is correct
17 Correct 59 ms 31812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 25420 KB Output is correct
2 Correct 27 ms 25420 KB Output is correct
3 Correct 52 ms 25840 KB Output is correct
4 Correct 43 ms 27008 KB Output is correct
5 Correct 79 ms 31024 KB Output is correct
6 Correct 71 ms 30380 KB Output is correct
7 Correct 69 ms 31036 KB Output is correct
8 Correct 73 ms 30940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 372 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 27 ms 2652 KB Output is correct
18 Correct 29 ms 3420 KB Output is correct
19 Correct 17 ms 3164 KB Output is correct
20 Correct 22 ms 3212 KB Output is correct
21 Correct 18 ms 3164 KB Output is correct
22 Correct 38 ms 6224 KB Output is correct
23 Correct 4 ms 856 KB Output is correct
24 Correct 16 ms 1884 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 4 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 372 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 27 ms 2652 KB Output is correct
18 Correct 29 ms 3420 KB Output is correct
19 Correct 17 ms 3164 KB Output is correct
20 Correct 22 ms 3212 KB Output is correct
21 Correct 18 ms 3164 KB Output is correct
22 Correct 38 ms 6224 KB Output is correct
23 Correct 4 ms 856 KB Output is correct
24 Correct 16 ms 1884 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 4 ms 860 KB Output is correct
27 Correct 2 ms 1116 KB Output is correct
28 Correct 151 ms 13436 KB Output is correct
29 Correct 191 ms 17684 KB Output is correct
30 Correct 148 ms 16768 KB Output is correct
31 Correct 158 ms 16980 KB Output is correct
32 Correct 207 ms 19028 KB Output is correct
33 Correct 152 ms 17016 KB Output is correct
34 Correct 155 ms 17212 KB Output is correct
35 Correct 52 ms 7764 KB Output is correct
36 Correct 181 ms 19028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 25420 KB Output is correct
2 Correct 27 ms 25420 KB Output is correct
3 Correct 52 ms 25840 KB Output is correct
4 Correct 43 ms 27008 KB Output is correct
5 Correct 79 ms 31024 KB Output is correct
6 Correct 71 ms 30380 KB Output is correct
7 Correct 69 ms 31036 KB Output is correct
8 Correct 73 ms 30940 KB Output is correct
9 Correct 67 ms 30788 KB Output is correct
10 Correct 48 ms 19376 KB Output is correct
11 Correct 107 ms 38716 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 32 ms 25320 KB Output is correct
19 Correct 34 ms 25420 KB Output is correct
20 Correct 35 ms 25416 KB Output is correct
21 Correct 27 ms 25360 KB Output is correct
22 Correct 79 ms 32176 KB Output is correct
23 Correct 127 ms 38720 KB Output is correct
24 Correct 123 ms 39112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 27292 KB Output is correct
2 Correct 57 ms 32076 KB Output is correct
3 Correct 27 ms 25388 KB Output is correct
4 Correct 26 ms 25420 KB Output is correct
5 Correct 153 ms 45368 KB Output is correct
6 Correct 145 ms 49732 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 87 ms 31124 KB Output is correct
9 Correct 106 ms 37956 KB Output is correct
10 Correct 50 ms 29848 KB Output is correct
11 Correct 69 ms 32068 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 440 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 30 ms 25408 KB Output is correct
17 Correct 26 ms 25420 KB Output is correct
18 Correct 64 ms 28724 KB Output is correct
19 Correct 82 ms 31944 KB Output is correct
20 Correct 55 ms 29076 KB Output is correct
21 Correct 61 ms 31812 KB Output is correct
22 Correct 57 ms 29012 KB Output is correct
23 Correct 59 ms 31812 KB Output is correct
24 Correct 26 ms 25420 KB Output is correct
25 Correct 27 ms 25420 KB Output is correct
26 Correct 52 ms 25840 KB Output is correct
27 Correct 43 ms 27008 KB Output is correct
28 Correct 79 ms 31024 KB Output is correct
29 Correct 71 ms 30380 KB Output is correct
30 Correct 69 ms 31036 KB Output is correct
31 Correct 73 ms 30940 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 1 ms 372 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 1 ms 348 KB Output is correct
48 Correct 27 ms 2652 KB Output is correct
49 Correct 29 ms 3420 KB Output is correct
50 Correct 17 ms 3164 KB Output is correct
51 Correct 22 ms 3212 KB Output is correct
52 Correct 18 ms 3164 KB Output is correct
53 Correct 38 ms 6224 KB Output is correct
54 Correct 4 ms 856 KB Output is correct
55 Correct 16 ms 1884 KB Output is correct
56 Correct 1 ms 344 KB Output is correct
57 Correct 4 ms 860 KB Output is correct
58 Correct 2 ms 1116 KB Output is correct
59 Correct 151 ms 13436 KB Output is correct
60 Correct 191 ms 17684 KB Output is correct
61 Correct 148 ms 16768 KB Output is correct
62 Correct 158 ms 16980 KB Output is correct
63 Correct 207 ms 19028 KB Output is correct
64 Correct 152 ms 17016 KB Output is correct
65 Correct 155 ms 17212 KB Output is correct
66 Correct 52 ms 7764 KB Output is correct
67 Correct 181 ms 19028 KB Output is correct
68 Correct 67 ms 30788 KB Output is correct
69 Correct 48 ms 19376 KB Output is correct
70 Correct 107 ms 38716 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 0 ms 348 KB Output is correct
74 Correct 0 ms 348 KB Output is correct
75 Correct 0 ms 348 KB Output is correct
76 Correct 0 ms 348 KB Output is correct
77 Correct 32 ms 25320 KB Output is correct
78 Correct 34 ms 25420 KB Output is correct
79 Correct 35 ms 25416 KB Output is correct
80 Correct 27 ms 25360 KB Output is correct
81 Correct 79 ms 32176 KB Output is correct
82 Correct 127 ms 38720 KB Output is correct
83 Correct 123 ms 39112 KB Output is correct
84 Correct 201 ms 44948 KB Output is correct
85 Correct 211 ms 46656 KB Output is correct
86 Correct 183 ms 44692 KB Output is correct
87 Correct 193 ms 47172 KB Output is correct
88 Correct 1 ms 348 KB Output is correct
89 Correct 207 ms 46916 KB Output is correct
90 Correct 186 ms 46068 KB Output is correct
91 Correct 148 ms 46164 KB Output is correct