답안 #838828

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
838828 2023-08-27T20:05:42 Z Andrey 메기 농장 (IOI22_fish) C++17
0 / 100
233 ms 158824 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({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;
        }
    }
    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:55: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]
   55 |         for(long long j = 0; j < haha[i].size(); j++) {
      |                              ~~^~~~~~~~~~~~~~~~
fish.cpp:56: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]
   56 |             while(y < haha[i-1].size() && haha[i-1][y].first <= haha[i][j].first) {
      |                   ~~^~~~~~~~~~~~~~~~~~
fish.cpp:62: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]
   62 |         for(int j = 0; j < haha[i-1].size(); j++) {
      |                        ~~^~~~~~~~~~~~~~~~~~
fish.cpp:68: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]
   68 |         for(long long j = 0; j < haha[i].size(); j++) {
      |                              ~~^~~~~~~~~~~~~~~~
fish.cpp:69: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]
   69 |             while(y < haha[i-1].size() && haha[i-1][y].first <= haha[i][j].first) {
      |                   ~~^~~~~~~~~~~~~~~~~~
fish.cpp:72: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]
   72 |             while(z < haha[i+1].size() && haha[i+1][z].first <= haha[i][j].first) {
      |                   ~~^~~~~~~~~~~~~~~~~~
fish.cpp:107: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]
  107 |         for(long long j = 0; j < haha[i].size(); j++) {
      |                              ~~^~~~~~~~~~~~~~~~
fish.cpp:108: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]
  108 |             while(y < haha[i-1].size() && haha[i-1][y].first <= haha[i][j].first) {
      |                   ~~^~~~~~~~~~~~~~~~~~
fish.cpp:111: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]
  111 |             while(z < haha[i+1].size() && haha[i+1][y].first <= haha[i][j].first) {
      |                   ~~^~~~~~~~~~~~~~~~~~
fish.cpp:119: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]
  119 |     for(long long i = 0; i < dp[n-1][0].size(); i++) {
      |                          ~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 105 ms 57308 KB Output is correct
2 Correct 111 ms 61548 KB Output is correct
3 Correct 75 ms 53524 KB Output is correct
4 Correct 74 ms 53452 KB Output is correct
5 Runtime error 233 ms 158824 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 23788 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 53468 KB Output is correct
2 Correct 74 ms 53412 KB Output is correct
3 Incorrect 108 ms 52256 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '26860403425264'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 23764 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 23764 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 23764 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 53468 KB Output is correct
2 Correct 74 ms 53412 KB Output is correct
3 Incorrect 108 ms 52256 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '26860403425264'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 105 ms 57308 KB Output is correct
2 Correct 111 ms 61548 KB Output is correct
3 Correct 75 ms 53524 KB Output is correct
4 Correct 74 ms 53452 KB Output is correct
5 Runtime error 233 ms 158824 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -