답안 #1035829

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1035829 2024-07-26T16:29:19 Z Andrey 메기 농장 (IOI22_fish) C++17
9 / 100
59 ms 33104 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]});
    }
    haha[0].push_back({0,0});
    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);
    dp[0][0].push_back(-LLONG_MAX/2);
    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 >= 0; j--) {
            while(y >= 0 && (j == 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) {
                dp[i][1][j] = max(dp[i][1][j],max(dp[i-1][0][y],dp[i-1][2][y])+haha[i][j].second);
                y++;
            }
        }
        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 >= 0; j--) {
            while(y >= 0 && (j == 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:16: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]
   16 |         for(long long j = 1; j < haha[i].size(); j++) {
      |                              ~~^~~~~~~~~~~~~~~~
fish.cpp:19: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]
   19 |         for(long long j = 1; j < haha[i].size(); j++) {
      |                              ~~^~~~~~~~~~~~~~~~
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 < haha[i].size(); j++) {
      |                              ~~^~~~~~~~~~~~~~~~
fish.cpp:46: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]
   46 |         for(long long j = 0; j < haha[i].size(); j++) {
      |                              ~~^~~~~~~~~~~~~~~~
fish.cpp:47: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]
   47 |             while(y < haha[i-1].size() && haha[i-1][y].first <= haha[i][j].first) {
      |                   ~~^~~~~~~~~~~~~~~~~~
fish.cpp:54: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]
   54 |         for(long long j = 0; j < haha[i].size(); j++) {
      |                              ~~^~~~~~~~~~~~~~~~
fish.cpp:55: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]
   55 |             while(y < haha[i-1].size() && haha[i-1][y].first <= haha[i][j].first) {
      |                   ~~^~~~~~~~~~~~~~~~~~
fish.cpp:74: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]
   74 |     for(long long i = 0; i < haha[n].size(); i++) {
      |                          ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 48 ms 32484 KB 1st lines differ - on the 1st token, expected: '40313272768926', found: '223762357'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 26972 KB Output is correct
2 Correct 26 ms 26972 KB Output is correct
3 Correct 39 ms 28816 KB Output is correct
4 Correct 35 ms 29020 KB Output is correct
5 Correct 56 ms 33104 KB Output is correct
6 Correct 55 ms 32340 KB Output is correct
7 Correct 57 ms 32976 KB Output is correct
8 Correct 58 ms 33032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 14428 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 14428 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 14428 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 26972 KB Output is correct
2 Correct 26 ms 26972 KB Output is correct
3 Correct 39 ms 28816 KB Output is correct
4 Correct 35 ms 29020 KB Output is correct
5 Correct 56 ms 33104 KB Output is correct
6 Correct 55 ms 32340 KB Output is correct
7 Correct 57 ms 32976 KB Output is correct
8 Correct 58 ms 33032 KB Output is correct
9 Incorrect 59 ms 32756 KB 1st lines differ - on the 1st token, expected: '99999', found: '66666'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 48 ms 32484 KB 1st lines differ - on the 1st token, expected: '40313272768926', found: '223762357'
2 Halted 0 ms 0 KB -