Submission #1053079

# Submission time Handle Problem Language Result Execution time Memory
1053079 2024-08-11T08:32:29 Z hirayuu_oj Catfish Farm (IOI22_fish) C++17
18 / 100
140 ms 69204 KB
#include "fish.h"

#include <vector>
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define rng(i,l,r) for(int i=(l); i<(r); i++)
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll INF=1LL<<60;

long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W) {
    vector<vector<pair<int,ll>>> fish(N);
    rep(i,M) {
        fish[X[i]].emplace_back(Y[i],W[i]);
    }
    rep(i,N) {
        fish[i].emplace_back(N,0);
    }
    vector<vector<int>> pos(N);
    vector<vector<ll>> cum_lf(N);
    vector<vector<ll>> cum_ri(N);
    vector<vector<ll>> cum_hr(N);
    vector<vector<ll>> updp(N);
    vector<vector<ll>> dndp(N);
    vector<int> sz(N);
    rep(i,N) {
        sort(all(fish[i]));
        sz[i]=fish[i].size();
        updp[i].resize(sz[i],-INF);
        dndp[i].resize(sz[i],-INF);
        if(i!=0) {
            ll cum=0;
            int cnt=0;
            for(auto &[y,_]:fish[i]){
                while(fish[i-1][cnt].first<y){
                    cum+=fish[i-1][cnt].second;
                    cnt++;
                }
                cum_lf[i].emplace_back(cum);
            }
        }
        if(i!=N-1){
            ll cum=0;
            int cnt=0;
            for(auto &[y,_]:fish[i]){
                while(fish[i+1][cnt].first<y){
                    cum+=fish[i+1][cnt].second;
                    cnt++;
                }
                cum_ri[i].emplace_back(cum);
            }
        }
        cum_hr[i].emplace_back(0);
        for(auto &[_,w]:fish[i]) {
            cum_hr[i].emplace_back(cum_hr[i].back()+w);
        }
    }
    rep(i,sz[0]) {
        updp[0][i]=0;
        dndp[0][i]=0;
    }
    rng(i,1,N) {
        int cnt=0;
        ll mx=-INF;
        rep(j,sz[i]) {
            while(cnt<sz[i-1]&&fish[i-1][cnt].first<=fish[i][j].first) {
                mx=max(mx,updp[i-1][cnt]-cum_hr[i-1][cnt]);
                cnt++;
            }
            updp[i][j]=mx+cum_lf[i][j];
        }
        cnt=sz[i-1]-1;
        mx=-INF;
        rrep(j,sz[i]) {
            while(cnt>=0&&fish[i-1][cnt].first>=fish[i][j].first) {
                mx=max(mx,dndp[i-1][cnt]+cum_ri[i-1][cnt]);
                cnt--;
            }
            dndp[i][j]=mx-cum_hr[i][j];
        }
        if(i>=2) {
            cnt=0;
            mx=-INF;
            ll mxa=-INF;
            rep(j,sz[i-2]) {
                mx=max(mx,dndp[i-2][j]);
                mxa=max(mxa,dndp[i-2][j]+cum_ri[i-2][cnt]);
            }
            rep(j,sz[i]) {
                updp[i][j]=max(updp[i][j],mxa);
                updp[i][j]=max(updp[i][j],mx+cum_lf[i][j]);
            }
        }
        rep(j,sz[i]) {
            dndp[i][j]=max(dndp[i][j],updp[i][j]);
        }
    }
    ll ans=-INF;
    for(ll i:dndp.back())ans=max(ans,i);
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 47 ms 39456 KB Output is correct
2 Correct 55 ms 44740 KB Output is correct
3 Correct 31 ms 35932 KB Output is correct
4 Correct 31 ms 35932 KB Output is correct
5 Correct 105 ms 65960 KB Output is correct
6 Correct 140 ms 69204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 74 ms 47296 KB Output is correct
3 Correct 80 ms 54200 KB Output is correct
4 Correct 54 ms 39360 KB Output is correct
5 Correct 55 ms 44736 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 39 ms 35972 KB Output is correct
11 Correct 30 ms 35928 KB Output is correct
12 Correct 48 ms 40240 KB Output is correct
13 Correct 56 ms 45408 KB Output is correct
14 Correct 55 ms 39780 KB Output is correct
15 Correct 54 ms 44220 KB Output is correct
16 Correct 49 ms 39872 KB Output is correct
17 Correct 53 ms 44220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 35908 KB Output is correct
2 Correct 35 ms 35928 KB Output is correct
3 Correct 49 ms 36432 KB Output is correct
4 Correct 43 ms 38748 KB Output is correct
5 Correct 69 ms 43492 KB Output is correct
6 Correct 72 ms 42940 KB Output is correct
7 Correct 65 ms 43344 KB Output is correct
8 Correct 64 ms 43436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 436 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 432 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 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 Incorrect 1 ms 604 KB 1st lines differ - on the 1st token, expected: '799839985182', found: '799098388912'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 436 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 432 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 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 Incorrect 1 ms 604 KB 1st lines differ - on the 1st token, expected: '799839985182', found: '799098388912'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 436 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 432 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 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 Incorrect 1 ms 604 KB 1st lines differ - on the 1st token, expected: '799839985182', found: '799098388912'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 31 ms 35908 KB Output is correct
2 Correct 35 ms 35928 KB Output is correct
3 Correct 49 ms 36432 KB Output is correct
4 Correct 43 ms 38748 KB Output is correct
5 Correct 69 ms 43492 KB Output is correct
6 Correct 72 ms 42940 KB Output is correct
7 Correct 65 ms 43344 KB Output is correct
8 Correct 64 ms 43436 KB Output is correct
9 Correct 65 ms 43352 KB Output is correct
10 Incorrect 76 ms 27220 KB 1st lines differ - on the 1st token, expected: '36454348383152', found: '36410078429822'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 47 ms 39456 KB Output is correct
2 Correct 55 ms 44740 KB Output is correct
3 Correct 31 ms 35932 KB Output is correct
4 Correct 31 ms 35932 KB Output is correct
5 Correct 105 ms 65960 KB Output is correct
6 Correct 140 ms 69204 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 74 ms 47296 KB Output is correct
9 Correct 80 ms 54200 KB Output is correct
10 Correct 54 ms 39360 KB Output is correct
11 Correct 55 ms 44736 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 39 ms 35972 KB Output is correct
17 Correct 30 ms 35928 KB Output is correct
18 Correct 48 ms 40240 KB Output is correct
19 Correct 56 ms 45408 KB Output is correct
20 Correct 55 ms 39780 KB Output is correct
21 Correct 54 ms 44220 KB Output is correct
22 Correct 49 ms 39872 KB Output is correct
23 Correct 53 ms 44220 KB Output is correct
24 Correct 31 ms 35908 KB Output is correct
25 Correct 35 ms 35928 KB Output is correct
26 Correct 49 ms 36432 KB Output is correct
27 Correct 43 ms 38748 KB Output is correct
28 Correct 69 ms 43492 KB Output is correct
29 Correct 72 ms 42940 KB Output is correct
30 Correct 65 ms 43344 KB Output is correct
31 Correct 64 ms 43436 KB Output is correct
32 Correct 0 ms 436 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 432 KB Output is correct
37 Correct 0 ms 344 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Incorrect 1 ms 604 KB 1st lines differ - on the 1st token, expected: '799839985182', found: '799098388912'
42 Halted 0 ms 0 KB -