Submission #1035801

# Submission time Handle Problem Language Result Execution time Memory
1035801 2024-07-26T16:00:54 Z Andrey Catfish Farm (IOI22_fish) C++17
0 / 100
49 ms 32456 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]});
    }
    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 = 1; j < haha[i].size(); 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);
    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 >= 1; j--) {
            while(y >= 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) {
                y++;
            }
            if(y > 0) {
                dp[i][1][j] = max(dp[i][1][j],max(dp[i-1][0][y-1],dp[i-1][2][y-1])+haha[i][j].second);
            }
        }
        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 >= 1; j--) {
            while(y >= 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:15: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]
   15 |         for(long long j = 1; j < haha[i].size(); j++) {
      |                              ~~^~~~~~~~~~~~~~~~
fish.cpp:18: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]
   18 |         for(long long j = 1; j < haha[i].size(); j++) {
      |                              ~~^~~~~~~~~~~~~~~~
fish.cpp:28: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]
   28 |         for(long long j = 0; j < haha[i].size(); j++) {
      |                              ~~^~~~~~~~~~~~~~~~
fish.cpp:42: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]
   42 |         for(long long j = 0; j < haha[i].size(); j++) {
      |                              ~~^~~~~~~~~~~~~~~~
fish.cpp:43: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]
   43 |             while(y < haha[i-1].size() && haha[i-1][y].first <= haha[i][j].first) {
      |                   ~~^~~~~~~~~~~~~~~~~~
fish.cpp:52: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]
   52 |         for(long long j = 0; j < haha[i].size(); j++) {
      |                              ~~^~~~~~~~~~~~~~~~
fish.cpp:53: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]
   53 |             while(y < haha[i-1].size() && haha[i-1][y].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 time Memory Grader output
1 Incorrect 44 ms 32456 KB 1st lines differ - on the 1st token, expected: '40313272768926', found: '223762357'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 14424 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 26972 KB Output is correct
2 Correct 22 ms 26972 KB Output is correct
3 Incorrect 49 ms 28852 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 Incorrect 7 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 7 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 7 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 26972 KB Output is correct
2 Correct 22 ms 26972 KB Output is correct
3 Incorrect 49 ms 28852 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 Incorrect 44 ms 32456 KB 1st lines differ - on the 1st token, expected: '40313272768926', found: '223762357'
2 Halted 0 ms 0 KB -