답안 #1079705

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1079705 2024-08-28T21:49:25 Z ArthuroWich 메기 농장 (IOI22_fish) C++17
100 / 100
239 ms 38632 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+5, vector<pair<int, int>>(1, {INT64_MIN, 0}));
    ind.resize(n+5);
    for (int i = 0; i < m; i++) {
        pref[X[i]+1].push_back({Y[i], W[i]});
    }
    for (int i = 0; i <= n; i++) {
        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;
        }
    }
    ind[0].push_back(-1);
    ind[n+1].push_back(-1);
    for (int i = 1; i <= n; i++) {
        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(2, vector<int>(ind[0].size()+5, 0)); // 0 is increasing, 1 is decreasing, increasing can go to decreasing, decreasing cant go to increasing if next to eachother
    for (int j = 1; j <= n+1; j++) {
        vector<vector<int>> tdp(2, vector<int>(ind[j].size()+5, 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[0], tdp[0]);
        swap(dp[1], tdp[1]);
    }
    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:25: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]
   25 |         for (int j = 1; j < pref[i].size(); j++) {
      |                         ~~^~~~~~~~~~~~~~~~
fish.cpp:45: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]
   45 |         for (int i = 0; i < ind[j].size(); i++) {
      |                         ~~^~~~~~~~~~~~~~~
fish.cpp:47: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]
   47 |             while(k < ind[j-1].size() && ind[j-1][k] <= x) {
      |                   ~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 17228 KB Output is correct
2 Correct 57 ms 19916 KB Output is correct
3 Correct 21 ms 11352 KB Output is correct
4 Correct 27 ms 11356 KB Output is correct
5 Correct 164 ms 35516 KB Output is correct
6 Correct 160 ms 37376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 111 ms 24536 KB Output is correct
3 Correct 116 ms 28352 KB Output is correct
4 Correct 54 ms 17288 KB Output is correct
5 Correct 56 ms 19896 KB Output is correct
6 Correct 1 ms 344 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 348 KB Output is correct
10 Correct 19 ms 11356 KB Output is correct
11 Correct 20 ms 11356 KB Output is correct
12 Correct 54 ms 18040 KB Output is correct
13 Correct 66 ms 20936 KB Output is correct
14 Correct 52 ms 17700 KB Output is correct
15 Correct 63 ms 19132 KB Output is correct
16 Correct 72 ms 17676 KB Output is correct
17 Correct 59 ms 19648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 11352 KB Output is correct
2 Correct 20 ms 11188 KB Output is correct
3 Correct 39 ms 14428 KB Output is correct
4 Correct 35 ms 14160 KB Output is correct
5 Correct 59 ms 19280 KB Output is correct
6 Correct 55 ms 18516 KB Output is correct
7 Correct 60 ms 19280 KB Output is correct
8 Correct 75 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 1 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 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 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 1 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 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 21 ms 3788 KB Output is correct
18 Correct 18 ms 4956 KB Output is correct
19 Correct 19 ms 4696 KB Output is correct
20 Correct 15 ms 4952 KB Output is correct
21 Correct 14 ms 4700 KB Output is correct
22 Correct 28 ms 9052 KB Output is correct
23 Correct 6 ms 1116 KB Output is correct
24 Correct 13 ms 2908 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 4 ms 1116 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 1 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 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 21 ms 3788 KB Output is correct
18 Correct 18 ms 4956 KB Output is correct
19 Correct 19 ms 4696 KB Output is correct
20 Correct 15 ms 4952 KB Output is correct
21 Correct 14 ms 4700 KB Output is correct
22 Correct 28 ms 9052 KB Output is correct
23 Correct 6 ms 1116 KB Output is correct
24 Correct 13 ms 2908 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 4 ms 1116 KB Output is correct
27 Correct 2 ms 860 KB Output is correct
28 Correct 92 ms 19724 KB Output is correct
29 Correct 159 ms 25828 KB Output is correct
30 Correct 169 ms 25936 KB Output is correct
31 Correct 128 ms 25812 KB Output is correct
32 Correct 103 ms 28244 KB Output is correct
33 Correct 146 ms 25936 KB Output is correct
34 Correct 129 ms 25680 KB Output is correct
35 Correct 44 ms 11224 KB Output is correct
36 Correct 184 ms 28768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 11352 KB Output is correct
2 Correct 20 ms 11188 KB Output is correct
3 Correct 39 ms 14428 KB Output is correct
4 Correct 35 ms 14160 KB Output is correct
5 Correct 59 ms 19280 KB Output is correct
6 Correct 55 ms 18516 KB Output is correct
7 Correct 60 ms 19280 KB Output is correct
8 Correct 75 ms 19280 KB Output is correct
9 Correct 57 ms 19048 KB Output is correct
10 Correct 44 ms 14928 KB Output is correct
11 Correct 96 ms 29524 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 0 ms 344 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 19 ms 11404 KB Output is correct
19 Correct 18 ms 11352 KB Output is correct
20 Correct 20 ms 11404 KB Output is correct
21 Correct 18 ms 11356 KB Output is correct
22 Correct 60 ms 20564 KB Output is correct
23 Correct 90 ms 29648 KB Output is correct
24 Correct 137 ms 29776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 17228 KB Output is correct
2 Correct 57 ms 19916 KB Output is correct
3 Correct 21 ms 11352 KB Output is correct
4 Correct 27 ms 11356 KB Output is correct
5 Correct 164 ms 35516 KB Output is correct
6 Correct 160 ms 37376 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 111 ms 24536 KB Output is correct
9 Correct 116 ms 28352 KB Output is correct
10 Correct 54 ms 17288 KB Output is correct
11 Correct 56 ms 19896 KB Output is correct
12 Correct 1 ms 344 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 348 KB Output is correct
16 Correct 19 ms 11356 KB Output is correct
17 Correct 20 ms 11356 KB Output is correct
18 Correct 54 ms 18040 KB Output is correct
19 Correct 66 ms 20936 KB Output is correct
20 Correct 52 ms 17700 KB Output is correct
21 Correct 63 ms 19132 KB Output is correct
22 Correct 72 ms 17676 KB Output is correct
23 Correct 59 ms 19648 KB Output is correct
24 Correct 20 ms 11352 KB Output is correct
25 Correct 20 ms 11188 KB Output is correct
26 Correct 39 ms 14428 KB Output is correct
27 Correct 35 ms 14160 KB Output is correct
28 Correct 59 ms 19280 KB Output is correct
29 Correct 55 ms 18516 KB Output is correct
30 Correct 60 ms 19280 KB Output is correct
31 Correct 75 ms 19280 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 21 ms 3788 KB Output is correct
49 Correct 18 ms 4956 KB Output is correct
50 Correct 19 ms 4696 KB Output is correct
51 Correct 15 ms 4952 KB Output is correct
52 Correct 14 ms 4700 KB Output is correct
53 Correct 28 ms 9052 KB Output is correct
54 Correct 6 ms 1116 KB Output is correct
55 Correct 13 ms 2908 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 4 ms 1116 KB Output is correct
58 Correct 2 ms 860 KB Output is correct
59 Correct 92 ms 19724 KB Output is correct
60 Correct 159 ms 25828 KB Output is correct
61 Correct 169 ms 25936 KB Output is correct
62 Correct 128 ms 25812 KB Output is correct
63 Correct 103 ms 28244 KB Output is correct
64 Correct 146 ms 25936 KB Output is correct
65 Correct 129 ms 25680 KB Output is correct
66 Correct 44 ms 11224 KB Output is correct
67 Correct 184 ms 28768 KB Output is correct
68 Correct 57 ms 19048 KB Output is correct
69 Correct 44 ms 14928 KB Output is correct
70 Correct 96 ms 29524 KB Output is correct
71 Correct 0 ms 344 KB Output is correct
72 Correct 1 ms 344 KB Output is correct
73 Correct 0 ms 344 KB Output is correct
74 Correct 0 ms 348 KB Output is correct
75 Correct 0 ms 348 KB Output is correct
76 Correct 0 ms 348 KB Output is correct
77 Correct 19 ms 11404 KB Output is correct
78 Correct 18 ms 11352 KB Output is correct
79 Correct 20 ms 11404 KB Output is correct
80 Correct 18 ms 11356 KB Output is correct
81 Correct 60 ms 20564 KB Output is correct
82 Correct 90 ms 29648 KB Output is correct
83 Correct 137 ms 29776 KB Output is correct
84 Correct 239 ms 35064 KB Output is correct
85 Correct 196 ms 35496 KB Output is correct
86 Correct 145 ms 37460 KB Output is correct
87 Correct 179 ms 38480 KB Output is correct
88 Correct 0 ms 344 KB Output is correct
89 Correct 162 ms 38632 KB Output is correct
90 Correct 144 ms 36948 KB Output is correct
91 Correct 126 ms 37220 KB Output is correct