Submission #788577

# Submission time Handle Problem Language Result Execution time Memory
788577 2023-07-20T11:21:26 Z mosiashvililuka Catfish Farm (IOI22_fish) C++17
100 / 100
278 ms 67804 KB
#include<bits/stdc++.h>
#include "fish.h"
using namespace std;
const long long N=999999999999999999LL;
long long a,b,c,d,e,i,j,ii,jj,zx,xc,X[300009],Y[300009],W[300009],DP0[300009],DP1[300009],best[300009],pas;
vector <pair <long long, long long> > dp0[300009],dp1[300009],pr[300009];
long long max_weights(int NN, int MM, std::vector<int> XX, std::vector<int> YY, std::vector<int> WW) {
    a=NN;b=MM;
    for(i=0; i<b; i++){
        XX[i]++;YY[i]++;
        X[i+1]=XX[i];Y[i+1]=YY[i];W[i+1]=WW[i];
    }

    for(i=1; i<=b; i++){
        //if(Y[i]!=1){
            dp0[X[i]].push_back({Y[i]-1,0});
            dp1[X[i]].push_back({Y[i]-1,0});
        //}
        pr[X[i]].push_back({Y[i],W[i]});
    }

    for(i=0; i<=a; i++){
        if(i!=0){
            dp0[i].push_back({a+4,0});
            dp1[i].push_back({a+4,0});
        }
        /*dp0[i].push_back({0,0});
        dp1[i].push_back({0,0});*/
        pr[i].push_back({0,0});
    }

    for(i=0; i<=a; i++){
        sort(dp0[i].begin(),dp0[i].end());
        sort(dp1[i].begin(),dp1[i].end());
        sort(pr[i].begin(),pr[i].end());
        for(j=1; j<pr[i].size(); j++){
            pr[i][j].second+=pr[i][j-1].second;
        }
    }
    //return max(pr[1].back().second,pr[2].back().second);

    for(i=1; i<=a+1; i++){
        //DP0[i-1] DP1[i-1] best[i-1]
        DP0[i-1]=-N;
        DP1[i-1]=-N;
        for(j=0; j<dp0[i-1].size(); j++){
            best[i-1]=max(best[i-1],dp0[i-1][j].second);
        }
        if(i==a+1) break;
        ii=0;
        for(j=0; j<dp0[i-1].size(); j++){
            while(ii+1<pr[i].size()&&pr[i][ii+1].first<=dp0[i-1][j].first) ii++;
            DP0[i-1]=max(DP0[i-1],dp0[i-1][j].second+pr[i][ii].second);
        }
        ii=0;
        for(j=0; j<dp1[i-1].size(); j++){
            while(ii+1<pr[i-1].size()&&pr[i-1][ii+1].first<=dp1[i-1][j].first) ii++;
            DP1[i-1]=max(DP1[i-1],dp1[i-1][j].second-pr[i-1][ii].second);
        }
        //dp1[i]
        ii=0;
        for(j=0; j<dp1[i].size(); j++){
            while(ii+1<pr[i-1].size()&&pr[i-1][ii+1].first<=dp1[i][j].first) ii++;
            dp1[i][j].second=pr[i-1][ii].second+DP1[i-1];
            dp1[i][j].second=max(dp1[i][j].second,best[i-1]);
        }

        //dp0[i]
        ii=0;
        for(j=0; j<dp0[i].size(); j++){
            dp0[i][j].second=dp1[i][j].second;
            while(ii+1<pr[i].size()&&pr[i][ii+1].first<=dp0[i][j].first) ii++;
            zx=-pr[i][ii].second+DP0[i-1];
            dp0[i][j].second=max(dp0[i][j].second,zx);
        }
    }

    for(i=1; i<=a; i++){
        pas=max(pas,best[i]);
    }
    return pas;
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:36:19: 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]
   36 |         for(j=1; j<pr[i].size(); j++){
      |                  ~^~~~~~~~~~~~~
fish.cpp:46:19: 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]
   46 |         for(j=0; j<dp0[i-1].size(); j++){
      |                  ~^~~~~~~~~~~~~~~~
fish.cpp:51:19: 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]
   51 |         for(j=0; j<dp0[i-1].size(); j++){
      |                  ~^~~~~~~~~~~~~~~~
fish.cpp:52:23: 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]
   52 |             while(ii+1<pr[i].size()&&pr[i][ii+1].first<=dp0[i-1][j].first) ii++;
      |                   ~~~~^~~~~~~~~~~~~
fish.cpp:56:19: 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]
   56 |         for(j=0; j<dp1[i-1].size(); j++){
      |                  ~^~~~~~~~~~~~~~~~
fish.cpp:57:23: 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]
   57 |             while(ii+1<pr[i-1].size()&&pr[i-1][ii+1].first<=dp1[i-1][j].first) ii++;
      |                   ~~~~^~~~~~~~~~~~~~~
fish.cpp:62:19: 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]
   62 |         for(j=0; j<dp1[i].size(); j++){
      |                  ~^~~~~~~~~~~~~~
fish.cpp:63:23: 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]
   63 |             while(ii+1<pr[i-1].size()&&pr[i-1][ii+1].first<=dp1[i][j].first) ii++;
      |                   ~~~~^~~~~~~~~~~~~~~
fish.cpp:70:19: 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]
   70 |         for(j=0; j<dp0[i].size(); j++){
      |                  ~^~~~~~~~~~~~~~
fish.cpp:72:23: 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]
   72 |             while(ii+1<pr[i].size()&&pr[i][ii+1].first<=dp0[i][j].first) ii++;
      |                   ~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 67 ms 39572 KB Output is correct
2 Correct 86 ms 42580 KB Output is correct
3 Correct 29 ms 33132 KB Output is correct
4 Correct 28 ms 33124 KB Output is correct
5 Correct 181 ms 61448 KB Output is correct
6 Correct 235 ms 67332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 21460 KB Output is correct
2 Correct 116 ms 47356 KB Output is correct
3 Correct 148 ms 52008 KB Output is correct
4 Correct 67 ms 39644 KB Output is correct
5 Correct 78 ms 42536 KB Output is correct
6 Correct 9 ms 21460 KB Output is correct
7 Correct 9 ms 21460 KB Output is correct
8 Correct 10 ms 21372 KB Output is correct
9 Correct 10 ms 21436 KB Output is correct
10 Correct 28 ms 33284 KB Output is correct
11 Correct 31 ms 33216 KB Output is correct
12 Correct 76 ms 39624 KB Output is correct
13 Correct 78 ms 42560 KB Output is correct
14 Correct 66 ms 39672 KB Output is correct
15 Correct 76 ms 41680 KB Output is correct
16 Correct 67 ms 39700 KB Output is correct
17 Correct 73 ms 41640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 33156 KB Output is correct
2 Correct 27 ms 33172 KB Output is correct
3 Correct 57 ms 37044 KB Output is correct
4 Correct 50 ms 36576 KB Output is correct
5 Correct 103 ms 42596 KB Output is correct
6 Correct 136 ms 42628 KB Output is correct
7 Correct 106 ms 42596 KB Output is correct
8 Correct 113 ms 42584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 21488 KB Output is correct
2 Correct 10 ms 21392 KB Output is correct
3 Correct 10 ms 21460 KB Output is correct
4 Correct 11 ms 21448 KB Output is correct
5 Correct 10 ms 21460 KB Output is correct
6 Correct 10 ms 21440 KB Output is correct
7 Correct 13 ms 21460 KB Output is correct
8 Correct 11 ms 21484 KB Output is correct
9 Correct 11 ms 21588 KB Output is correct
10 Correct 12 ms 21844 KB Output is correct
11 Correct 11 ms 21624 KB Output is correct
12 Correct 11 ms 21588 KB Output is correct
13 Correct 14 ms 21460 KB Output is correct
14 Correct 11 ms 21588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 21488 KB Output is correct
2 Correct 10 ms 21392 KB Output is correct
3 Correct 10 ms 21460 KB Output is correct
4 Correct 11 ms 21448 KB Output is correct
5 Correct 10 ms 21460 KB Output is correct
6 Correct 10 ms 21440 KB Output is correct
7 Correct 13 ms 21460 KB Output is correct
8 Correct 11 ms 21484 KB Output is correct
9 Correct 11 ms 21588 KB Output is correct
10 Correct 12 ms 21844 KB Output is correct
11 Correct 11 ms 21624 KB Output is correct
12 Correct 11 ms 21588 KB Output is correct
13 Correct 14 ms 21460 KB Output is correct
14 Correct 11 ms 21588 KB Output is correct
15 Correct 11 ms 21460 KB Output is correct
16 Correct 12 ms 21664 KB Output is correct
17 Correct 30 ms 26092 KB Output is correct
18 Correct 31 ms 27988 KB Output is correct
19 Correct 28 ms 27572 KB Output is correct
20 Correct 31 ms 27600 KB Output is correct
21 Correct 30 ms 27596 KB Output is correct
22 Correct 47 ms 33480 KB Output is correct
23 Correct 14 ms 22612 KB Output is correct
24 Correct 22 ms 24916 KB Output is correct
25 Correct 11 ms 21588 KB Output is correct
26 Correct 14 ms 22440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 21488 KB Output is correct
2 Correct 10 ms 21392 KB Output is correct
3 Correct 10 ms 21460 KB Output is correct
4 Correct 11 ms 21448 KB Output is correct
5 Correct 10 ms 21460 KB Output is correct
6 Correct 10 ms 21440 KB Output is correct
7 Correct 13 ms 21460 KB Output is correct
8 Correct 11 ms 21484 KB Output is correct
9 Correct 11 ms 21588 KB Output is correct
10 Correct 12 ms 21844 KB Output is correct
11 Correct 11 ms 21624 KB Output is correct
12 Correct 11 ms 21588 KB Output is correct
13 Correct 14 ms 21460 KB Output is correct
14 Correct 11 ms 21588 KB Output is correct
15 Correct 11 ms 21460 KB Output is correct
16 Correct 12 ms 21664 KB Output is correct
17 Correct 30 ms 26092 KB Output is correct
18 Correct 31 ms 27988 KB Output is correct
19 Correct 28 ms 27572 KB Output is correct
20 Correct 31 ms 27600 KB Output is correct
21 Correct 30 ms 27596 KB Output is correct
22 Correct 47 ms 33480 KB Output is correct
23 Correct 14 ms 22612 KB Output is correct
24 Correct 22 ms 24916 KB Output is correct
25 Correct 11 ms 21588 KB Output is correct
26 Correct 14 ms 22440 KB Output is correct
27 Correct 11 ms 22168 KB Output is correct
28 Correct 102 ms 48896 KB Output is correct
29 Correct 149 ms 57436 KB Output is correct
30 Correct 136 ms 55308 KB Output is correct
31 Correct 137 ms 55308 KB Output is correct
32 Correct 135 ms 60996 KB Output is correct
33 Correct 142 ms 55392 KB Output is correct
34 Correct 136 ms 55288 KB Output is correct
35 Correct 70 ms 36128 KB Output is correct
36 Correct 165 ms 60804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 33156 KB Output is correct
2 Correct 27 ms 33172 KB Output is correct
3 Correct 57 ms 37044 KB Output is correct
4 Correct 50 ms 36576 KB Output is correct
5 Correct 103 ms 42596 KB Output is correct
6 Correct 136 ms 42628 KB Output is correct
7 Correct 106 ms 42596 KB Output is correct
8 Correct 113 ms 42584 KB Output is correct
9 Correct 99 ms 42592 KB Output is correct
10 Correct 82 ms 40292 KB Output is correct
11 Correct 160 ms 59264 KB Output is correct
12 Correct 9 ms 21436 KB Output is correct
13 Correct 9 ms 21484 KB Output is correct
14 Correct 9 ms 21460 KB Output is correct
15 Correct 9 ms 21460 KB Output is correct
16 Correct 12 ms 21436 KB Output is correct
17 Correct 9 ms 21460 KB Output is correct
18 Correct 36 ms 33216 KB Output is correct
19 Correct 28 ms 33152 KB Output is correct
20 Correct 26 ms 33100 KB Output is correct
21 Correct 26 ms 33124 KB Output is correct
22 Correct 88 ms 44140 KB Output is correct
23 Correct 164 ms 59292 KB Output is correct
24 Correct 165 ms 59340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 39572 KB Output is correct
2 Correct 86 ms 42580 KB Output is correct
3 Correct 29 ms 33132 KB Output is correct
4 Correct 28 ms 33124 KB Output is correct
5 Correct 181 ms 61448 KB Output is correct
6 Correct 235 ms 67332 KB Output is correct
7 Correct 10 ms 21460 KB Output is correct
8 Correct 116 ms 47356 KB Output is correct
9 Correct 148 ms 52008 KB Output is correct
10 Correct 67 ms 39644 KB Output is correct
11 Correct 78 ms 42536 KB Output is correct
12 Correct 9 ms 21460 KB Output is correct
13 Correct 9 ms 21460 KB Output is correct
14 Correct 10 ms 21372 KB Output is correct
15 Correct 10 ms 21436 KB Output is correct
16 Correct 28 ms 33284 KB Output is correct
17 Correct 31 ms 33216 KB Output is correct
18 Correct 76 ms 39624 KB Output is correct
19 Correct 78 ms 42560 KB Output is correct
20 Correct 66 ms 39672 KB Output is correct
21 Correct 76 ms 41680 KB Output is correct
22 Correct 67 ms 39700 KB Output is correct
23 Correct 73 ms 41640 KB Output is correct
24 Correct 27 ms 33156 KB Output is correct
25 Correct 27 ms 33172 KB Output is correct
26 Correct 57 ms 37044 KB Output is correct
27 Correct 50 ms 36576 KB Output is correct
28 Correct 103 ms 42596 KB Output is correct
29 Correct 136 ms 42628 KB Output is correct
30 Correct 106 ms 42596 KB Output is correct
31 Correct 113 ms 42584 KB Output is correct
32 Correct 10 ms 21488 KB Output is correct
33 Correct 10 ms 21392 KB Output is correct
34 Correct 10 ms 21460 KB Output is correct
35 Correct 11 ms 21448 KB Output is correct
36 Correct 10 ms 21460 KB Output is correct
37 Correct 10 ms 21440 KB Output is correct
38 Correct 13 ms 21460 KB Output is correct
39 Correct 11 ms 21484 KB Output is correct
40 Correct 11 ms 21588 KB Output is correct
41 Correct 12 ms 21844 KB Output is correct
42 Correct 11 ms 21624 KB Output is correct
43 Correct 11 ms 21588 KB Output is correct
44 Correct 14 ms 21460 KB Output is correct
45 Correct 11 ms 21588 KB Output is correct
46 Correct 11 ms 21460 KB Output is correct
47 Correct 12 ms 21664 KB Output is correct
48 Correct 30 ms 26092 KB Output is correct
49 Correct 31 ms 27988 KB Output is correct
50 Correct 28 ms 27572 KB Output is correct
51 Correct 31 ms 27600 KB Output is correct
52 Correct 30 ms 27596 KB Output is correct
53 Correct 47 ms 33480 KB Output is correct
54 Correct 14 ms 22612 KB Output is correct
55 Correct 22 ms 24916 KB Output is correct
56 Correct 11 ms 21588 KB Output is correct
57 Correct 14 ms 22440 KB Output is correct
58 Correct 11 ms 22168 KB Output is correct
59 Correct 102 ms 48896 KB Output is correct
60 Correct 149 ms 57436 KB Output is correct
61 Correct 136 ms 55308 KB Output is correct
62 Correct 137 ms 55308 KB Output is correct
63 Correct 135 ms 60996 KB Output is correct
64 Correct 142 ms 55392 KB Output is correct
65 Correct 136 ms 55288 KB Output is correct
66 Correct 70 ms 36128 KB Output is correct
67 Correct 165 ms 60804 KB Output is correct
68 Correct 99 ms 42592 KB Output is correct
69 Correct 82 ms 40292 KB Output is correct
70 Correct 160 ms 59264 KB Output is correct
71 Correct 9 ms 21436 KB Output is correct
72 Correct 9 ms 21484 KB Output is correct
73 Correct 9 ms 21460 KB Output is correct
74 Correct 9 ms 21460 KB Output is correct
75 Correct 12 ms 21436 KB Output is correct
76 Correct 9 ms 21460 KB Output is correct
77 Correct 36 ms 33216 KB Output is correct
78 Correct 28 ms 33152 KB Output is correct
79 Correct 26 ms 33100 KB Output is correct
80 Correct 26 ms 33124 KB Output is correct
81 Correct 88 ms 44140 KB Output is correct
82 Correct 164 ms 59292 KB Output is correct
83 Correct 165 ms 59340 KB Output is correct
84 Correct 197 ms 61524 KB Output is correct
85 Correct 219 ms 62300 KB Output is correct
86 Correct 273 ms 66576 KB Output is correct
87 Correct 278 ms 67640 KB Output is correct
88 Correct 11 ms 21460 KB Output is correct
89 Correct 262 ms 67612 KB Output is correct
90 Correct 229 ms 67360 KB Output is correct
91 Correct 237 ms 67804 KB Output is correct