답안 #1053038

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1053038 2024-08-11T08:05:11 Z hirayuu_oj 메기 농장 (IOI22_fish) C++17
18 / 100
145 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;
const 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,fish[0].size()) {
        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;
            rep(j,sz[i]) {
                while(cnt<sz[i-2]&&fish[i-2][cnt].first<=fish[i][j].first) {
                    mx=max(mx,dndp[i-2][cnt]);
                    cnt++;
                }
                updp[i][j]=max(updp[i][j],mx+cum_lf[i][j]);
            }
            cnt=sz[i-2]-1;
            mx=-INF;
            rrep(j,sz[i]) {
                while(0<=cnt&&fish[i-2][cnt].first>=fish[i][j].first) {
                    mx=max(mx,dndp[i-2][cnt]+cum_ri[i-2][cnt]);
                    cnt--;
                }
                updp[i][j]=max(updp[i][j],mx);
            }
        }
        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;
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:6:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 | #define rep(i,n) for(int i=0; i<(n); i++)
      |                                ^
fish.cpp:61:5: note: in expansion of macro 'rep'
   61 |     rep(i,fish[0].size()) {
      |     ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 39364 KB Output is correct
2 Correct 54 ms 44844 KB Output is correct
3 Correct 31 ms 35932 KB Output is correct
4 Correct 31 ms 35852 KB Output is correct
5 Correct 106 ms 65960 KB Output is correct
6 Correct 145 ms 69204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 69 ms 47164 KB Output is correct
3 Correct 80 ms 54192 KB Output is correct
4 Correct 48 ms 39364 KB Output is correct
5 Correct 54 ms 44652 KB Output is correct
6 Correct 1 ms 344 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 31 ms 36016 KB Output is correct
11 Correct 35 ms 35928 KB Output is correct
12 Correct 48 ms 40128 KB Output is correct
13 Correct 55 ms 45508 KB Output is correct
14 Correct 49 ms 39932 KB Output is correct
15 Correct 52 ms 44224 KB Output is correct
16 Correct 48 ms 39832 KB Output is correct
17 Correct 52 ms 44220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 35928 KB Output is correct
2 Correct 34 ms 35924 KB Output is correct
3 Correct 47 ms 36400 KB Output is correct
4 Correct 46 ms 38484 KB Output is correct
5 Correct 62 ms 43440 KB Output is correct
6 Correct 60 ms 42836 KB Output is correct
7 Correct 62 ms 43552 KB Output is correct
8 Correct 68 ms 43572 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 348 KB Output is correct
5 Correct 0 ms 348 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 348 KB Output is correct
10 Incorrect 1 ms 704 KB 1st lines differ - on the 1st token, expected: '799839985182', found: '799098388912'
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 348 KB Output is correct
5 Correct 0 ms 348 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 348 KB Output is correct
10 Incorrect 1 ms 704 KB 1st lines differ - on the 1st token, expected: '799839985182', found: '799098388912'
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 348 KB Output is correct
5 Correct 0 ms 348 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 348 KB Output is correct
10 Incorrect 1 ms 704 KB 1st lines differ - on the 1st token, expected: '799839985182', found: '799098388912'
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 35928 KB Output is correct
2 Correct 34 ms 35924 KB Output is correct
3 Correct 47 ms 36400 KB Output is correct
4 Correct 46 ms 38484 KB Output is correct
5 Correct 62 ms 43440 KB Output is correct
6 Correct 60 ms 42836 KB Output is correct
7 Correct 62 ms 43552 KB Output is correct
8 Correct 68 ms 43572 KB Output is correct
9 Correct 82 ms 43344 KB Output is correct
10 Incorrect 49 ms 27224 KB 1st lines differ - on the 1st token, expected: '36454348383152', found: '36410078429822'
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 39364 KB Output is correct
2 Correct 54 ms 44844 KB Output is correct
3 Correct 31 ms 35932 KB Output is correct
4 Correct 31 ms 35852 KB Output is correct
5 Correct 106 ms 65960 KB Output is correct
6 Correct 145 ms 69204 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 69 ms 47164 KB Output is correct
9 Correct 80 ms 54192 KB Output is correct
10 Correct 48 ms 39364 KB Output is correct
11 Correct 54 ms 44652 KB Output is correct
12 Correct 1 ms 344 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 31 ms 36016 KB Output is correct
17 Correct 35 ms 35928 KB Output is correct
18 Correct 48 ms 40128 KB Output is correct
19 Correct 55 ms 45508 KB Output is correct
20 Correct 49 ms 39932 KB Output is correct
21 Correct 52 ms 44224 KB Output is correct
22 Correct 48 ms 39832 KB Output is correct
23 Correct 52 ms 44220 KB Output is correct
24 Correct 32 ms 35928 KB Output is correct
25 Correct 34 ms 35924 KB Output is correct
26 Correct 47 ms 36400 KB Output is correct
27 Correct 46 ms 38484 KB Output is correct
28 Correct 62 ms 43440 KB Output is correct
29 Correct 60 ms 42836 KB Output is correct
30 Correct 62 ms 43552 KB Output is correct
31 Correct 68 ms 43572 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 348 KB Output is correct
36 Correct 0 ms 348 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 348 KB Output is correct
41 Incorrect 1 ms 704 KB 1st lines differ - on the 1st token, expected: '799839985182', found: '799098388912'
42 Halted 0 ms 0 KB -