답안 #1079704

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1079704 2024-08-28T21:48:23 Z ArthuroWich 메기 농장 (IOI22_fish) C++17
26 / 100
164 ms 38504 KB
#include "fish.h"
#include<bits/stdc++.h>
using namespace std;
#define int long long int
vector<vector<int>> ind;
vector<vector<pair<int, int>>> pref;
int query(int i, int j) {
    pair<int, int> c = {j, INT64_MAX};
    auto ind = upper_bound(pref[i].begin(), pref[i].end(), c);
    ind--;
    c = *ind;
    return c.second;
}
int max_weights(int32_t N, int32_t M, vector<int32_t> X, vector<int32_t> Y, vector<int32_t> W) {
    int n = N, m = M;
    pref.resize(n+1);
    ind.resize(n+1);
    for (int i = 0; i < m; i++) {
        pref[X[i]].push_back({Y[i], W[i]});
    }
    pref[n] = {{-1, 0}};
    for (int i = 0; i <= n; i++) {
        pref[i].push_back({-1, 0}); // to make 1-indexed
        sort(pref[i].begin(), pref[i].end());
    }
    for (int i = 0; i <= n; i++) {
        for (int j = 1; j < pref[i].size(); j++) {
            pref[i][j].second += pref[i][j-1].second;
        }
    }
    for (int i = 0; i < n; i++) {
        if (i != 0) {
            for (auto [a, b] : pref[i-1]) {
                ind[i].push_back(a);
            }
        }
        for (auto [a, b] : pref[i+1]) {
            ind[i].push_back(a);
        }
        sort(ind[i].begin(), ind[i].end());
        ind[i].erase(unique(ind[i].begin(), ind[i].end()), ind[i].end());
    }
    vector<vector<int>> dp(ind[0].size()+1, vector<int>(1, 0)); // 0 is increasing, 1 is decreasing, increasing can go to decreasing, decreasing cant go to increasing if next to eachother
    ind[n].push_back(-1);
    for (int j = 1; j <= n; j++) {
        vector<vector<int>> tdp(2, vector<int>(ind[j].size()+1, 0));
        int v = 0, k = 0;
        for (int i = 0; i < ind[j].size(); i++) {
            int x = ind[j][i];
            while(k < ind[j-1].size() && ind[j-1][k] <= x) {
                v = max(v, dp[0][k]-query(j-1, ind[j-1][k]));
                k++;
            }
            tdp[0][i] = max(v+query(j-1, x), dp[1][0]);
        }
        v = 0;
        k = ind[j-1].size();
        for (int i = ind[j].size()-1; i >= 0; i--) {
            int x = ind[j][i];
            while(k > 0 && ind[j-1][k-1] >= x) {
                k--;
                v = max(v, max(dp[0][k], dp[1][k])+query(j, ind[j-1][k]));
            }
            tdp[1][i] = v-query(j, x);
        }
        swap(dp, tdp);
    }
    int ans = max(dp[0][0], dp[1][0]);
    return ans;
}

Compilation message

fish.cpp: In function 'long long int max_weights(int32_t, int32_t, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:27:27: 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]
   27 |         for (int j = 1; j < pref[i].size(); j++) {
      |                         ~~^~~~~~~~~~~~~~~~
fish.cpp:48:27: 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]
   48 |         for (int i = 0; i < ind[j].size(); i++) {
      |                         ~~^~~~~~~~~~~~~~~
fish.cpp:50:21: 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]
   50 |             while(k < ind[j-1].size() && ind[j-1][k] <= x) {
      |                   ~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 17344 KB Output is correct
2 Correct 59 ms 20160 KB Output is correct
3 Correct 19 ms 11352 KB Output is correct
4 Correct 20 ms 11356 KB Output is correct
5 Correct 164 ms 36528 KB Output is correct
6 Correct 135 ms 38504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 96 ms 27572 KB Output is correct
3 Correct 119 ms 32696 KB Output is correct
4 Correct 50 ms 17472 KB Output is correct
5 Correct 71 ms 20000 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 20 ms 11356 KB Output is correct
11 Correct 19 ms 11408 KB Output is correct
12 Incorrect 60 ms 20420 KB 1st lines differ - on the 1st token, expected: '40374264367003', found: '40374264367036'
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 11376 KB Output is correct
2 Correct 19 ms 11352 KB Output is correct
3 Correct 39 ms 14168 KB Output is correct
4 Correct 31 ms 13912 KB Output is correct
5 Correct 54 ms 19280 KB Output is correct
6 Correct 51 ms 18512 KB Output is correct
7 Correct 62 ms 19280 KB Output is correct
8 Correct 54 ms 19280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Incorrect 1 ms 348 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '216638282549'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Incorrect 1 ms 348 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '216638282549'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Incorrect 1 ms 348 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '216638282549'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 11376 KB Output is correct
2 Correct 19 ms 11352 KB Output is correct
3 Correct 39 ms 14168 KB Output is correct
4 Correct 31 ms 13912 KB Output is correct
5 Correct 54 ms 19280 KB Output is correct
6 Correct 51 ms 18512 KB Output is correct
7 Correct 62 ms 19280 KB Output is correct
8 Correct 54 ms 19280 KB Output is correct
9 Correct 59 ms 19132 KB Output is correct
10 Correct 43 ms 15180 KB Output is correct
11 Correct 103 ms 30028 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 20 ms 11416 KB Output is correct
19 Correct 22 ms 11580 KB Output is correct
20 Correct 24 ms 11356 KB Output is correct
21 Correct 19 ms 11352 KB Output is correct
22 Correct 64 ms 20360 KB Output is correct
23 Correct 98 ms 30036 KB Output is correct
24 Correct 90 ms 30544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 17344 KB Output is correct
2 Correct 59 ms 20160 KB Output is correct
3 Correct 19 ms 11352 KB Output is correct
4 Correct 20 ms 11356 KB Output is correct
5 Correct 164 ms 36528 KB Output is correct
6 Correct 135 ms 38504 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 96 ms 27572 KB Output is correct
9 Correct 119 ms 32696 KB Output is correct
10 Correct 50 ms 17472 KB Output is correct
11 Correct 71 ms 20000 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 20 ms 11356 KB Output is correct
17 Correct 19 ms 11408 KB Output is correct
18 Incorrect 60 ms 20420 KB 1st lines differ - on the 1st token, expected: '40374264367003', found: '40374264367036'
19 Halted 0 ms 0 KB -