Submission #788575

# Submission time Handle Problem Language Result Execution time Memory
788575 2023-07-20T11:20:15 Z mosiashvililuka Catfish Farm (IOI22_fish) C++17
100 / 100
258 ms 73724 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; 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);
        }
        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++){
        cout<<i<<":\n";
        for(j=0; j<dp0[i].size(); j++){
            cout<<"dp0 "<<i<<" "<<j<<":  "<<dp0[i][j].first<<" "<<dp0[i][j].second<<"\n";
        }
        cout<<"\n";
        for(j=0; j<dp1[i].size(); j++){
            cout<<"dp1 "<<i<<" "<<j<<":  "<<dp1[i][j].first<<" "<<dp1[i][j].second<<"\n";
        }
        cout<<"----------------------------------------------------------\n";
    }*/

    for(i=1; i<=a; i++){
        for(j=0; j<dp0[i].size(); j++){
            pas=max(pas,dp0[i][j].second);
        }
        for(j=0; j<dp1[i].size(); j++){
            pas=max(pas,dp1[i][j].second);
        }
    }

    /*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:50: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]
   50 |         for(j=0; j<dp0[i-1].size(); j++){
      |                  ~^~~~~~~~~~~~~~~~
fish.cpp:51: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]
   51 |             while(ii+1<pr[i].size()&&pr[i][ii+1].first<=dp0[i-1][j].first) ii++;
      |                   ~~~~^~~~~~~~~~~~~
fish.cpp:55: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]
   55 |         for(j=0; j<dp1[i-1].size(); j++){
      |                  ~^~~~~~~~~~~~~~~~
fish.cpp:56: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]
   56 |             while(ii+1<pr[i-1].size()&&pr[i-1][ii+1].first<=dp1[i-1][j].first) ii++;
      |                   ~~~~^~~~~~~~~~~~~~~
fish.cpp:61: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]
   61 |         for(j=0; j<dp1[i].size(); j++){
      |                  ~^~~~~~~~~~~~~~
fish.cpp:62: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]
   62 |             while(ii+1<pr[i-1].size()&&pr[i-1][ii+1].first<=dp1[i][j].first) ii++;
      |                   ~~~~^~~~~~~~~~~~~~~
fish.cpp:69: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]
   69 |         for(j=0; j<dp0[i].size(); j++){
      |                  ~^~~~~~~~~~~~~~
fish.cpp:71: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]
   71 |             while(ii+1<pr[i].size()&&pr[i][ii+1].first<=dp0[i][j].first) ii++;
      |                   ~~~~^~~~~~~~~~~~~
fish.cpp:91: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]
   91 |         for(j=0; j<dp0[i].size(); j++){
      |                  ~^~~~~~~~~~~~~~
fish.cpp:94: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]
   94 |         for(j=0; j<dp1[i].size(); j++){
      |                  ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 66 ms 39576 KB Output is correct
2 Correct 77 ms 42548 KB Output is correct
3 Correct 27 ms 33224 KB Output is correct
4 Correct 27 ms 33216 KB Output is correct
5 Correct 184 ms 61456 KB Output is correct
6 Correct 243 ms 68652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 21400 KB Output is correct
2 Correct 107 ms 50032 KB Output is correct
3 Correct 128 ms 55524 KB Output is correct
4 Correct 70 ms 41000 KB Output is correct
5 Correct 77 ms 44320 KB Output is correct
6 Correct 10 ms 21460 KB Output is correct
7 Correct 12 ms 21444 KB Output is correct
8 Correct 10 ms 21452 KB Output is correct
9 Correct 10 ms 21460 KB Output is correct
10 Correct 29 ms 33188 KB Output is correct
11 Correct 27 ms 33236 KB Output is correct
12 Correct 66 ms 41028 KB Output is correct
13 Correct 82 ms 44324 KB Output is correct
14 Correct 65 ms 40988 KB Output is correct
15 Correct 72 ms 43280 KB Output is correct
16 Correct 66 ms 41056 KB Output is correct
17 Correct 71 ms 43164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 33144 KB Output is correct
2 Correct 28 ms 33236 KB Output is correct
3 Correct 68 ms 37992 KB Output is correct
4 Correct 52 ms 37124 KB Output is correct
5 Correct 109 ms 44216 KB Output is correct
6 Correct 100 ms 43532 KB Output is correct
7 Correct 104 ms 44244 KB Output is correct
8 Correct 140 ms 44220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 21464 KB Output is correct
2 Correct 11 ms 21464 KB Output is correct
3 Correct 10 ms 21460 KB Output is correct
4 Correct 10 ms 21448 KB Output is correct
5 Correct 10 ms 21460 KB Output is correct
6 Correct 10 ms 21388 KB Output is correct
7 Correct 10 ms 21368 KB Output is correct
8 Correct 10 ms 21448 KB Output is correct
9 Correct 10 ms 21588 KB Output is correct
10 Correct 11 ms 21844 KB Output is correct
11 Correct 10 ms 21552 KB Output is correct
12 Correct 14 ms 21684 KB Output is correct
13 Correct 10 ms 21460 KB Output is correct
14 Correct 11 ms 21552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 21464 KB Output is correct
2 Correct 11 ms 21464 KB Output is correct
3 Correct 10 ms 21460 KB Output is correct
4 Correct 10 ms 21448 KB Output is correct
5 Correct 10 ms 21460 KB Output is correct
6 Correct 10 ms 21388 KB Output is correct
7 Correct 10 ms 21368 KB Output is correct
8 Correct 10 ms 21448 KB Output is correct
9 Correct 10 ms 21588 KB Output is correct
10 Correct 11 ms 21844 KB Output is correct
11 Correct 10 ms 21552 KB Output is correct
12 Correct 14 ms 21684 KB Output is correct
13 Correct 10 ms 21460 KB Output is correct
14 Correct 11 ms 21552 KB Output is correct
15 Correct 11 ms 21584 KB Output is correct
16 Correct 11 ms 21700 KB Output is correct
17 Correct 27 ms 26840 KB Output is correct
18 Correct 29 ms 28752 KB Output is correct
19 Correct 28 ms 28208 KB Output is correct
20 Correct 29 ms 28244 KB Output is correct
21 Correct 29 ms 28244 KB Output is correct
22 Correct 53 ms 35132 KB Output is correct
23 Correct 16 ms 22812 KB Output is correct
24 Correct 22 ms 25428 KB Output is correct
25 Correct 11 ms 21588 KB Output is correct
26 Correct 14 ms 22696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 21464 KB Output is correct
2 Correct 11 ms 21464 KB Output is correct
3 Correct 10 ms 21460 KB Output is correct
4 Correct 10 ms 21448 KB Output is correct
5 Correct 10 ms 21460 KB Output is correct
6 Correct 10 ms 21388 KB Output is correct
7 Correct 10 ms 21368 KB Output is correct
8 Correct 10 ms 21448 KB Output is correct
9 Correct 10 ms 21588 KB Output is correct
10 Correct 11 ms 21844 KB Output is correct
11 Correct 10 ms 21552 KB Output is correct
12 Correct 14 ms 21684 KB Output is correct
13 Correct 10 ms 21460 KB Output is correct
14 Correct 11 ms 21552 KB Output is correct
15 Correct 11 ms 21584 KB Output is correct
16 Correct 11 ms 21700 KB Output is correct
17 Correct 27 ms 26840 KB Output is correct
18 Correct 29 ms 28752 KB Output is correct
19 Correct 28 ms 28208 KB Output is correct
20 Correct 29 ms 28244 KB Output is correct
21 Correct 29 ms 28244 KB Output is correct
22 Correct 53 ms 35132 KB Output is correct
23 Correct 16 ms 22812 KB Output is correct
24 Correct 22 ms 25428 KB Output is correct
25 Correct 11 ms 21588 KB Output is correct
26 Correct 14 ms 22696 KB Output is correct
27 Correct 13 ms 22228 KB Output is correct
28 Correct 100 ms 52632 KB Output is correct
29 Correct 147 ms 62956 KB Output is correct
30 Correct 142 ms 60896 KB Output is correct
31 Correct 137 ms 60924 KB Output is correct
32 Correct 136 ms 66124 KB Output is correct
33 Correct 137 ms 60912 KB Output is correct
34 Correct 144 ms 60912 KB Output is correct
35 Correct 60 ms 38160 KB Output is correct
36 Correct 140 ms 66300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 33144 KB Output is correct
2 Correct 28 ms 33236 KB Output is correct
3 Correct 68 ms 37992 KB Output is correct
4 Correct 52 ms 37124 KB Output is correct
5 Correct 109 ms 44216 KB Output is correct
6 Correct 100 ms 43532 KB Output is correct
7 Correct 104 ms 44244 KB Output is correct
8 Correct 140 ms 44220 KB Output is correct
9 Correct 101 ms 43940 KB Output is correct
10 Correct 74 ms 42056 KB Output is correct
11 Correct 175 ms 62828 KB Output is correct
12 Correct 10 ms 21460 KB Output is correct
13 Correct 10 ms 21444 KB Output is correct
14 Correct 10 ms 21460 KB Output is correct
15 Correct 10 ms 21460 KB Output is correct
16 Correct 9 ms 21444 KB Output is correct
17 Correct 10 ms 21392 KB Output is correct
18 Correct 26 ms 33240 KB Output is correct
19 Correct 27 ms 33108 KB Output is correct
20 Correct 32 ms 33236 KB Output is correct
21 Correct 26 ms 33172 KB Output is correct
22 Correct 95 ms 46296 KB Output is correct
23 Correct 172 ms 62764 KB Output is correct
24 Correct 179 ms 63308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 39576 KB Output is correct
2 Correct 77 ms 42548 KB Output is correct
3 Correct 27 ms 33224 KB Output is correct
4 Correct 27 ms 33216 KB Output is correct
5 Correct 184 ms 61456 KB Output is correct
6 Correct 243 ms 68652 KB Output is correct
7 Correct 10 ms 21400 KB Output is correct
8 Correct 107 ms 50032 KB Output is correct
9 Correct 128 ms 55524 KB Output is correct
10 Correct 70 ms 41000 KB Output is correct
11 Correct 77 ms 44320 KB Output is correct
12 Correct 10 ms 21460 KB Output is correct
13 Correct 12 ms 21444 KB Output is correct
14 Correct 10 ms 21452 KB Output is correct
15 Correct 10 ms 21460 KB Output is correct
16 Correct 29 ms 33188 KB Output is correct
17 Correct 27 ms 33236 KB Output is correct
18 Correct 66 ms 41028 KB Output is correct
19 Correct 82 ms 44324 KB Output is correct
20 Correct 65 ms 40988 KB Output is correct
21 Correct 72 ms 43280 KB Output is correct
22 Correct 66 ms 41056 KB Output is correct
23 Correct 71 ms 43164 KB Output is correct
24 Correct 26 ms 33144 KB Output is correct
25 Correct 28 ms 33236 KB Output is correct
26 Correct 68 ms 37992 KB Output is correct
27 Correct 52 ms 37124 KB Output is correct
28 Correct 109 ms 44216 KB Output is correct
29 Correct 100 ms 43532 KB Output is correct
30 Correct 104 ms 44244 KB Output is correct
31 Correct 140 ms 44220 KB Output is correct
32 Correct 11 ms 21464 KB Output is correct
33 Correct 11 ms 21464 KB Output is correct
34 Correct 10 ms 21460 KB Output is correct
35 Correct 10 ms 21448 KB Output is correct
36 Correct 10 ms 21460 KB Output is correct
37 Correct 10 ms 21388 KB Output is correct
38 Correct 10 ms 21368 KB Output is correct
39 Correct 10 ms 21448 KB Output is correct
40 Correct 10 ms 21588 KB Output is correct
41 Correct 11 ms 21844 KB Output is correct
42 Correct 10 ms 21552 KB Output is correct
43 Correct 14 ms 21684 KB Output is correct
44 Correct 10 ms 21460 KB Output is correct
45 Correct 11 ms 21552 KB Output is correct
46 Correct 11 ms 21584 KB Output is correct
47 Correct 11 ms 21700 KB Output is correct
48 Correct 27 ms 26840 KB Output is correct
49 Correct 29 ms 28752 KB Output is correct
50 Correct 28 ms 28208 KB Output is correct
51 Correct 29 ms 28244 KB Output is correct
52 Correct 29 ms 28244 KB Output is correct
53 Correct 53 ms 35132 KB Output is correct
54 Correct 16 ms 22812 KB Output is correct
55 Correct 22 ms 25428 KB Output is correct
56 Correct 11 ms 21588 KB Output is correct
57 Correct 14 ms 22696 KB Output is correct
58 Correct 13 ms 22228 KB Output is correct
59 Correct 100 ms 52632 KB Output is correct
60 Correct 147 ms 62956 KB Output is correct
61 Correct 142 ms 60896 KB Output is correct
62 Correct 137 ms 60924 KB Output is correct
63 Correct 136 ms 66124 KB Output is correct
64 Correct 137 ms 60912 KB Output is correct
65 Correct 144 ms 60912 KB Output is correct
66 Correct 60 ms 38160 KB Output is correct
67 Correct 140 ms 66300 KB Output is correct
68 Correct 101 ms 43940 KB Output is correct
69 Correct 74 ms 42056 KB Output is correct
70 Correct 175 ms 62828 KB Output is correct
71 Correct 10 ms 21460 KB Output is correct
72 Correct 10 ms 21444 KB Output is correct
73 Correct 10 ms 21460 KB Output is correct
74 Correct 10 ms 21460 KB Output is correct
75 Correct 9 ms 21444 KB Output is correct
76 Correct 10 ms 21392 KB Output is correct
77 Correct 26 ms 33240 KB Output is correct
78 Correct 27 ms 33108 KB Output is correct
79 Correct 32 ms 33236 KB Output is correct
80 Correct 26 ms 33172 KB Output is correct
81 Correct 95 ms 46296 KB Output is correct
82 Correct 172 ms 62764 KB Output is correct
83 Correct 179 ms 63308 KB Output is correct
84 Correct 177 ms 67288 KB Output is correct
85 Correct 179 ms 67476 KB Output is correct
86 Correct 257 ms 72548 KB Output is correct
87 Correct 258 ms 73724 KB Output is correct
88 Correct 10 ms 21448 KB Output is correct
89 Correct 247 ms 73700 KB Output is correct
90 Correct 201 ms 72356 KB Output is correct
91 Correct 201 ms 73072 KB Output is correct