답안 #632031

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
632031 2022-08-19T10:28:30 Z timreizin 메기 농장 (IOI22_fish) C++17
100 / 100
171 ms 29288 KB
#include "fish.h"

#include <vector>
#include <algorithm>

using namespace std;

using ll = long long;

ll solve(vector<vector<pair<int, ll>>> &fish, int n)
{
    ll res = 0;
    vector<vector<ll>> dp0(fish.size()), dp1(fish.size());
    for (int i = 0; i < fish.size(); ++i)
    {
        fish[i].emplace_back(n, 0);
        dp0[i].resize(fish[i].size());
        ll mx = 0;
        if (i != 0)
        {
            for (int j = 0; j < fish[i - 1].size(); ++j)
            {
                mx = max(mx, dp1[i - 1][j]);
            }
            fill(dp0[i].begin(), dp0[i].end(), mx);
            mx = 0;
        }
        for (int j = 0, k = 0; j < fish[i].size(); ++j)
        {
            if (i != 0)
            {
                while (k < fish[i - 1].size() && fish[i - 1][k].first < fish[i][j].first)
                {
                    mx = max(mx, dp0[i - 1][k]);
                    mx += fish[i - 1][k].second;
                    ++k;
                }
            }
            dp0[i][j] = max(mx, dp0[i][j]);
        }
        dp1[i] = dp0[i];
        if (i != 0)
        {
            ll mx = 0;
            for (int j = (int)fish[i].size() - 1, k = (int)fish[i - 1].size() - 1; j >= 0; --j)
            {
                while (k >= 0 && fish[i - 1][k].first > fish[i][j].first)
                {
                    mx = max(mx, dp1[i - 1][k]);
                    --k;
                }
                mx += fish[i][j].second;
                dp1[i][j] = max(dp1[i][j], mx);
                res = max(dp1[i][j], res);
            }
        }
    }
    return res;
}

ll max_weights(int n, int m, vector<int> X, vector<int> Y, vector<int> W)
{
    vector<tuple<int, int, ll>> xyw(m);
    for (int i = 0; i < m; ++i) xyw[i] = {X[i], Y[i], W[i]};
    sort(xyw.begin(), xyw.end());
    ll res = 0;
    vector<vector<pair<int, ll>>> tos;
    int prevX = -1;
    for (auto [x, y, w] : xyw)
    {
        if (x > prevX + 1)
        {
            tos.push_back(vector<pair<int, ll>>());
            res += solve(tos, n);
            tos.clear();
            tos.push_back(vector<pair<int, ll>>());
            prevX = x - 1;
        }
        if (x == prevX + 1)
        {
            tos.push_back(vector<pair<int, ll>>());
        }
        tos.back().emplace_back(y, w);
        prevX = x;
    }
    if (prevX != n - 1) tos.push_back(vector<pair<int, ll>>());
    res += solve(tos, n);
    return res;
}

Compilation message

fish.cpp: In function 'll solve(std::vector<std::vector<std::pair<int, long long int> > >&, int)':
fish.cpp:14:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |     for (int i = 0; i < fish.size(); ++i)
      |                     ~~^~~~~~~~~~~~~
fish.cpp:21:31: 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]
   21 |             for (int j = 0; j < fish[i - 1].size(); ++j)
      |                             ~~^~~~~~~~~~~~~~~~~~~~
fish.cpp:28:34: 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]
   28 |         for (int j = 0, k = 0; j < fish[i].size(); ++j)
      |                                ~~^~~~~~~~~~~~~~~~
fish.cpp:32:26: 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]
   32 |                 while (k < fish[i - 1].size() && fish[i - 1][k].first < fish[i][j].first)
      |                        ~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 5948 KB Output is correct
2 Correct 39 ms 7236 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 119 ms 15448 KB Output is correct
6 Correct 143 ms 12020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 61 ms 11620 KB Output is correct
3 Correct 76 ms 14376 KB Output is correct
4 Correct 29 ms 5956 KB Output is correct
5 Correct 36 ms 7340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 30 ms 5892 KB Output is correct
13 Correct 37 ms 7216 KB Output is correct
14 Correct 32 ms 5980 KB Output is correct
15 Correct 34 ms 6592 KB Output is correct
16 Correct 30 ms 5960 KB Output is correct
17 Correct 33 ms 6596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 32 ms 2520 KB Output is correct
4 Correct 22 ms 3512 KB Output is correct
5 Correct 77 ms 22140 KB Output is correct
6 Correct 56 ms 22120 KB Output is correct
7 Correct 60 ms 22144 KB Output is correct
8 Correct 59 ms 22128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 16 ms 2244 KB Output is correct
18 Correct 17 ms 2788 KB Output is correct
19 Correct 16 ms 3900 KB Output is correct
20 Correct 16 ms 3924 KB Output is correct
21 Correct 16 ms 3932 KB Output is correct
22 Correct 40 ms 7652 KB Output is correct
23 Correct 4 ms 980 KB Output is correct
24 Correct 12 ms 2500 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 4 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 16 ms 2244 KB Output is correct
18 Correct 17 ms 2788 KB Output is correct
19 Correct 16 ms 3900 KB Output is correct
20 Correct 16 ms 3924 KB Output is correct
21 Correct 16 ms 3932 KB Output is correct
22 Correct 40 ms 7652 KB Output is correct
23 Correct 4 ms 980 KB Output is correct
24 Correct 12 ms 2500 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 4 ms 980 KB Output is correct
27 Correct 2 ms 852 KB Output is correct
28 Correct 78 ms 12292 KB Output is correct
29 Correct 114 ms 12420 KB Output is correct
30 Correct 120 ms 22988 KB Output is correct
31 Correct 125 ms 23008 KB Output is correct
32 Correct 110 ms 23628 KB Output is correct
33 Correct 127 ms 23024 KB Output is correct
34 Correct 132 ms 22988 KB Output is correct
35 Correct 47 ms 9720 KB Output is correct
36 Correct 123 ms 24284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 32 ms 2520 KB Output is correct
4 Correct 22 ms 3512 KB Output is correct
5 Correct 77 ms 22140 KB Output is correct
6 Correct 56 ms 22120 KB Output is correct
7 Correct 60 ms 22144 KB Output is correct
8 Correct 59 ms 22128 KB Output is correct
9 Correct 58 ms 22108 KB Output is correct
10 Correct 57 ms 14744 KB Output is correct
11 Correct 117 ms 29288 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 55 ms 4152 KB Output is correct
23 Correct 111 ms 29172 KB Output is correct
24 Correct 120 ms 29176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 5948 KB Output is correct
2 Correct 39 ms 7236 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 119 ms 15448 KB Output is correct
6 Correct 143 ms 12020 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 61 ms 11620 KB Output is correct
9 Correct 76 ms 14376 KB Output is correct
10 Correct 29 ms 5956 KB Output is correct
11 Correct 36 ms 7340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 30 ms 5892 KB Output is correct
19 Correct 37 ms 7216 KB Output is correct
20 Correct 32 ms 5980 KB Output is correct
21 Correct 34 ms 6592 KB Output is correct
22 Correct 30 ms 5960 KB Output is correct
23 Correct 33 ms 6596 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 32 ms 2520 KB Output is correct
27 Correct 22 ms 3512 KB Output is correct
28 Correct 77 ms 22140 KB Output is correct
29 Correct 56 ms 22120 KB Output is correct
30 Correct 60 ms 22144 KB Output is correct
31 Correct 59 ms 22128 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 340 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 2 ms 340 KB Output is correct
44 Correct 1 ms 212 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 16 ms 2244 KB Output is correct
49 Correct 17 ms 2788 KB Output is correct
50 Correct 16 ms 3900 KB Output is correct
51 Correct 16 ms 3924 KB Output is correct
52 Correct 16 ms 3932 KB Output is correct
53 Correct 40 ms 7652 KB Output is correct
54 Correct 4 ms 980 KB Output is correct
55 Correct 12 ms 2500 KB Output is correct
56 Correct 1 ms 340 KB Output is correct
57 Correct 4 ms 980 KB Output is correct
58 Correct 2 ms 852 KB Output is correct
59 Correct 78 ms 12292 KB Output is correct
60 Correct 114 ms 12420 KB Output is correct
61 Correct 120 ms 22988 KB Output is correct
62 Correct 125 ms 23008 KB Output is correct
63 Correct 110 ms 23628 KB Output is correct
64 Correct 127 ms 23024 KB Output is correct
65 Correct 132 ms 22988 KB Output is correct
66 Correct 47 ms 9720 KB Output is correct
67 Correct 123 ms 24284 KB Output is correct
68 Correct 58 ms 22108 KB Output is correct
69 Correct 57 ms 14744 KB Output is correct
70 Correct 117 ms 29288 KB Output is correct
71 Correct 0 ms 212 KB Output is correct
72 Correct 0 ms 212 KB Output is correct
73 Correct 0 ms 212 KB Output is correct
74 Correct 0 ms 212 KB Output is correct
75 Correct 0 ms 212 KB Output is correct
76 Correct 0 ms 212 KB Output is correct
77 Correct 0 ms 212 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 0 ms 212 KB Output is correct
80 Correct 0 ms 212 KB Output is correct
81 Correct 55 ms 4152 KB Output is correct
82 Correct 111 ms 29172 KB Output is correct
83 Correct 120 ms 29176 KB Output is correct
84 Correct 125 ms 14948 KB Output is correct
85 Correct 132 ms 15168 KB Output is correct
86 Correct 148 ms 11964 KB Output is correct
87 Correct 171 ms 11984 KB Output is correct
88 Correct 0 ms 212 KB Output is correct
89 Correct 146 ms 12144 KB Output is correct
90 Correct 131 ms 11988 KB Output is correct
91 Correct 133 ms 27020 KB Output is correct