Submission #1035860

#TimeUsernameProblemLanguageResultExecution timeMemory
1035860AndreyCatfish Farm (IOI22_fish)C++17
100 / 100
141 ms55784 KiB
#include "fish.h"
#include<bits/stdc++.h>
using namespace std;

vector<pair<long long,long long>> haha[150000];
vector<long long> dp[150000][3];

long long max_weights(int n, int m, vector<int> x, vector<int> y,  vector<int> w) {
    for(long long i = 0; i < m; i++) {
        haha[x[i]+1].push_back({y[i],w[i]});
    }
    haha[0].push_back({0,0});
    for(long long i = 0; i <= n; i++) {
        haha[i].push_back({n,0});
        sort(haha[i].begin(),haha[i].end());
        for(long long j = 1; j < haha[i].size(); j++) {
            haha[i][j] = {haha[i][j].first,haha[i][j].second+haha[i][j-1].second};
        }
        for(long long j = haha[i].size()-1; j >= 1; j--) {
            haha[i][j] = {haha[i][j].first,haha[i][j-1].second};
        }
        haha[i][0] = {haha[i][0].first,0};
    }
    long long ans = 0;
    dp[0][0].push_back(0);
    dp[0][1].push_back(-LLONG_MAX/2);
    dp[0][2].push_back(-LLONG_MAX/2);
    dp[0][0].push_back(-LLONG_MAX/2);
    dp[0][1].push_back(-LLONG_MAX/2);
    dp[0][2].push_back(-LLONG_MAX/2);
    for(long long i = 1; i <= n; i++) {
        for(long long j = 0; j < haha[i].size(); j++) {
            dp[i][0].push_back(-LLONG_MAX/2);
            dp[i][1].push_back(-LLONG_MAX/2);
            dp[i][2].push_back(-LLONG_MAX/2);
        }
        long long x = -LLONG_MAX/2,y = haha[i-1].size()-1;
        for(long long j = haha[i].size()-1; j >= 0; j--) {
            while(y >= 0 && (j == 0 || haha[i-1][y].first > haha[i][j-1].first)) {
                x = max(x,max(dp[i-1][2][y],dp[i-1][0][y])+haha[i][j].second);
                y--;
            }
            dp[i][2][j] = max(dp[i][2][j],x-haha[i][j].second);
        }
        y = 0;
        for(long long j = 0; j < haha[i].size(); j++) {
            while(y < haha[i-1].size() && (y == 0 || haha[i-1][y-1].first < haha[i][j].first)) {
                dp[i][1][j] = max(dp[i][1][j],max(dp[i-1][0][y],dp[i-1][2][y])+haha[i][j].second);
                y++;
            }
        }
        x = -LLONG_MAX/2;
        y = 0;
        for(long long j = 0; j < haha[i].size(); j++) {
            while(y < haha[i-1].size() && (y == 0 || haha[i-1][y-1].first < haha[i][j].first)) {
                x = max(x,dp[i-1][1][y]-haha[i-1][y].second);
                x = max(x,dp[i-1][0][y]-haha[i-1][y].second);
                y++;
            }
            dp[i][0][j] = max(dp[i][0][j],x+haha[i-1][y-1].second);
        }
        x = -LLONG_MAX/2;
        y = haha[i-1].size()-1;
        for(long long j = haha[i].size()-1; j >= 0; j--) {
            while(y >= 0 && (j == 0 || haha[i-1][y].first > haha[i][j-1].first)) {
                x = max(x,dp[i-1][1][y]);
                y--;
            }
            dp[i][0][j] = max(dp[i][0][j],x);
        }
    }
    for(long long i = 0; i < haha[n].size(); i++) {
        ans = max(ans,dp[n][0][i]);
        ans = max(ans,dp[n][1][i]);
        ans = max(ans,dp[n][2][i]);
    }
    return ans;
}

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:16:32: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |         for(long long j = 1; j < haha[i].size(); j++) {
      |                              ~~^~~~~~~~~~~~~~~~
fish.cpp:32:32: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         for(long long j = 0; j < haha[i].size(); j++) {
      |                              ~~^~~~~~~~~~~~~~~~
fish.cpp:46:32: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         for(long long j = 0; j < haha[i].size(); j++) {
      |                              ~~^~~~~~~~~~~~~~~~
fish.cpp:47:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |             while(y < haha[i-1].size() && (y == 0 || haha[i-1][y-1].first < haha[i][j].first)) {
      |                   ~~^~~~~~~~~~~~~~~~~~
fish.cpp:54:32: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         for(long long j = 0; j < haha[i].size(); j++) {
      |                              ~~^~~~~~~~~~~~~~~~
fish.cpp:55:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |             while(y < haha[i-1].size() && (y == 0 || haha[i-1][y-1].first < haha[i][j].first)) {
      |                   ~~^~~~~~~~~~~~~~~~~~
fish.cpp:72:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |     for(long long i = 0; i < haha[n].size(); i++) {
      |                          ~~^~~~~~~~~~~~~~~~
#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...