Submission #838833

# Submission time Handle Problem Language Result Execution time Memory
838833 2023-08-27T20:55:03 Z Andrey Catfish Farm (IOI22_fish) C++17
0 / 100
200 ms 136472 KB
#include "fish.h"
#include<bits/stdc++.h>
#include <vector>
using namespace std;

/// Bobcho tova e C grupa DP

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

long long max_weights(int n, int m, std::vector<int> x, std::vector<int> Y, std::vector<int> w) {
    for(long long i = 0; i < m; i++) {
        bruh[x[i]].push_back({Y[i],w[i]});
        dp[x[i]][0].push_back(0);
        dp[x[i]][1].push_back(0);
        dp[x[i]][2].push_back(0);
    }
    for(int i = 0; i <= n; i++) {
        bruh[i].push_back({n,0});
        bruh[i].push_back({0,0});
        sort(bruh[i].begin(),bruh[i].end());
        dp[i][0].push_back(0);
        dp[i][1].push_back(0);
        dp[i][2].push_back(0);
        dp[i][0].push_back(0);
        dp[i][1].push_back(0);
        dp[i][2].push_back(0);
    }
    for(long long i = 0; i <= n; i++) {
        long long br = 0;
        for(long long j = 0; j < bruh[i].size(); j++) {
            br+=bruh[i][j].second;
            haha[i].push_back({bruh[i][j].first,br});
        }
    }
    int y = 0;
    for(int i = 0; i < haha[0].size(); i++) {
        while(y < haha[1].size() && haha[0][i].first > haha[1][y].first) {
            y++;
        }
        if(y > 0) {
            dp[0][0][i] = haha[1][y-1].second;
        }
    }
    long long ans = 0,z = 0,sb = 0;
    for(long long i = 1; i < n; i++) {
        y = 0;
        z = 1;
        sb = 0;
        for(long long j = 0; j < haha[i].size(); j++) {
            while(y < haha[i-1].size()-1 && haha[i-1][y].first <= haha[i][j].first) {
                y++;
            }
            dp[i][2][j] = max(dp[i][2][j],dp[i-1][0][y]);
            dp[i][2][j] = max(dp[i][2][j],dp[i-1][1][y]);
        }
        for(int j = 0; j < haha[i-1].size(); j++) {
            sb = max(sb,dp[i-1][2][j]);
        }
        long long big = 0;
        y = 1;
        z = 1;
        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++;
            }
            while(z < haha[i+1].size() && haha[i+1][z].first < haha[i][j].first) {
                z++;
            }
            big = max(big,dp[i-1][0][y-1]-haha[i-1][y-1].second-haha[i][j].second);
            dp[i][0][j] = big+haha[i+1][z-1].second+haha[i-1][y-1].second;
        }
        big = 0;
        y = haha[i-1].size()-2;
        z = haha[i+1].size()-2;
        for(long long j = haha[i].size()-1; j >= 0; j--) {
            while(y >= 0 && haha[i-1][y].first > haha[i][j].first) {
                y--;
            }
            while(z >= 0 && haha[i+1][z].first > haha[i][j].first) {
                z--;
            }
            dp[i][1][j] = big-haha[i][j].second+haha[i+1][z+1].second;
            big = max(big,dp[i-1][0][y+1]);
        }
        big = 0;
        y = haha[i-1].size()-2;
        z = haha[i+1].size()-2;
        for(long long j = haha[i].size()-1; j >= 0; j--) {
            while(y >= 0 && haha[i-1][y].first > haha[i][j].first) {
                y--;
            }
            while(z >= 0 && haha[i+1][z].first > haha[i][j].first) {
                z--;
            }
            dp[i][1][j] = max(dp[i][1][j],big-haha[i][j].second+haha[i+1][z+1].second);
            big = max(big,dp[i-1][1][y+1]);
        }
        big = 0;
        y = 1;
        z = 1;
        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++;
            }
            while(z < haha[i+1].size() && haha[i+1][y].first < haha[i][j].first) {
                z++;
            }
            dp[i][0][j] = max(dp[i][0][j],sb+haha[i+1][z-1].second);
            big = max(big,dp[i-1][2][y-1]-haha[i-1][y-1].second);
            dp[i][0][j] = max(dp[i][0][j],big+haha[i-1][y-1].second);
        }
    }
    for(long long i = 0; i < dp[n-1][0].size(); i++) {
        ans = max(ans,dp[n-1][0][i]);
        ans = max(ans,dp[n-1][1][i]);
        ans = max(ans,dp[n-1][2][i]);
    }
    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: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 < bruh[i].size(); j++) {
      |                              ~~^~~~~~~~~~~~~~~~
fish.cpp:38:22: 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]
   38 |     for(int i = 0; i < haha[0].size(); i++) {
      |                    ~~^~~~~~~~~~~~~~~~
fish.cpp:39:17: 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]
   39 |         while(y < haha[1].size() && haha[0][i].first > haha[1][y].first) {
      |               ~~^~~~~~~~~~~~~~~~
fish.cpp:51: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]
   51 |         for(long long j = 0; j < haha[i].size(); j++) {
      |                              ~~^~~~~~~~~~~~~~~~
fish.cpp:52: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]
   52 |             while(y < haha[i-1].size()-1 && haha[i-1][y].first <= haha[i][j].first) {
      |                   ~~^~~~~~~~~~~~~~~~~~~~
fish.cpp:58:26: 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]
   58 |         for(int j = 0; j < haha[i-1].size(); j++) {
      |                        ~~^~~~~~~~~~~~~~~~~~
fish.cpp:64: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]
   64 |         for(long long j = 0; j < haha[i].size(); j++) {
      |                              ~~^~~~~~~~~~~~~~~~
fish.cpp:65: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]
   65 |             while(y < haha[i-1].size() && haha[i-1][y].first < haha[i][j].first) {
      |                   ~~^~~~~~~~~~~~~~~~~~
fish.cpp:68: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]
   68 |             while(z < haha[i+1].size() && haha[i+1][z].first < haha[i][j].first) {
      |                   ~~^~~~~~~~~~~~~~~~~~
fish.cpp:103: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]
  103 |         for(long long j = 0; j < haha[i].size(); j++) {
      |                              ~~^~~~~~~~~~~~~~~~
fish.cpp:104: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]
  104 |             while(y < haha[i-1].size() && haha[i-1][y].first < haha[i][j].first) {
      |                   ~~^~~~~~~~~~~~~~~~~~
fish.cpp:107: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]
  107 |             while(z < haha[i+1].size() && haha[i+1][y].first < haha[i][j].first) {
      |                   ~~^~~~~~~~~~~~~~~~~~
fish.cpp:115:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  115 |     for(long long i = 0; i < dp[n-1][0].size(); i++) {
      |                          ~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 84 ms 47324 KB Output is correct
2 Correct 87 ms 50664 KB Output is correct
3 Correct 51 ms 42560 KB Output is correct
4 Correct 53 ms 42532 KB Output is correct
5 Runtime error 200 ms 136472 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23784 KB Output is correct
2 Incorrect 109 ms 54228 KB 1st lines differ - on the 1st token, expected: '40604614618209', found: '40479831066969'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 49 ms 42448 KB Output is correct
2 Correct 51 ms 42464 KB Output is correct
3 Incorrect 97 ms 47844 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '23150706624296'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 23784 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 11 ms 23784 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 11 ms 23784 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 49 ms 42448 KB Output is correct
2 Correct 51 ms 42464 KB Output is correct
3 Incorrect 97 ms 47844 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '23150706624296'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 84 ms 47324 KB Output is correct
2 Correct 87 ms 50664 KB Output is correct
3 Correct 51 ms 42560 KB Output is correct
4 Correct 53 ms 42532 KB Output is correct
5 Runtime error 200 ms 136472 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -