Submission #1075630

# Submission time Handle Problem Language Result Execution time Memory
1075630 2024-08-26T08:09:48 Z Faisal_Saqib Catfish Farm (IOI22_fish) C++17
0 / 100
280 ms 81188 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define all(x) begin(x),end(x)
const int N=1e5+10;
vll pre[N];
ll sz[N];
vll dp[N][3];
vll possible[N];
vector<pair<ll,ll>> values[N];
ll solve(ll&n,ll&m,vll&x,vll&y,vll&w)
{
    ll ans=0;
    for(int j=0;j<m;j++)
    {
        values[x[j]].push_back({y[j]+1,w[j]});
        possible[x[j]].push_back(y[j]+1);
        possible[x[j]+1].push_back(y[j]+1);
        if(x[j]>0)
            possible[x[j]-1].push_back(y[j]+1);
    }
    for(int i=0;i<=n;i++)
    {
        possible[i].push_back(0);
        possible[i].push_back(n);
        sort(begin(possible[i]),end(possible[i]));
        sort(begin(values[i]),end(values[i]));
        sz[i]=possible[i].size();
        pre[i].resize(sz[i]+1,0);
        ll sm=0;
        int pp=0;
        int rp=0;
        for(auto&j:possible[i])
        {
            while(pp<values[i].size() and values[i][pp].first<=j)
            {
                sm+=values[i][pp].second;
                pp++;
            }
            pre[i][rp]=sm;
            rp++;
        }
        dp[i][0].resize(sz[i]+1,0);
        dp[i][1].resize(sz[i]+1,0);
    }
    // for(int i=0;i<n;i++)
    //     for(int j=0;j<=n;j++)
    //         for(int k=0;k<2;k++)
    //             dp[i][j][k]=0;
    for(int i=1;i<n;i++)
    {
        // ll sum=0;
        ll mx1=-2e18;
        ll mx2=-2e18;
        ll mx11=0,mx22=0;
        for(int k=0;k<sz[i];k++)
        {
            int hp=possible[i][k];
            mx11=max(mx11,dp[i-1][0][k]);
            auto index=lower_bound(all(possible[i-1]),hp)-begin(possible[i-1]);
            mx1=max(mx1,dp[i-1][0][k]-pre[i-1][index]);
        }
        for(int k=0;k<sz[i];k++)
        {
            int hp=possible[i][k];
            mx11=max(mx11,dp[i-1][1][k]);

            auto index=lower_bound(all(possible[i]),hp)-begin(possible[i]);
            mx1=max(mx1,dp[i-1][1][k]+pre[i][index]);
        }
        int pp=0;
        for(auto&h:possible[i])
        {
            auto index=lower_bound(all(possible[i-1]),h)-begin(possible[i-1]);
            dp[i][0][pp]=max(dp[i][0][pp],mx1+pre[i-1][index]);
            dp[i][1][pp]=max(dp[i][1][pp],mx1+pre[i-1][index]);
            dp[i][1][pp]=max(dp[i][1][pp],mx2-pre[i][pp]);

            dp[i][0][pp]=max(dp[i][0][pp],mx11);
            dp[i][0][pp]=max(dp[i][0][pp],mx22);

            dp[i][1][pp]=max(dp[i][1][pp],mx11);
            dp[i][1][pp]=max(dp[i][1][pp],mx22);
            pp++;
        }
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<sz[i];j++)
        {
            ans=max(ans,dp[i][0][j]);
            ans=max(ans,dp[i][1][j]);
            
        }
    }
    return ans;
}
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,std::vector<int> W)
{
    ll n=N,m=M,ans=0;
    vector<ll> x(all(X)),y(all(Y)),w(all(W));
    return solve(n,m,x,y,w);
}

Compilation message

fish.cpp: In function 'long long int solve(long long int&, long long int&, std::vector<long long int>&, std::vector<long long int>&, std::vector<long long int>&)':
fish.cpp:36:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |             while(pp<values[i].size() and values[i][pp].first<=j)
      |                   ~~^~~~~~~~~~~~~~~~~
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:101:16: warning: unused variable 'ans' [-Wunused-variable]
  101 |     ll n=N,m=M,ans=0;
      |                ^~~
# Verdict Execution time Memory Grader output
1 Correct 112 ms 37992 KB Output is correct
2 Correct 89 ms 41900 KB Output is correct
3 Correct 54 ms 27728 KB Output is correct
4 Correct 31 ms 27740 KB Output is correct
5 Incorrect 280 ms 81188 KB 1st lines differ - on the 1st token, expected: '149814460735479', found: '194645700188779'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 14428 KB 1st lines differ - on the 1st token, expected: '2', found: '3'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 27732 KB Output is correct
2 Correct 35 ms 27728 KB Output is correct
3 Incorrect 59 ms 38736 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '53445416092380'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 14428 KB 1st lines differ - on the 1st token, expected: '3', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 14428 KB 1st lines differ - on the 1st token, expected: '3', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 14428 KB 1st lines differ - on the 1st token, expected: '3', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 27732 KB Output is correct
2 Correct 35 ms 27728 KB Output is correct
3 Incorrect 59 ms 38736 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '53445416092380'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 112 ms 37992 KB Output is correct
2 Correct 89 ms 41900 KB Output is correct
3 Correct 54 ms 27728 KB Output is correct
4 Correct 31 ms 27740 KB Output is correct
5 Incorrect 280 ms 81188 KB 1st lines differ - on the 1st token, expected: '149814460735479', found: '194645700188779'
6 Halted 0 ms 0 KB -