답안 #863456

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
863456 2023-10-20T11:38:41 Z neki 메기 농장 (IOI22_fish) C++17
100 / 100
541 ms 77668 KB
#include <bits/stdc++.h>
#include "fish.h"

#define ll long long
#define vc vector
 
using namespace std;
 
ll max_weights(int N, int M, vc<int> X, vc<int> Y, vc<int> W) {
    vc<ll> ind(M); for(ll i=0;i<M;++i) ind[i]=i;
    sort(ind.begin(),ind.end(),[&](ll a,ll b){return Y[a]<Y[b];});
    
    vc<vc<pair<ll, ll>>> f(N);
    vc<vc<ll>> rel(N, vc<ll>(1, -1)), dpm(N, vc<ll>(1, 0)), dpv(N, vc<ll>(1, 0)), dpn(N, vc<ll>(1, 0));
    for(auto i: ind){
        f[X[i]].emplace_back(Y[i], W[i]);
        if(X[i]-1>=0) rel[X[i]-1].push_back(Y[i]),dpn[X[i]-1].push_back(0),dpm[X[i]-1].push_back(0),dpv[X[i]-1].push_back(0);
        if(X[i]+1<N) rel[X[i]+1].push_back(Y[i]),dpn[X[i]+1].push_back(0),dpm[X[i]+1].push_back(0),dpv[X[i]+1].push_back(0);
    }
    
    for(ll i=0;i<N;++i){
        if(i-2>=0){
            for(ll j=0, prej=0, c=0, pp=0, mm=0;j<(ll)rel[i].size();++j){
                while(pp<(ll)rel[i-2].size()&&rel[i-2][pp]<=rel[i][j])mm=max(mm, max(dpv[i-2][pp], dpm[i-2][pp])),++pp;
                while(prej<(ll)f[i-1].size()&&f[i-1][prej].first<=rel[i][j])c+=f[i-1][prej++].second;
                dpv[i][j]=max(dpv[i][j],mm+c);
                dpm[i][j]=max(dpm[i][j],mm+c);
            }
            for(ll j=(ll)rel[i].size()-1, pp=(ll)rel[i-2].size(), mm=0;j>=0;--j){
                while(pp-1>=0&&rel[i-2][pp-1]>=rel[i][j])mm=max(mm, dpn[i-2][--pp]);
                dpv[i][j]=max(dpv[i][j],mm);
                dpm[i][j]=max(dpm[i][j],mm);
            }
        }
        if(i-1>=0){
            for(ll j=0, prej=0, pf=0, mm=0;j<(ll)rel[i].size();++j){
                while(1){
                    if(prej<(ll)rel[i-1].size()&&rel[i-1][prej]<=rel[i][j]&&(!(pf<(ll)f[i-1].size()) || rel[i-1][prej]<f[i-1][pf].first))mm=max(mm, dpm[i-1][prej++]);
                    else if(pf<(ll)f[i-1].size()&&f[i-1][pf].first<=rel[i][j])mm+=f[i-1][pf++].second;
                    else break;
                }
                dpm[i][j]=max(dpm[i][j], mm);
            }
            
            ll mm=0;
            for(auto v: dpn[i-1])mm=max(mm, v);
            for(ll j=0, nas=0, c=0;j<(ll)rel[i].size();++j){
                while(nas<(ll)f[i].size()&&f[i][nas].first<=rel[i][j])c+=f[i][nas++].second;
                dpv[i][j]=max({dpv[i][j],dpm[i][j], mm-c});
            }
        }
        if(i+1<N){
            for(ll j=0, nas=0, c=0;j<(ll)rel[i].size();++j){
                while(nas<(ll)f[i+1].size()&&f[i+1][nas].first<=rel[i][j])c+=f[i+1][nas++].second;
                dpn[i][j]=max(dpn[i][j],max(dpv[i][j], dpm[i][j])+c);
            }
        }
    }
    ll ans=0;
    for(ll i=0;i<N;++i){
        for(ll j=0;j<(ll)rel[i].size();++j)ans=max({ans, dpn[i][j], dpv[i][j], dpm[i][j]});
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 29220 KB Output is correct
2 Correct 59 ms 32660 KB Output is correct
3 Correct 23 ms 24668 KB Output is correct
4 Correct 24 ms 24668 KB Output is correct
5 Correct 152 ms 63120 KB Output is correct
6 Correct 409 ms 74600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 85 ms 40392 KB Output is correct
3 Correct 100 ms 44076 KB Output is correct
4 Correct 49 ms 29220 KB Output is correct
5 Correct 59 ms 32560 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 0 ms 348 KB Output is correct
10 Correct 24 ms 24716 KB Output is correct
11 Correct 23 ms 24668 KB Output is correct
12 Correct 55 ms 31156 KB Output is correct
13 Correct 63 ms 35752 KB Output is correct
14 Correct 56 ms 31700 KB Output is correct
15 Correct 61 ms 34840 KB Output is correct
16 Correct 52 ms 32056 KB Output is correct
17 Correct 55 ms 35240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 24668 KB Output is correct
2 Correct 24 ms 24668 KB Output is correct
3 Correct 131 ms 30080 KB Output is correct
4 Correct 69 ms 29520 KB Output is correct
5 Correct 213 ms 38992 KB Output is correct
6 Correct 245 ms 39252 KB Output is correct
7 Correct 206 ms 39160 KB Output is correct
8 Correct 218 ms 38996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 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 364 KB Output is correct
5 Correct 0 ms 344 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 604 KB Output is correct
10 Correct 2 ms 856 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 2 ms 856 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 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 364 KB Output is correct
5 Correct 0 ms 344 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 604 KB Output is correct
10 Correct 2 ms 856 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 2 ms 856 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 18 ms 6624 KB Output is correct
18 Correct 19 ms 10016 KB Output is correct
19 Correct 18 ms 9052 KB Output is correct
20 Correct 18 ms 9048 KB Output is correct
21 Correct 18 ms 9052 KB Output is correct
22 Correct 36 ms 17756 KB Output is correct
23 Correct 5 ms 1884 KB Output is correct
24 Correct 14 ms 5056 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 5 ms 1628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 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 364 KB Output is correct
5 Correct 0 ms 344 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 604 KB Output is correct
10 Correct 2 ms 856 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 2 ms 856 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 18 ms 6624 KB Output is correct
18 Correct 19 ms 10016 KB Output is correct
19 Correct 18 ms 9052 KB Output is correct
20 Correct 18 ms 9048 KB Output is correct
21 Correct 18 ms 9052 KB Output is correct
22 Correct 36 ms 17756 KB Output is correct
23 Correct 5 ms 1884 KB Output is correct
24 Correct 14 ms 5056 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 5 ms 1628 KB Output is correct
27 Correct 3 ms 1368 KB Output is correct
28 Correct 103 ms 39612 KB Output is correct
29 Correct 136 ms 50808 KB Output is correct
30 Correct 167 ms 48352 KB Output is correct
31 Correct 158 ms 48220 KB Output is correct
32 Correct 127 ms 57180 KB Output is correct
33 Correct 189 ms 48612 KB Output is correct
34 Correct 168 ms 48612 KB Output is correct
35 Correct 64 ms 21884 KB Output is correct
36 Correct 159 ms 57972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 24668 KB Output is correct
2 Correct 24 ms 24668 KB Output is correct
3 Correct 131 ms 30080 KB Output is correct
4 Correct 69 ms 29520 KB Output is correct
5 Correct 213 ms 38992 KB Output is correct
6 Correct 245 ms 39252 KB Output is correct
7 Correct 206 ms 39160 KB Output is correct
8 Correct 218 ms 38996 KB Output is correct
9 Correct 101 ms 37148 KB Output is correct
10 Correct 139 ms 29908 KB Output is correct
11 Correct 377 ms 58960 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 24 ms 24712 KB Output is correct
19 Correct 25 ms 24668 KB Output is correct
20 Correct 24 ms 24664 KB Output is correct
21 Correct 24 ms 24712 KB Output is correct
22 Correct 216 ms 39160 KB Output is correct
23 Correct 391 ms 62800 KB Output is correct
24 Correct 274 ms 58880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 29220 KB Output is correct
2 Correct 59 ms 32660 KB Output is correct
3 Correct 23 ms 24668 KB Output is correct
4 Correct 24 ms 24668 KB Output is correct
5 Correct 152 ms 63120 KB Output is correct
6 Correct 409 ms 74600 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 85 ms 40392 KB Output is correct
9 Correct 100 ms 44076 KB Output is correct
10 Correct 49 ms 29220 KB Output is correct
11 Correct 59 ms 32560 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 24 ms 24716 KB Output is correct
17 Correct 23 ms 24668 KB Output is correct
18 Correct 55 ms 31156 KB Output is correct
19 Correct 63 ms 35752 KB Output is correct
20 Correct 56 ms 31700 KB Output is correct
21 Correct 61 ms 34840 KB Output is correct
22 Correct 52 ms 32056 KB Output is correct
23 Correct 55 ms 35240 KB Output is correct
24 Correct 25 ms 24668 KB Output is correct
25 Correct 24 ms 24668 KB Output is correct
26 Correct 131 ms 30080 KB Output is correct
27 Correct 69 ms 29520 KB Output is correct
28 Correct 213 ms 38992 KB Output is correct
29 Correct 245 ms 39252 KB Output is correct
30 Correct 206 ms 39160 KB Output is correct
31 Correct 218 ms 38996 KB Output is correct
32 Correct 0 ms 348 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 364 KB Output is correct
36 Correct 0 ms 344 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 604 KB Output is correct
41 Correct 2 ms 856 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 2 ms 856 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 604 KB Output is correct
46 Correct 1 ms 344 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 18 ms 6624 KB Output is correct
49 Correct 19 ms 10016 KB Output is correct
50 Correct 18 ms 9052 KB Output is correct
51 Correct 18 ms 9048 KB Output is correct
52 Correct 18 ms 9052 KB Output is correct
53 Correct 36 ms 17756 KB Output is correct
54 Correct 5 ms 1884 KB Output is correct
55 Correct 14 ms 5056 KB Output is correct
56 Correct 1 ms 600 KB Output is correct
57 Correct 5 ms 1628 KB Output is correct
58 Correct 3 ms 1368 KB Output is correct
59 Correct 103 ms 39612 KB Output is correct
60 Correct 136 ms 50808 KB Output is correct
61 Correct 167 ms 48352 KB Output is correct
62 Correct 158 ms 48220 KB Output is correct
63 Correct 127 ms 57180 KB Output is correct
64 Correct 189 ms 48612 KB Output is correct
65 Correct 168 ms 48612 KB Output is correct
66 Correct 64 ms 21884 KB Output is correct
67 Correct 159 ms 57972 KB Output is correct
68 Correct 101 ms 37148 KB Output is correct
69 Correct 139 ms 29908 KB Output is correct
70 Correct 377 ms 58960 KB Output is correct
71 Correct 0 ms 344 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 0 ms 344 KB Output is correct
74 Correct 1 ms 348 KB Output is correct
75 Correct 0 ms 348 KB Output is correct
76 Correct 1 ms 348 KB Output is correct
77 Correct 24 ms 24712 KB Output is correct
78 Correct 25 ms 24668 KB Output is correct
79 Correct 24 ms 24664 KB Output is correct
80 Correct 24 ms 24712 KB Output is correct
81 Correct 216 ms 39160 KB Output is correct
82 Correct 391 ms 62800 KB Output is correct
83 Correct 274 ms 58880 KB Output is correct
84 Correct 167 ms 66104 KB Output is correct
85 Correct 166 ms 66844 KB Output is correct
86 Correct 495 ms 72316 KB Output is correct
87 Correct 474 ms 74560 KB Output is correct
88 Correct 0 ms 344 KB Output is correct
89 Correct 541 ms 75356 KB Output is correct
90 Correct 384 ms 77668 KB Output is correct
91 Correct 270 ms 77136 KB Output is correct