Submission #1033038

# Submission time Handle Problem Language Result Execution time Memory
1033038 2024-07-24T12:09:28 Z vjudge1 Catfish Farm (IOI22_fish) C++17
0 / 100
189 ms 95828 KB
#include "fish.h"
#include <bits/stdc++.h>

#pragma GCC optimize("Ofast")

using namespace std;

#define ll long long
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define sz(s) (int)s.size()
#define lb lower_bound
#define ub upper_bound

const int MAX=2e5+10;

vector<pair<ll,ll>> y[MAX];
vector<ll> p[MAX];
vector<ll> dp[MAX][2];
vector<ll> can[MAX];
ll getR(int x,ll r){
    if(r<0)return 0;
    int R=ub(all(y[x]),make_pair(r+1,-1ll))-y[x].begin()-1;
    if(R<0)return 0;
    return p[x][R];
}

vector<ll> pref[MAX][2],suf[MAX][2];
vector<pair<int,int>> vec[MAX];

long long max_weights(int N, int M, vector<int> X, vector<int> Y,vector<int> W) {
    for(int i=0;i<M;i++){
        X[i]++;
        Y[i]++;
        y[X[i]].pb({Y[i],i});
        vec[Y[i]].pb({X[i],W[i]});
    }
    for(int i=1;i<=N;i++){
        if(y[i].empty())continue;
        sort(all(y[i]));
        p[i].pb(W[y[i][0].S]);
        for(int j=1;j<sz(y[i]);j++){
            p[i].pb(p[i].back()+W[y[i][j].S]);
        }
    }
    can[0].pb(0);
    for(int i=1;i<=N;i++){
        can[i].pb(0);
        if(i>0){
            for(auto [x,b]:y[i-1])can[i].pb(x);
        }
        if(i+1<=N){
            for(auto [x,b]:y[i+1])can[i].pb(x);
        }
        sort(all(can[i]));
        can[i].erase(unique(all(can[i])),can[i].end());
    }
    for(int i=0;i<=N+1;i++){
        dp[i][0].resize(sz(can[i]));
        dp[i][1].resize(sz(can[i]));
        for(int j=0;j<sz(can[i]);j++){
            dp[i][0][j]=dp[i][1][j]=0;
        }
    }
    for(int i=1;i<=N;i++){
        {
            int r=sz(can[i-1]);
            ll mx=0;
            for(int j=sz(can[i])-1;j>=0;j--){
                while(r-1>=0&&can[i-1][r-1]>=can[i][j]){
                    mx=max(mx,max(dp[i-1][0][r-1],dp[i-1][1][r-1])+getR(i,can[i-1][r-1]));
                    r--;
                }
                dp[i][0][j]=mx-getR(i,can[i][j]);
            }
        }
        {
            int r=0;
            ll mx=0;
            for(int j=0;j<sz(can[i]);j++){
                while(r<sz(can[i-1])&&can[i-1][r]<=can[i][j]){
                    mx=max(mx,dp[i-1][r][1]-getR(i-1,can[i-1][r]));
                    r++;
                }
                dp[i][1][j]=mx+getR(i-1,can[i][j]);
                dp[i][1][j]=max(dp[i][1][j],dp[i-1][0][0]);
            }
        }
    }
    ll ans=0;
    for(int j=0;j<sz(can[N]);j++)ans=max(ans,max(dp[N][0][j],dp[N][1][j]));
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 67 ms 65416 KB Output is correct
2 Correct 79 ms 68288 KB Output is correct
3 Correct 34 ms 56660 KB Output is correct
4 Correct 36 ms 56660 KB Output is correct
5 Incorrect 189 ms 94752 KB 1st lines differ - on the 1st token, expected: '149814460735479', found: '149814466847975'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 47192 KB Output is correct
2 Incorrect 127 ms 74608 KB 1st lines differ - on the 1st token, expected: '40604614618209', found: '121377263282980'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 36 ms 56656 KB Output is correct
2 Correct 38 ms 56644 KB Output is correct
3 Incorrect 59 ms 62412 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '16359027219341'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 22 ms 47192 KB Output is correct
2 Correct 22 ms 47196 KB Output is correct
3 Correct 21 ms 47192 KB Output is correct
4 Correct 21 ms 47192 KB Output is correct
5 Correct 23 ms 47192 KB Output is correct
6 Correct 22 ms 47196 KB Output is correct
7 Correct 22 ms 47192 KB Output is correct
8 Correct 21 ms 47192 KB Output is correct
9 Runtime error 52 ms 95828 KB Execution killed with signal 11
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 22 ms 47192 KB Output is correct
2 Correct 22 ms 47196 KB Output is correct
3 Correct 21 ms 47192 KB Output is correct
4 Correct 21 ms 47192 KB Output is correct
5 Correct 23 ms 47192 KB Output is correct
6 Correct 22 ms 47196 KB Output is correct
7 Correct 22 ms 47192 KB Output is correct
8 Correct 21 ms 47192 KB Output is correct
9 Runtime error 52 ms 95828 KB Execution killed with signal 11
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 22 ms 47192 KB Output is correct
2 Correct 22 ms 47196 KB Output is correct
3 Correct 21 ms 47192 KB Output is correct
4 Correct 21 ms 47192 KB Output is correct
5 Correct 23 ms 47192 KB Output is correct
6 Correct 22 ms 47196 KB Output is correct
7 Correct 22 ms 47192 KB Output is correct
8 Correct 21 ms 47192 KB Output is correct
9 Runtime error 52 ms 95828 KB Execution killed with signal 11
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 36 ms 56656 KB Output is correct
2 Correct 38 ms 56644 KB Output is correct
3 Incorrect 59 ms 62412 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '16359027219341'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 67 ms 65416 KB Output is correct
2 Correct 79 ms 68288 KB Output is correct
3 Correct 34 ms 56660 KB Output is correct
4 Correct 36 ms 56660 KB Output is correct
5 Incorrect 189 ms 94752 KB 1st lines differ - on the 1st token, expected: '149814460735479', found: '149814466847975'
6 Halted 0 ms 0 KB -