답안 #645996

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
645996 2022-09-28T12:57:59 Z mosiashvililuka 메기 농장 (IOI22_fish) C++17
100 / 100
507 ms 87788 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,M,ANS;
vector <pair <long long, long long> > fish[100009],JM[100009];
vector <long long> v[100009],dp[100009],dp2[100009],jm[100009],f[100009];
long long max_weights(int NN, int MM, std::vector<int> XX, std::vector<int> YY, std::vector<int> WW) {
    a=NN;M=MM;
    for(i=1; i<=M; i++){
        fish[XX[i-1]+1].push_back({YY[i-1]+1,WW[i-1]});
    }
    for(i=1; i<=a; i++){
        fish[i].push_back({0,0});
        sort(fish[i].begin(),fish[i].end());
    }
    for(i=1; i<=a; i++){
        v[i].push_back(0);
        for(j=0; j<fish[i-1].size(); j++){
            v[i].push_back(fish[i-1][j].first);
        }
        for(j=0; j<fish[i+1].size(); j++){
            v[i].push_back(fish[i+1][j].first);
        }
        sort(v[i].begin(),v[i].end());
        dp[i].resize(v[i].size());dp2[i].resize(v[i].size());
        jm[i].resize(v[i].size());f[i].resize(v[i].size());
        /*zx=0;
        for(j=0; j<v[i].size(); j++){
            zx+=v[i][j];
            jm[i][j]=zx;
        }*/

        JM[i].resize(fish[i].size());
        zx=0;
        for(j=0; j<JM[i].size(); j++){
            zx+=fish[i][j].second;
            JM[i][j]={fish[i][j].first,zx};
        }
        for(j=0; j<v[i].size(); j++){
            c=lower_bound(JM[i].begin(),JM[i].end(),make_pair(v[i][j]+1,0LL))-JM[i].begin();c--;
            if(c<0) continue;
            jm[i][j]=JM[i][c].second;
        }
    }
    /*for(i=1; i<=a; i++){
        cout<<i<<":\n";
        for(j=0; j<v[i].size(); j++){
            cout<<v[i][j]<<" "<<jm[i][j]<<"\n";
        }
    }*/
    for(i=2; i<=a; i++){
        zx=-N;
        for(j=0; j<v[i-1].size(); j++){
            zx=max(zx,dp[i-1][j]);
            f[i-1][j]=zx;
        }
        for(j=0; j<v[i].size(); j++){
            c=lower_bound(v[i-1].begin(),v[i-1].end(),v[i][j]+1)-v[i-1].begin();c--;
            dp2[i][j]=max(dp2[i][j],f[i-1][c]);
        }
        zx=-N;
        for(j=0; j<v[i-1].size(); j++){
            zx=max(zx,dp2[i-1][j]-jm[i-1][j]);
            f[i-1][j]=zx;
        }
        for(j=0; j<v[i].size(); j++){
            c=lower_bound(v[i-1].begin(),v[i-1].end(),v[i][j]+1)-v[i-1].begin();c--;
            d=lower_bound(JM[i-1].begin(),JM[i-1].end(),make_pair(v[i][j]+1,0LL))-JM[i-1].begin();d--;
            dp2[i][j]=max(dp2[i][j],f[i-1][c]+/*jm[i-1][c]*/JM[i-1][d].second);
        }
        zx=-N;e=v[i-1].size();
        for(j=e-1; j>=0; j--){
            zx=max(zx,max(dp[i-1][j],dp2[i-1][j]));
            f[i-1][j]=zx;
        }
        for(j=0; j<v[i].size(); j++){
            c=lower_bound(v[i-1].begin(),v[i-1].end(),v[i][j]+1)-v[i-1].begin();
            if(c>=v[i-1].size()) continue;
            dp2[i][j]=max(dp2[i][j],f[i-1][c]);
        }
        //
        //
        zx=-N;
        for(j=0; j<v[i-1].size(); j++){
            zx=max(zx,dp[i-1][j]);
            f[i-1][j]=zx;
        }
        for(j=0; j<v[i].size(); j++){
            c=lower_bound(v[i-1].begin(),v[i-1].end(),v[i][j]+1)-v[i-1].begin();c--;
            dp2[i][j]=max(dp2[i][j],f[i-1][c]);
        }
        zx=-N;
        for(j=0; j<v[i-1].size(); j++){
            zx=max(zx,dp2[i-1][j]-jm[i-1][j]);
            f[i-1][j]=zx;
        }
        for(j=0; j<v[i].size(); j++){
            c=lower_bound(v[i-1].begin(),v[i-1].end(),v[i][j]+1)-v[i-1].begin();c--;
            d=lower_bound(JM[i-1].begin(),JM[i-1].end(),make_pair(v[i][j]+1,0LL))-JM[i-1].begin();d--;
            dp2[i][j]=max(dp2[i][j],f[i-1][c]+/*jm[i-1][c]*/JM[i-1][d].second);
        }
        zx=-N;e=v[i-1].size();
        for(j=e-1; j>=0; j--){
            /*c=lower_bound(v[i].begin(),v[i].end(),v[i-1][j]+1)-v[i].begin();c--;
            xc=jm[i][c];*/
            d=lower_bound(JM[i].begin(),JM[i].end(),make_pair(v[i-1][j]+1,0LL))-JM[i].begin();d--;
            xc=JM[i][d].second;
            zx=max(zx,max(dp[i-1][j],dp2[i-1][j])+xc);
            f[i-1][j]=zx;
        }
        for(j=0; j<v[i].size(); j++){
            c=lower_bound(v[i-1].begin(),v[i-1].end(),v[i][j]+1)-v[i-1].begin();
            if(c>=v[i-1].size()) continue;
            dp[i][j]=max(dp[i][j],f[i-1][c]-jm[i][j]);
        }
    }
    ANS=-N;
    for(i=1; i<=a; i++){
        for(j=0; j<dp[i].size(); j++){
            ANS=max(ANS,dp[i][j]);
            ANS=max(ANS,dp2[i][j]);
        }
    }
    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:19: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]
   19 |         for(j=0; j<fish[i-1].size(); j++){
      |                  ~^~~~~~~~~~~~~~~~~
fish.cpp:22: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]
   22 |         for(j=0; j<fish[i+1].size(); j++){
      |                  ~^~~~~~~~~~~~~~~~~
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=0; j<JM[i].size(); j++){
      |                  ~^~~~~~~~~~~~~
fish.cpp:40:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         for(j=0; j<v[i].size(); j++){
      |                  ~^~~~~~~~~~~~
fish.cpp:54:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         for(j=0; j<v[i-1].size(); j++){
      |                  ~^~~~~~~~~~~~~~
fish.cpp:58:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |         for(j=0; j<v[i].size(); j++){
      |                  ~^~~~~~~~~~~~
fish.cpp:63:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |         for(j=0; j<v[i-1].size(); j++){
      |                  ~^~~~~~~~~~~~~~
fish.cpp:67:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |         for(j=0; j<v[i].size(); j++){
      |                  ~^~~~~~~~~~~~
fish.cpp:77:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |         for(j=0; j<v[i].size(); j++){
      |                  ~^~~~~~~~~~~~
fish.cpp:79:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |             if(c>=v[i-1].size()) continue;
      |                ~^~~~~~~~~~~~~~~
fish.cpp:85:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |         for(j=0; j<v[i-1].size(); j++){
      |                  ~^~~~~~~~~~~~~~
fish.cpp:89:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |         for(j=0; j<v[i].size(); j++){
      |                  ~^~~~~~~~~~~~
fish.cpp:94:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |         for(j=0; j<v[i-1].size(); j++){
      |                  ~^~~~~~~~~~~~~~
fish.cpp:98:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   98 |         for(j=0; j<v[i].size(); j++){
      |                  ~^~~~~~~~~~~~
fish.cpp:112:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  112 |         for(j=0; j<v[i].size(); j++){
      |                  ~^~~~~~~~~~~~
fish.cpp:114:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  114 |             if(c>=v[i-1].size()) continue;
      |                ~^~~~~~~~~~~~~~~
fish.cpp:120:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  120 |         for(j=0; j<dp[i].size(); j++){
      |                  ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 147 ms 46804 KB Output is correct
2 Correct 159 ms 51212 KB Output is correct
3 Correct 87 ms 40212 KB Output is correct
4 Correct 89 ms 40196 KB Output is correct
5 Correct 353 ms 82240 KB Output is correct
6 Correct 402 ms 87152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 16724 KB Output is correct
2 Correct 259 ms 58200 KB Output is correct
3 Correct 301 ms 64780 KB Output is correct
4 Correct 143 ms 46708 KB Output is correct
5 Correct 158 ms 51088 KB Output is correct
6 Correct 9 ms 16660 KB Output is correct
7 Correct 9 ms 16664 KB Output is correct
8 Correct 9 ms 16724 KB Output is correct
9 Correct 9 ms 16724 KB Output is correct
10 Correct 91 ms 40140 KB Output is correct
11 Correct 91 ms 40212 KB Output is correct
12 Correct 151 ms 49848 KB Output is correct
13 Correct 196 ms 55024 KB Output is correct
14 Correct 149 ms 48236 KB Output is correct
15 Correct 189 ms 51824 KB Output is correct
16 Correct 153 ms 48160 KB Output is correct
17 Correct 166 ms 51744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 40324 KB Output is correct
2 Correct 89 ms 40136 KB Output is correct
3 Correct 130 ms 46740 KB Output is correct
4 Correct 122 ms 45892 KB Output is correct
5 Correct 193 ms 56140 KB Output is correct
6 Correct 164 ms 56720 KB Output is correct
7 Correct 156 ms 57188 KB Output is correct
8 Correct 165 ms 57268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 16724 KB Output is correct
2 Correct 9 ms 16724 KB Output is correct
3 Correct 9 ms 16736 KB Output is correct
4 Correct 9 ms 16724 KB Output is correct
5 Correct 9 ms 16736 KB Output is correct
6 Correct 9 ms 16724 KB Output is correct
7 Correct 9 ms 16744 KB Output is correct
8 Correct 9 ms 16636 KB Output is correct
9 Correct 10 ms 16852 KB Output is correct
10 Correct 11 ms 17188 KB Output is correct
11 Correct 11 ms 16772 KB Output is correct
12 Correct 11 ms 16988 KB Output is correct
13 Correct 10 ms 16688 KB Output is correct
14 Correct 10 ms 16852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 16724 KB Output is correct
2 Correct 9 ms 16724 KB Output is correct
3 Correct 9 ms 16736 KB Output is correct
4 Correct 9 ms 16724 KB Output is correct
5 Correct 9 ms 16736 KB Output is correct
6 Correct 9 ms 16724 KB Output is correct
7 Correct 9 ms 16744 KB Output is correct
8 Correct 9 ms 16636 KB Output is correct
9 Correct 10 ms 16852 KB Output is correct
10 Correct 11 ms 17188 KB Output is correct
11 Correct 11 ms 16772 KB Output is correct
12 Correct 11 ms 16988 KB Output is correct
13 Correct 10 ms 16688 KB Output is correct
14 Correct 10 ms 16852 KB Output is correct
15 Correct 9 ms 16852 KB Output is correct
16 Correct 11 ms 16980 KB Output is correct
17 Correct 69 ms 23664 KB Output is correct
18 Correct 66 ms 24604 KB Output is correct
19 Correct 59 ms 24420 KB Output is correct
20 Correct 67 ms 24444 KB Output is correct
21 Correct 57 ms 24500 KB Output is correct
22 Correct 122 ms 32352 KB Output is correct
23 Correct 19 ms 18132 KB Output is correct
24 Correct 46 ms 21472 KB Output is correct
25 Correct 10 ms 16980 KB Output is correct
26 Correct 19 ms 17996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 16724 KB Output is correct
2 Correct 9 ms 16724 KB Output is correct
3 Correct 9 ms 16736 KB Output is correct
4 Correct 9 ms 16724 KB Output is correct
5 Correct 9 ms 16736 KB Output is correct
6 Correct 9 ms 16724 KB Output is correct
7 Correct 9 ms 16744 KB Output is correct
8 Correct 9 ms 16636 KB Output is correct
9 Correct 10 ms 16852 KB Output is correct
10 Correct 11 ms 17188 KB Output is correct
11 Correct 11 ms 16772 KB Output is correct
12 Correct 11 ms 16988 KB Output is correct
13 Correct 10 ms 16688 KB Output is correct
14 Correct 10 ms 16852 KB Output is correct
15 Correct 9 ms 16852 KB Output is correct
16 Correct 11 ms 16980 KB Output is correct
17 Correct 69 ms 23664 KB Output is correct
18 Correct 66 ms 24604 KB Output is correct
19 Correct 59 ms 24420 KB Output is correct
20 Correct 67 ms 24444 KB Output is correct
21 Correct 57 ms 24500 KB Output is correct
22 Correct 122 ms 32352 KB Output is correct
23 Correct 19 ms 18132 KB Output is correct
24 Correct 46 ms 21472 KB Output is correct
25 Correct 10 ms 16980 KB Output is correct
26 Correct 19 ms 17996 KB Output is correct
27 Correct 12 ms 17888 KB Output is correct
28 Correct 302 ms 51044 KB Output is correct
29 Correct 416 ms 62056 KB Output is correct
30 Correct 365 ms 62412 KB Output is correct
31 Correct 364 ms 62340 KB Output is correct
32 Correct 398 ms 64760 KB Output is correct
33 Correct 365 ms 62428 KB Output is correct
34 Correct 377 ms 62480 KB Output is correct
35 Correct 146 ms 36244 KB Output is correct
36 Correct 429 ms 64512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 40324 KB Output is correct
2 Correct 89 ms 40136 KB Output is correct
3 Correct 130 ms 46740 KB Output is correct
4 Correct 122 ms 45892 KB Output is correct
5 Correct 193 ms 56140 KB Output is correct
6 Correct 164 ms 56720 KB Output is correct
7 Correct 156 ms 57188 KB Output is correct
8 Correct 165 ms 57268 KB Output is correct
9 Correct 151 ms 56676 KB Output is correct
10 Correct 117 ms 44148 KB Output is correct
11 Correct 246 ms 71548 KB Output is correct
12 Correct 8 ms 16724 KB Output is correct
13 Correct 9 ms 16724 KB Output is correct
14 Correct 9 ms 16740 KB Output is correct
15 Correct 10 ms 16724 KB Output is correct
16 Correct 8 ms 16724 KB Output is correct
17 Correct 9 ms 16724 KB Output is correct
18 Correct 88 ms 40204 KB Output is correct
19 Correct 91 ms 40448 KB Output is correct
20 Correct 87 ms 40140 KB Output is correct
21 Correct 86 ms 40124 KB Output is correct
22 Correct 224 ms 57252 KB Output is correct
23 Correct 253 ms 70456 KB Output is correct
24 Correct 250 ms 70820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 147 ms 46804 KB Output is correct
2 Correct 159 ms 51212 KB Output is correct
3 Correct 87 ms 40212 KB Output is correct
4 Correct 89 ms 40196 KB Output is correct
5 Correct 353 ms 82240 KB Output is correct
6 Correct 402 ms 87152 KB Output is correct
7 Correct 10 ms 16724 KB Output is correct
8 Correct 259 ms 58200 KB Output is correct
9 Correct 301 ms 64780 KB Output is correct
10 Correct 143 ms 46708 KB Output is correct
11 Correct 158 ms 51088 KB Output is correct
12 Correct 9 ms 16660 KB Output is correct
13 Correct 9 ms 16664 KB Output is correct
14 Correct 9 ms 16724 KB Output is correct
15 Correct 9 ms 16724 KB Output is correct
16 Correct 91 ms 40140 KB Output is correct
17 Correct 91 ms 40212 KB Output is correct
18 Correct 151 ms 49848 KB Output is correct
19 Correct 196 ms 55024 KB Output is correct
20 Correct 149 ms 48236 KB Output is correct
21 Correct 189 ms 51824 KB Output is correct
22 Correct 153 ms 48160 KB Output is correct
23 Correct 166 ms 51744 KB Output is correct
24 Correct 95 ms 40324 KB Output is correct
25 Correct 89 ms 40136 KB Output is correct
26 Correct 130 ms 46740 KB Output is correct
27 Correct 122 ms 45892 KB Output is correct
28 Correct 193 ms 56140 KB Output is correct
29 Correct 164 ms 56720 KB Output is correct
30 Correct 156 ms 57188 KB Output is correct
31 Correct 165 ms 57268 KB Output is correct
32 Correct 9 ms 16724 KB Output is correct
33 Correct 9 ms 16724 KB Output is correct
34 Correct 9 ms 16736 KB Output is correct
35 Correct 9 ms 16724 KB Output is correct
36 Correct 9 ms 16736 KB Output is correct
37 Correct 9 ms 16724 KB Output is correct
38 Correct 9 ms 16744 KB Output is correct
39 Correct 9 ms 16636 KB Output is correct
40 Correct 10 ms 16852 KB Output is correct
41 Correct 11 ms 17188 KB Output is correct
42 Correct 11 ms 16772 KB Output is correct
43 Correct 11 ms 16988 KB Output is correct
44 Correct 10 ms 16688 KB Output is correct
45 Correct 10 ms 16852 KB Output is correct
46 Correct 9 ms 16852 KB Output is correct
47 Correct 11 ms 16980 KB Output is correct
48 Correct 69 ms 23664 KB Output is correct
49 Correct 66 ms 24604 KB Output is correct
50 Correct 59 ms 24420 KB Output is correct
51 Correct 67 ms 24444 KB Output is correct
52 Correct 57 ms 24500 KB Output is correct
53 Correct 122 ms 32352 KB Output is correct
54 Correct 19 ms 18132 KB Output is correct
55 Correct 46 ms 21472 KB Output is correct
56 Correct 10 ms 16980 KB Output is correct
57 Correct 19 ms 17996 KB Output is correct
58 Correct 12 ms 17888 KB Output is correct
59 Correct 302 ms 51044 KB Output is correct
60 Correct 416 ms 62056 KB Output is correct
61 Correct 365 ms 62412 KB Output is correct
62 Correct 364 ms 62340 KB Output is correct
63 Correct 398 ms 64760 KB Output is correct
64 Correct 365 ms 62428 KB Output is correct
65 Correct 377 ms 62480 KB Output is correct
66 Correct 146 ms 36244 KB Output is correct
67 Correct 429 ms 64512 KB Output is correct
68 Correct 151 ms 56676 KB Output is correct
69 Correct 117 ms 44148 KB Output is correct
70 Correct 246 ms 71548 KB Output is correct
71 Correct 8 ms 16724 KB Output is correct
72 Correct 9 ms 16724 KB Output is correct
73 Correct 9 ms 16740 KB Output is correct
74 Correct 10 ms 16724 KB Output is correct
75 Correct 8 ms 16724 KB Output is correct
76 Correct 9 ms 16724 KB Output is correct
77 Correct 88 ms 40204 KB Output is correct
78 Correct 91 ms 40448 KB Output is correct
79 Correct 87 ms 40140 KB Output is correct
80 Correct 86 ms 40124 KB Output is correct
81 Correct 224 ms 57252 KB Output is correct
82 Correct 253 ms 70456 KB Output is correct
83 Correct 250 ms 70820 KB Output is correct
84 Correct 496 ms 79792 KB Output is correct
85 Correct 502 ms 82488 KB Output is correct
86 Correct 465 ms 83916 KB Output is correct
87 Correct 507 ms 87788 KB Output is correct
88 Correct 9 ms 16640 KB Output is correct
89 Correct 484 ms 86584 KB Output is correct
90 Correct 463 ms 85940 KB Output is correct
91 Correct 424 ms 86160 KB Output is correct