Submission #838826

# Submission time Handle Problem Language Result Execution time Memory
838826 2023-08-27T20:03:59 Z Andrey Catfish Farm (IOI22_fish) C++17
0 / 100
98 ms 45620 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[100001];
vector<pair<long long,long long>> bruh[100001];
vector<long long> dp[100001][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({n+1,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);
        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++) {
            haha[i].push_back({bruh[i][j].first,br});
            br+=bruh[i][j].second;
        }
    }
    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;
            cout << dp[0][0][i] << " ";
        }
    }
    cout << endl;
    long long ans = 0,z = 0,sb = 0;
    for(long long i = 1; i < n; i++) {
        y = 1;
        z = 1;
        sb = 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++;
            }
            dp[i][2][j] = max(dp[i][2][j],dp[i-1][0][y-1]);
            dp[i][2][j] = max(dp[i][2][j],dp[i-1][1][y-1]);
        }
        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:36: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]
   36 |         for(long long j = 0; j < bruh[i].size(); j++) {
      |                              ~~^~~~~~~~~~~~~~~~
fish.cpp:42: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]
   42 |     for(int i = 0; i < haha[0].size(); i++) {
      |                    ~~^~~~~~~~~~~~~~~~
fish.cpp:43: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]
   43 |         while(y < haha[1].size() && haha[0][i].first > haha[1][y].first) {
      |               ~~^~~~~~~~~~~~~~~~
fish.cpp:57: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]
   57 |         for(long long j = 0; j < haha[i].size(); j++) {
      |                              ~~^~~~~~~~~~~~~~~~
fish.cpp:58: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]
   58 |             while(y < haha[i-1].size() && haha[i-1][y].first <= haha[i][j].first) {
      |                   ~~^~~~~~~~~~~~~~~~~~
fish.cpp:64: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]
   64 |         for(int j = 0; j < haha[i-1].size(); j++) {
      |                        ~~^~~~~~~~~~~~~~~~~~
fish.cpp:70: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]
   70 |         for(long long j = 0; j < haha[i].size(); j++) {
      |                              ~~^~~~~~~~~~~~~~~~
fish.cpp:71: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]
   71 |             while(y < haha[i-1].size() && haha[i-1][y].first <= haha[i][j].first) {
      |                   ~~^~~~~~~~~~~~~~~~~~
fish.cpp:74: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]
   74 |             while(z < haha[i+1].size() && haha[i+1][z].first <= haha[i][j].first) {
      |                   ~~^~~~~~~~~~~~~~~~~~
fish.cpp:109: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]
  109 |         for(long long j = 0; j < haha[i].size(); j++) {
      |                              ~~^~~~~~~~~~~~~~~~
fish.cpp:110: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]
  110 |             while(y < haha[i-1].size() && haha[i-1][y].first <= haha[i][j].first) {
      |                   ~~^~~~~~~~~~~~~~~~~~
fish.cpp:113: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]
  113 |             while(z < haha[i+1].size() && haha[i+1][y].first <= haha[i][j].first) {
      |                   ~~^~~~~~~~~~~~~~~~~~
fish.cpp:121: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]
  121 |     for(long long i = 0; i < dp[n-1][0].size(); i++) {
      |                          ~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 98 ms 45620 KB Possible tampering with the output
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 11988 KB Possible tampering with the output
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 74 ms 41748 KB Possible tampering with the output
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 11988 KB Possible tampering with the output
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 11988 KB Possible tampering with the output
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 11988 KB Possible tampering with the output
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 74 ms 41748 KB Possible tampering with the output
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 98 ms 45620 KB Possible tampering with the output
2 Halted 0 ms 0 KB -