Submission #1035832

# Submission time Handle Problem Language Result Execution time Memory
1035832 2024-07-26T16:33:07 Z Andrey Catfish Farm (IOI22_fish) C++17
12 / 100
174 ms 56176 KB
#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() && haha[i-1][y].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() && haha[i-1][y].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++;
            }
            if(y > 0) {
                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][i][0]);
        ans = max(ans,dp[n][i][1]);
        ans = max(ans,dp[n][i][2]);
    }
    return ans;
}

Compilation message

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() && haha[i-1][y].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() && haha[i-1][y].first <= haha[i][j].first) {
      |                   ~~^~~~~~~~~~~~~~~~~~
fish.cpp:74: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]
   74 |     for(long long i = 0; i < haha[n].size(); i++) {
      |                          ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 54 ms 32452 KB Output is correct
2 Correct 61 ms 35172 KB Output is correct
3 Correct 23 ms 26972 KB Output is correct
4 Correct 22 ms 26864 KB Output is correct
5 Correct 120 ms 53728 KB Output is correct
6 Correct 174 ms 56176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 14428 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 26868 KB Output is correct
2 Correct 38 ms 27024 KB Output is correct
3 Correct 40 ms 28756 KB Output is correct
4 Correct 34 ms 29008 KB Output is correct
5 Correct 67 ms 33084 KB Output is correct
6 Correct 54 ms 32340 KB Output is correct
7 Correct 60 ms 32848 KB Output is correct
8 Correct 58 ms 32852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 14428 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
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: '2'
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: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 26868 KB Output is correct
2 Correct 38 ms 27024 KB Output is correct
3 Correct 40 ms 28756 KB Output is correct
4 Correct 34 ms 29008 KB Output is correct
5 Correct 67 ms 33084 KB Output is correct
6 Correct 54 ms 32340 KB Output is correct
7 Correct 60 ms 32848 KB Output is correct
8 Correct 58 ms 32852 KB Output is correct
9 Incorrect 68 ms 32592 KB 1st lines differ - on the 1st token, expected: '99999', found: '66666'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 54 ms 32452 KB Output is correct
2 Correct 61 ms 35172 KB Output is correct
3 Correct 23 ms 26972 KB Output is correct
4 Correct 22 ms 26864 KB Output is correct
5 Correct 120 ms 53728 KB Output is correct
6 Correct 174 ms 56176 KB Output is correct
7 Incorrect 6 ms 14428 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
8 Halted 0 ms 0 KB -