Submission #628391

# Submission time Handle Problem Language Result Execution time Memory
628391 2022-08-13T11:21:21 Z guangxuan Catfish Farm (IOI22_fish) C++17
12 / 100
185 ms 27468 KB
#include "fish.h"
#define F first
#define S second
#include <bits/stdc++.h>
typedef long long ll;

const ll INF= 1LL<<60;
using namespace std;
typedef pair<int, ll> pil;

long long max_weights(int N, int M, std::vector<int> X, vector<int> Y,
                      vector<int> W) {
    for(int i=0;i<M;i++){
        Y[i]+=1;
    }
    vector<pil> rs[N];
    for(int i=0;i<M;i++){
        rs[X[i]].emplace_back(Y[i],W[i]);
    }
    for(int i=0;i<N;i++){
        rs[i].emplace_back(0,0);
        sort(rs[i].begin(),rs[i].end());
        rs[i].emplace_back(N+2,0);
        for(int j=1;j<(int)rs[i].size();j++){
            rs[i][j].S+=rs[i][j-1].S;
        }
    }
    ll dp[2][3][N+2]; // (0, h[i-1]), (h[i-1] <= h[i], h[i]), (h[i-1]>h[i], h[i])
    memset(dp,0,sizeof dp);
    for(int i=0,k=0;i<(int)rs[0].size();i++){
        while(k+1<(int)rs[1].size() && rs[0][i].F>rs[1][k+1].F){
            k++;
        }
        dp[1][0][i]=rs[1][k].S;
    }
    for(int i=0,k=0;i<(int)rs[1].size();i++){
        while(k+1<(int)rs[0].size() && rs[1][i].F>rs[0][k+1].F ){
            k++;
        }
        dp[1][1][i]=rs[0][k].S;
        dp[1][2][i]=rs[1].back().S-rs[1][max(i-1,0)].S;
    }
    for(int i=2;i<N;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<(int)max(rs[i-1].size(),rs[i].size());k++){
                dp[i&1][j][k]=0;
            }   
        }
        int rss = rs[i].size();
        int ps = rs[i-1].size();
        int pps = rs[i-2].size();
        for(int j=0, k = 0;j<ps;j++){
            while(k+1<rss && rs[i-1][j].F > rs[i][k+1].F){
                k++;
            }
            dp[i&1][0][j]=max(dp[(i&1)^1][1][j],dp[(i&1)^1][2][j])+rs[i][k].S;
        }
        //0,k -> 1,j
        ll cmax = -INF;
        for(int j=0, k =0, l=0, l2=0;j<rss;j++){
            while(k<pps && rs[i][j].F>rs[i-2][k].F){
                while(l+1<ps && rs[i-2][k].F > rs[i-1][l+1].F){
                    l++;
                }
                cmax = max(cmax,dp[(i&1)^1][0][k]+rs[i-1][l].S);
                k++;
            }
            while(l2+1<ps && rs[i][j].F > rs[i-1][l2+1].F){
                l2++;
            }
            dp[i&1][1][j]=max(dp[i&1][1][j],cmax-rs[i-1][max(l2-1,0)].S);
        }
        cmax = -INF;
        for(int j=rss-1,k=pps-1 ;j>=0;j--){
            while(k>=0 && rs[i][j].F<=rs[i-2][k].F){
                cmax = max(cmax,dp[(i&1)^1][0][k]);
                k--;
            }
            dp[i&1][1][j]=max(dp[i&1][1][j],cmax);
        }
        //1,k -> 1,j
        cmax = -INF;
        for(int j=0, k=0;j<rss;j++){
            while(k<ps && rs[i][j].F>rs[i-1][k].F){
                cmax = max(cmax, dp[(i&1)^1][1][k]-rs[i-1][max(k-1,0)].S);
                k++;
            }
            dp[i&1][1][j]=max(dp[i&1][1][j],cmax+rs[i-1][max(k-1,0)].S);
        }
        //1,k 2,k -> 2,j
        cmax = -INF;
        for(int j=rss-1, k = ps-1, l = rss-1;j>=0;j--){
            while(k>=0 && rs[i][j].F<=rs[i-1][k].F){
                while(l-1>=0 && rs[i-1][k].F<=rs[i][l].F)l--;
                cmax = max(cmax, max(dp[(i&1)^1][1][k],dp[(i&1)^1][2][k])+rs[i][l].S);
                k--;
            }
            dp[i&1][2][j]=max(dp[i&1][2][j],cmax-rs[i][j].S);
        }
    }
    ll ans = 0;
    /*for(int i=0;i<=N;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<=N;k++){
                cout << dp[i&1][j][k] << ' ';
            }
            cout << endl;
        }
        cout << endl;
    }*/
    for(int k=0;k<(int)rs[N-2].size();k++)ans = max(ans, dp[(N-1)&1][0][k]);
    for(int j=1;j<3;j++)
        for(int k=0;k<(int)rs[N-1].size();k++)ans = max(ans, dp[(N-1)&1][j][k]);
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 52 ms 14396 KB Output is correct
2 Correct 58 ms 16612 KB Output is correct
3 Correct 19 ms 11992 KB Output is correct
4 Correct 20 ms 11964 KB Output is correct
5 Correct 140 ms 24896 KB Output is correct
6 Correct 185 ms 27468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 81 ms 17604 KB Output is correct
3 Correct 103 ms 20944 KB Output is correct
4 Correct 61 ms 14772 KB Output is correct
5 Correct 68 ms 16656 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 304 KB Output is correct
10 Correct 20 ms 11912 KB Output is correct
11 Correct 19 ms 12008 KB Output is correct
12 Correct 51 ms 14572 KB Output is correct
13 Correct 70 ms 16680 KB Output is correct
14 Incorrect 60 ms 14616 KB 1st lines differ - on the 1st token, expected: '20226650012153', found: '20226987086125'
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 11988 KB Output is correct
2 Correct 19 ms 12036 KB Output is correct
3 Correct 41 ms 14684 KB Output is correct
4 Correct 36 ms 14292 KB Output is correct
5 Correct 70 ms 18120 KB Output is correct
6 Correct 62 ms 18124 KB Output is correct
7 Correct 63 ms 18252 KB Output is correct
8 Correct 59 ms 18124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Incorrect 2 ms 468 KB 1st lines differ - on the 1st token, expected: '799839985182', found: '799129753765'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Incorrect 2 ms 468 KB 1st lines differ - on the 1st token, expected: '799839985182', found: '799129753765'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Incorrect 2 ms 468 KB 1st lines differ - on the 1st token, expected: '799839985182', found: '799129753765'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 11988 KB Output is correct
2 Correct 19 ms 12036 KB Output is correct
3 Correct 41 ms 14684 KB Output is correct
4 Correct 36 ms 14292 KB Output is correct
5 Correct 70 ms 18120 KB Output is correct
6 Correct 62 ms 18124 KB Output is correct
7 Correct 63 ms 18252 KB Output is correct
8 Correct 59 ms 18124 KB Output is correct
9 Correct 78 ms 18248 KB Output is correct
10 Incorrect 52 ms 10588 KB 1st lines differ - on the 1st token, expected: '36454348383152', found: '36364983059693'
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 52 ms 14396 KB Output is correct
2 Correct 58 ms 16612 KB Output is correct
3 Correct 19 ms 11992 KB Output is correct
4 Correct 20 ms 11964 KB Output is correct
5 Correct 140 ms 24896 KB Output is correct
6 Correct 185 ms 27468 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 81 ms 17604 KB Output is correct
9 Correct 103 ms 20944 KB Output is correct
10 Correct 61 ms 14772 KB Output is correct
11 Correct 68 ms 16656 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 304 KB Output is correct
16 Correct 20 ms 11912 KB Output is correct
17 Correct 19 ms 12008 KB Output is correct
18 Correct 51 ms 14572 KB Output is correct
19 Correct 70 ms 16680 KB Output is correct
20 Incorrect 60 ms 14616 KB 1st lines differ - on the 1st token, expected: '20226650012153', found: '20226987086125'
21 Halted 0 ms 0 KB -