답안 #838808

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
838808 2023-08-27T19:00:06 Z Andrey 메기 농장 (IOI22_fish) C++17
0 / 100
42 ms 29388 KB
#include "fish.h"
#include<bits/stdc++.h>
#include <vector>
using namespace std;

vector<pair<long long,long long>> haha[100001];
vector<pair<long long,long long>> bruh[100001];
vector<long long> dp[1001][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[i][0].push_back(0);
        dp[i][1].push_back(0);
        dp[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++) {
            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][j][2]);
        }
        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:30: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]
   30 |         for(long long j = 0; j < bruh[i].size(); j++) {
      |                              ~~^~~~~~~~~~~~~~~~
fish.cpp:36: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]
   36 |     for(int i = 0; i < haha[0].size(); i++) {
      |                    ~~^~~~~~~~~~~~~~~~
fish.cpp:37: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]
   37 |         while(y < haha[1].size() && haha[0][i].first > haha[1][y].first) {
      |               ~~^~~~~~~~~~~~~~~~
fish.cpp:49: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]
   49 |         for(long long j = 0; j < haha[i].size(); j++) {
      |                              ~~^~~~~~~~~~~~~~~~
fish.cpp:50: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]
   50 |             while(y < haha[i-1].size() && haha[i-1][y].first <= haha[i][j].first) {
      |                   ~~^~~~~~~~~~~~~~~~~~
fish.cpp:56: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]
   56 |         for(int j = 0; j < haha[i-1].size(); j++) {
      |                        ~~^~~~~~~~~~~~~~~~~~
fish.cpp:62: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]
   62 |         for(long long j = 0; j < haha[i].size(); j++) {
      |                              ~~^~~~~~~~~~~~~~~~
fish.cpp:63: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]
   63 |             while(y < haha[i-1].size() && haha[i-1][y].first <= haha[i][j].first) {
      |                   ~~^~~~~~~~~~~~~~~~~~
fish.cpp:66: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]
   66 |             while(z < haha[i+1].size() && haha[i+1][z].first <= haha[i][j].first) {
      |                   ~~^~~~~~~~~~~~~~~~~~
fish.cpp:101: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]
  101 |         for(long long j = 0; j < haha[i].size(); j++) {
      |                              ~~^~~~~~~~~~~~~~~~
fish.cpp:102: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]
  102 |             while(y < haha[i-1].size() && haha[i-1][y].first < haha[i][j].first) {
      |                   ~~^~~~~~~~~~~~~~~~~~
fish.cpp:105: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]
  105 |             while(z < haha[i+1].size() && haha[i+1][y].first < haha[i][j].first) {
      |                   ~~^~~~~~~~~~~~~~~~~~
fish.cpp:113: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]
  113 |     for(long long i = 0; i < dp[n-1][0].size(); i++) {
      |                          ~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 42 ms 26756 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 5076 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 32 ms 29388 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Incorrect 2 ms 5076 KB 1st lines differ - on the 1st token, expected: '4044', found: '2022'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Incorrect 2 ms 5076 KB 1st lines differ - on the 1st token, expected: '4044', found: '2022'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Incorrect 2 ms 5076 KB 1st lines differ - on the 1st token, expected: '4044', found: '2022'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 32 ms 29388 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 42 ms 26756 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -