Submission #627018

#TimeUsernameProblemLanguageResultExecution timeMemory
627018jhhope1Catfish Farm (IOI22_fish)C++17
100 / 100
219 ms25456 KiB
#include <bits/stdc++.h>
#include "fish.h"

#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<pii, ll> tri;
const int MAXN = 100010;
const ll INF = 1e18;
vector<pii> HW[MAXN];
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {
    vector<tri> P;
    for(int i=0 ; i<M ; i++){
        P.emplace_back(pii(X[i], Y[i]), W[i]);
    }
    sort(P.begin(), P.end());
    for(int i=0 ; i<M ; i++){
        HW[P[i].first.first].emplace_back(P[i].first.second, P[i].second);
    }
    
    vector<ll> U(HW[0].size(), 0), D(HW[0].size(), 0);
    ll T = 0, S = 0;
    for(int j=0 ; j<HW[0].size() ; j++){
        S += HW[0][j].second;
        D[j] = S;
    }

    for(int i=1 ; i<N ; i++){
        vector<ll> new_U(HW[i].size(), 0), new_D(HW[i].size(), 0);
        ll S = 0, ma = -INF;
        for(int j=HW[i].size()-1 ; j>=0 ; j--){
            S += HW[i][j].second;
            new_U[j] = T + S;
        }
        S = 0;
        for(int j=HW[i].size()-1 ; j>=0 ; j--){
            auto [x, w] = HW[i][j];
            int idx = lower_bound(HW[i-1].begin(), HW[i-1].end(), pii(x+1, 0)) - HW[i-1].begin();
            if(idx < U.size()){
                ma = max(ma, U[idx] - S);
                new_U[j] = max(new_U[j], ma + (S + w));
            }
            S += w;
        }
        S = 0, ma = -INF;
        for(int j=0 ; j<HW[i].size() ; j++){
            S += HW[i][j].second;
            if(U.size()){
                new_D[j] = U[0] + S;
            }
        }
        S = 0;
        for(int j=0 ; j<HW[i].size() ; j++){
            auto [x, w] = HW[i][j];
            int idx = lower_bound(HW[i-1].begin(), HW[i-1].end(), pii(x, 0)) - HW[i-1].begin() - 1;
            if(idx >= 0 && idx < U.size()){
                ma = max(ma, D[idx] - S);
                new_D[j] = max(new_D[j], ma + (S + w));
            }
            S += w;
        }

        if(U.size()){
            T = max(T, U[0]);
            T = max(T, D[D.size()-1]);
        }
        U = new_U;
        D = new_D;
    }
    if(U.size()){
        T = max(T, U[0]);
    }
    return T;
}

Compilation message (stderr)

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:24:20: 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]
   24 |     for(int j=0 ; j<HW[0].size() ; j++){
      |                   ~^~~~~~~~~~~~~
fish.cpp:40:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |             if(idx < U.size()){
      |                ~~~~^~~~~~~~~~
fish.cpp:47:24: 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]
   47 |         for(int j=0 ; j<HW[i].size() ; j++){
      |                       ~^~~~~~~~~~~~~
fish.cpp:54:24: 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]
   54 |         for(int j=0 ; j<HW[i].size() ; j++){
      |                       ~^~~~~~~~~~~~~
fish.cpp:57:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |             if(idx >= 0 && idx < U.size()){
      |                            ~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...