답안 #732515

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
732515 2023-04-29T05:12:31 Z math_rabbit_1028 메기 농장 (IOI22_fish) C++17
9 / 100
237 ms 53212 KB
#include "fish.h"
#include <bits/stdc++.h>
#include <vector>
using namespace std;

long long zero[101010], full[101010];
vector< pair<int, long long> > ylist[101010];
vector< long long > sum[101010], dp[2][101010];

long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {
    for (int i = 0; i < M; i++) {
        X[i] += 1;
        Y[i] += 1;
        ylist[X[i]].push_back({Y[i], 0});
        ylist[X[i] - 1].push_back({Y[i], 0});
        ylist[X[i] + 1].push_back({Y[i], 0});
    }

    for (int i = 0; i <= N + 1; i++) {
        ylist[i].push_back({0, 0});
        ylist[i].push_back({N, 0});
        sort(ylist[i].begin(), ylist[i].end());
        ylist[i].erase(unique(ylist[i].begin(), ylist[i].end()), ylist[i].end());
    }

    for (int i = 0; i < M; i++) {
        int idx = lower_bound(ylist[X[i]].begin(), ylist[X[i]].end(), make_pair(Y[i], 0LL)) - ylist[X[i]].begin();
        ylist[X[i]][idx].second = W[i];
    }

    for (int i = 0; i <= N + 1; i++) {
        sum[i].push_back(0);
        for (int j = 1; j < ylist[i].size(); j++) {
            sum[i].push_back(sum[i].back() + ylist[i][j].second);
        }
    }

    for (int i = 0; i <= N + 1; i++) {
        for (int j = 0; j < ylist[i].size(); j++) dp[0][i].push_back(0);
        for (int j = 0; j < ylist[i].size(); j++) dp[1][i].push_back(0);
    }
    for (int j = 1; j < ylist[0].size() - 1; j++) dp[0][0][j] = -1e18;
    for (int j = 1; j < ylist[0].size() - 1; j++) dp[1][0][j] = -1e18;
    full[0] = -1e18;
    for (int i = 2; i <= N + 1; i++) {
        long long val0 = 0, val1 = 0;
        for (int k = 1; k < ylist[i - 1].size() - 1; k++) {
            val0 = max(val0, dp[0][i - 1][k] - sum[i - 1][k]);
            val1 = max(val1, dp[1][i - 1][k] + sum[i][k]);
        }
        zero[i] = max(val1, max(zero[i - 1], full[i - 1] + sum[i][ylist[i].size() - 1]));
        for (int j = 1; j < ylist[i].size() - 1; j++) {
            dp[1][i][j] = max(dp[1][i][j], val1 - sum[i][j]);
            dp[1][i][j] = max(dp[1][i][j], full[i - 1] + sum[i][ylist[i].size() - 1] - sum[i][j]);
        }

        for (int j = 1; j < ylist[i].size() - 1; j++) {
            int k = lower_bound(ylist[i - 1].begin(), ylist[i - 1].end(), make_pair(ylist[i][j].first, 0LL))
                  - ylist[i - 1].begin();
            assert(k < ylist[i - 1].size());
            dp[0][i][j] = max(dp[0][i][j], val0 + sum[i - 1][k]);
            dp[0][i][j] = max(dp[0][i][j], zero[i - 2] + sum[i - 1][k]);
            dp[0][i][j] = max(dp[0][i][j], full[i - 2] + sum[i - 1][ylist[i - 1].size() - 1]);
        }
        long long val2 = 0;
        int l = 0;
        for (int j = 1; j < ylist[i].size() - 1; j++) {
            int k = lower_bound(ylist[i - 1].begin(), ylist[i - 1].end(), make_pair(ylist[i][j].first, 0LL))
                  - ylist[i - 1].begin();
            assert(k < ylist[i - 1].size());
            while (l < ylist[i - 2].size() && ylist[i - 2][l].first <= j) {
                val2 = max(val2, dp[1][i - 2][l]);
                l++;
            }
            dp[0][i][j] = max(dp[0][i][j], val2 + sum[i - 1][k]);
        }
        long long val3 = 0;
        l = ylist[i - 2].size() - 1;
        for (int j = ylist[i].size() - 1; j >= 1; j--) {
            int k = lower_bound(ylist[i - 1].begin(), ylist[i - 1].end(), make_pair(ylist[i][j].first, 0LL))
                  - ylist[i - 1].begin();
            assert(k < ylist[i - 1].size());
            while (l >= 0 && ylist[i - 2][l].first >= j) {
                val3 = max(val3, dp[1][i - 2][l] + sum[i - 1][k]);
                l--;
            }
            dp[0][i][j] = max(dp[0][i][j], val3);
        }

        full[i] = max(val0 + sum[i - 1][ylist[i - 1].size() - 1], full[i - 1]);
        full[i] = max(full[i], zero[i - 2] + sum[i - 1][ylist[i - 1].size() - 1]);
        full[i] = max(full[i], full[i - 2] + sum[i - 1][ylist[i - 1].size() - 1]);
        full[i] = max(full[i], val2 + sum[i - 1][ylist[i - 1].size() - 1]);
        /*
        for (int j = 0; j < ylist[i].size(); j++) cout << ylist[i][j].first << " ";
        cout << "\n";
        cout << zero[i] << " ";
        for (int j = 1; j < ylist[i].size() - 1; j++) cout << dp[0][i][j] << " ";
        cout << full[i] << "\n";
        cout << zero[i] << " ";
        for (int j = 1; j < ylist[i].size() - 1; j++) cout << dp[1][i][j] << " ";
        cout << full[i] << "\n";
        cout << "\n";
        */
    }
    long long res = 0;
    res = zero[N + 1];
    return res;
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:33:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |         for (int j = 1; j < ylist[i].size(); j++) {
      |                         ~~^~~~~~~~~~~~~~~~~
fish.cpp:39:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         for (int j = 0; j < ylist[i].size(); j++) dp[0][i].push_back(0);
      |                         ~~^~~~~~~~~~~~~~~~~
fish.cpp:40:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         for (int j = 0; j < ylist[i].size(); j++) dp[1][i].push_back(0);
      |                         ~~^~~~~~~~~~~~~~~~~
fish.cpp:42:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     for (int j = 1; j < ylist[0].size() - 1; j++) dp[0][0][j] = -1e18;
      |                     ~~^~~~~~~~~~~~~~~~~~~~~
fish.cpp:43:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     for (int j = 1; j < ylist[0].size() - 1; j++) dp[1][0][j] = -1e18;
      |                     ~~^~~~~~~~~~~~~~~~~~~~~
fish.cpp:47:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         for (int k = 1; k < ylist[i - 1].size() - 1; k++) {
      |                         ~~^~~~~~~~~~~~~~~~~~~~~~~~~
fish.cpp:52:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         for (int j = 1; j < ylist[i].size() - 1; j++) {
      |                         ~~^~~~~~~~~~~~~~~~~~~~~
fish.cpp:57:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |         for (int j = 1; j < ylist[i].size() - 1; j++) {
      |                         ~~^~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from fish.cpp:2:
fish.cpp:60:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |             assert(k < ylist[i - 1].size());
      |                    ~~^~~~~~~~~~~~~~~~~~~~~
fish.cpp:67:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |         for (int j = 1; j < ylist[i].size() - 1; j++) {
      |                         ~~^~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from fish.cpp:2:
fish.cpp:70:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |             assert(k < ylist[i - 1].size());
      |                    ~~^~~~~~~~~~~~~~~~~~~~~
fish.cpp:71:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |             while (l < ylist[i - 2].size() && ylist[i - 2][l].first <= j) {
      |                    ~~^~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from fish.cpp:2:
fish.cpp:82:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |             assert(k < ylist[i - 1].size());
      |                    ~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 167 ms 36508 KB 1st lines differ - on the 1st token, expected: '40313272768926', found: '140724603543425'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9804 KB Output is correct
2 Incorrect 229 ms 44608 KB 1st lines differ - on the 1st token, expected: '40604614618209', found: '181211757187945'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 25376 KB Output is correct
2 Correct 43 ms 25436 KB Output is correct
3 Correct 108 ms 33504 KB Output is correct
4 Correct 90 ms 32360 KB Output is correct
5 Correct 171 ms 43516 KB Output is correct
6 Correct 161 ms 43216 KB Output is correct
7 Correct 157 ms 43940 KB Output is correct
8 Correct 155 ms 43868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9800 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 6 ms 9796 KB Output is correct
4 Correct 6 ms 9684 KB Output is correct
5 Correct 5 ms 9796 KB Output is correct
6 Correct 5 ms 9792 KB Output is correct
7 Correct 6 ms 9792 KB Output is correct
8 Correct 5 ms 9796 KB Output is correct
9 Correct 6 ms 9804 KB Output is correct
10 Incorrect 8 ms 10120 KB 1st lines differ - on the 1st token, expected: '799839985182', found: '801326851508'
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9800 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 6 ms 9796 KB Output is correct
4 Correct 6 ms 9684 KB Output is correct
5 Correct 5 ms 9796 KB Output is correct
6 Correct 5 ms 9792 KB Output is correct
7 Correct 6 ms 9792 KB Output is correct
8 Correct 5 ms 9796 KB Output is correct
9 Correct 6 ms 9804 KB Output is correct
10 Incorrect 8 ms 10120 KB 1st lines differ - on the 1st token, expected: '799839985182', found: '801326851508'
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9800 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 6 ms 9796 KB Output is correct
4 Correct 6 ms 9684 KB Output is correct
5 Correct 5 ms 9796 KB Output is correct
6 Correct 5 ms 9792 KB Output is correct
7 Correct 6 ms 9792 KB Output is correct
8 Correct 5 ms 9796 KB Output is correct
9 Correct 6 ms 9804 KB Output is correct
10 Incorrect 8 ms 10120 KB 1st lines differ - on the 1st token, expected: '799839985182', found: '801326851508'
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 25376 KB Output is correct
2 Correct 43 ms 25436 KB Output is correct
3 Correct 108 ms 33504 KB Output is correct
4 Correct 90 ms 32360 KB Output is correct
5 Correct 171 ms 43516 KB Output is correct
6 Correct 161 ms 43216 KB Output is correct
7 Correct 157 ms 43940 KB Output is correct
8 Correct 155 ms 43868 KB Output is correct
9 Correct 171 ms 53212 KB Output is correct
10 Correct 109 ms 29032 KB Output is correct
11 Incorrect 237 ms 48320 KB 1st lines differ - on the 1st token, expected: '72889508713304', found: '72890221687387'
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 167 ms 36508 KB 1st lines differ - on the 1st token, expected: '40313272768926', found: '140724603543425'
2 Halted 0 ms 0 KB -