답안 #1074412

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1074412 2024-08-25T10:22:37 Z zsombor 메기 농장 (IOI22_fish) C++17
67 / 100
1000 ms 37208 KB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll n, m, ans;
vector<vector<pair<int, ll> > > f(2e5);
vector<vector<ll> > dp1(2e5);
vector<vector<ll> > dp2(2e5);

ll solve2() {
    f[1].push_back({n + 1, 0});
    f[2].push_back({n + 1, 0});
    sort(f[1].begin(), f[1].end());
    sort(f[2].begin(), f[2].end());
    ll sum1 = 0, sum2 = 0, h, nxt = 0;
    for (auto p: f[1]) sum1 += p.second;
    for (auto p: f[2]) sum2 += p.second;
    if (n == 2) return max(sum1, sum2);
    ans = sum2;
    for (auto p: f[2]) {
        h = p.first - 1;
        while (h >= f[1][nxt].first) sum2 += f[1][nxt++].second;
        ans = max(ans, sum2);
        sum2 -= p.second;
    }
    return ans;
}

void get_dp1(int i, int j) {
    ll h0, h = f[i][j].first - 1, val = 0;
    for (auto p: f[i]) if (p.first <= h) val -= p.second;
    for (auto p: f[i + 1]) if (p.first <= h) val += p.second;
    for (int k = 0; k < f[i - 1].size(); k++) {
        h0 = f[i - 1][k].first - 1;
        if (h0 < h) continue;
        dp1[i][j] = max(dp1[i][j], dp1[i - 1][k] + val);
        dp1[i][j] = max(dp1[i][j], dp2[i - 1][k] + val);
    }
    ans = max(ans, dp1[i][j]);
}

void get_dp2(int i, int j) {
    ll h0, h = f[i][j].first - 1, val = 0, nxt = 0;
    for (auto p: f[i - 1]) if (p.first <= h) val += p.second;
    for (auto p: f[i + 1]) if (p.first <= h) val += p.second;
    for (int k = 0; k < f[i - 1].size(); k++) {
        h0 = f[i - 1][k].first - 1;
        if (h0 >= h) break;
        if (k) val -= f[i - 1][k - 1].second;
        while (h0 >= f[i][nxt].first) val -= f[i][nxt++].second;
        dp2[i][j] = max(dp2[i][j], dp2[i - 1][k] + val);
    }
    if (i == 1) {
        ans = max(ans, dp2[i][j]);
        return;
    }
    val = nxt = 0;
    for (auto p: f[i - 1]) if (p.first <= h) val += p.second;
    for (auto p: f[i + 1]) if (p.first <= h) val += p.second;
    for (int k = 0; k < f[i - 2].size(); k++) {
        h0 = f[i - 2][k].first - 1;
        while (h0 >= f[i - 1][nxt].first && h0 >= f[i - 1][nxt].first) val -= f[i - 1][nxt++].second;
        dp2[i][j] = max(dp2[i][j], dp1[i - 2][k] + val);
        dp2[i][j] = max(dp2[i][j], dp2[i - 2][k] + val);
    }
    ans = max(ans, dp2[i][j]);
}

ll solve() {
    f[0].push_back({1, 0});
    for (int i = 0; i <= n + 1; i++) {
        f[i].push_back({n + 1, 0});
        sort(f[i].begin(), f[i].end());
    }
    dp1[0] = dp2[0] = {0ll, ll(-1e18)};
    for (int i = 1; i <= n; i++) {
        dp1[i].resize(f[i].size(), 0);
        dp2[i].resize(f[i].size(), 0);
        for (int j = 0; j < f[i].size(); j++) {
            get_dp1(i, j);
            get_dp2(i, j);
        }
    }
    return ans;
}

ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
    n = N;
    m = M;
    ll sum = 0;
    for (int i = 0; i < m; i++) {
        X[i]++;
        Y[i]++;
        f[X[i]].push_back({Y[i], W[i]});
        sum += W[i];
    }
    bool st1 = true, st2 = true;
    for (int i = 0; i < m; i++) {
        if (X[i] % 2 == 0) st1 = false;
        if (X[i] > 2) st2 = false;
    }
    if (st1) return sum;
    if (st2) return solve2();
    return solve();
}

Compilation message

fish.cpp: In function 'void get_dp1(int, int)':
fish.cpp:34: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]
   34 |     for (int k = 0; k < f[i - 1].size(); k++) {
      |                     ~~^~~~~~~~~~~~~~~~~
fish.cpp: In function 'void get_dp2(int, int)':
fish.cpp:47: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]
   47 |     for (int k = 0; k < f[i - 1].size(); k++) {
      |                     ~~^~~~~~~~~~~~~~~~~
fish.cpp:61: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]
   61 |     for (int k = 0; k < f[i - 2].size(); k++) {
      |                     ~~^~~~~~~~~~~~~~~~~
fish.cpp: In function 'll solve()':
fish.cpp:80: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]
   80 |         for (int j = 0; j < f[i].size(); j++) {
      |                         ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 19916 KB Output is correct
2 Correct 26 ms 20676 KB Output is correct
3 Correct 6 ms 14428 KB Output is correct
4 Correct 7 ms 14428 KB Output is correct
5 Correct 69 ms 33104 KB Output is correct
6 Correct 85 ms 35828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 14428 KB Output is correct
2 Correct 59 ms 23648 KB Output is correct
3 Correct 59 ms 25936 KB Output is correct
4 Correct 21 ms 19912 KB Output is correct
5 Correct 34 ms 20680 KB Output is correct
6 Correct 6 ms 14428 KB Output is correct
7 Correct 6 ms 14424 KB Output is correct
8 Correct 5 ms 14424 KB Output is correct
9 Correct 6 ms 14424 KB Output is correct
10 Correct 6 ms 14424 KB Output is correct
11 Correct 5 ms 14428 KB Output is correct
12 Correct 29 ms 19920 KB Output is correct
13 Correct 32 ms 20632 KB Output is correct
14 Correct 27 ms 19440 KB Output is correct
15 Correct 32 ms 19784 KB Output is correct
16 Correct 33 ms 19552 KB Output is correct
17 Correct 29 ms 19916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 14484 KB Output is correct
2 Correct 20 ms 23728 KB Output is correct
3 Correct 34 ms 25924 KB Output is correct
4 Correct 36 ms 25828 KB Output is correct
5 Correct 63 ms 29780 KB Output is correct
6 Correct 53 ms 29084 KB Output is correct
7 Correct 74 ms 29752 KB Output is correct
8 Correct 72 ms 29876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 14472 KB Output is correct
2 Correct 5 ms 14428 KB Output is correct
3 Correct 6 ms 14428 KB Output is correct
4 Correct 4 ms 14428 KB Output is correct
5 Correct 9 ms 14412 KB Output is correct
6 Correct 5 ms 14424 KB Output is correct
7 Correct 5 ms 14428 KB Output is correct
8 Correct 5 ms 14424 KB Output is correct
9 Correct 6 ms 14428 KB Output is correct
10 Correct 6 ms 14684 KB Output is correct
11 Correct 5 ms 14428 KB Output is correct
12 Correct 5 ms 14428 KB Output is correct
13 Correct 6 ms 14428 KB Output is correct
14 Correct 5 ms 14428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 14472 KB Output is correct
2 Correct 5 ms 14428 KB Output is correct
3 Correct 6 ms 14428 KB Output is correct
4 Correct 4 ms 14428 KB Output is correct
5 Correct 9 ms 14412 KB Output is correct
6 Correct 5 ms 14424 KB Output is correct
7 Correct 5 ms 14428 KB Output is correct
8 Correct 5 ms 14424 KB Output is correct
9 Correct 6 ms 14428 KB Output is correct
10 Correct 6 ms 14684 KB Output is correct
11 Correct 5 ms 14428 KB Output is correct
12 Correct 5 ms 14428 KB Output is correct
13 Correct 6 ms 14428 KB Output is correct
14 Correct 5 ms 14428 KB Output is correct
15 Correct 5 ms 14428 KB Output is correct
16 Correct 7 ms 14640 KB Output is correct
17 Correct 100 ms 17884 KB Output is correct
18 Correct 108 ms 18392 KB Output is correct
19 Correct 98 ms 18256 KB Output is correct
20 Correct 80 ms 18096 KB Output is correct
21 Correct 109 ms 18256 KB Output is correct
22 Correct 261 ms 22096 KB Output is correct
23 Correct 15 ms 15064 KB Output is correct
24 Correct 38 ms 16784 KB Output is correct
25 Correct 5 ms 14428 KB Output is correct
26 Correct 9 ms 15060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 14472 KB Output is correct
2 Correct 5 ms 14428 KB Output is correct
3 Correct 6 ms 14428 KB Output is correct
4 Correct 4 ms 14428 KB Output is correct
5 Correct 9 ms 14412 KB Output is correct
6 Correct 5 ms 14424 KB Output is correct
7 Correct 5 ms 14428 KB Output is correct
8 Correct 5 ms 14424 KB Output is correct
9 Correct 6 ms 14428 KB Output is correct
10 Correct 6 ms 14684 KB Output is correct
11 Correct 5 ms 14428 KB Output is correct
12 Correct 5 ms 14428 KB Output is correct
13 Correct 6 ms 14428 KB Output is correct
14 Correct 5 ms 14428 KB Output is correct
15 Correct 5 ms 14428 KB Output is correct
16 Correct 7 ms 14640 KB Output is correct
17 Correct 100 ms 17884 KB Output is correct
18 Correct 108 ms 18392 KB Output is correct
19 Correct 98 ms 18256 KB Output is correct
20 Correct 80 ms 18096 KB Output is correct
21 Correct 109 ms 18256 KB Output is correct
22 Correct 261 ms 22096 KB Output is correct
23 Correct 15 ms 15064 KB Output is correct
24 Correct 38 ms 16784 KB Output is correct
25 Correct 5 ms 14428 KB Output is correct
26 Correct 9 ms 15060 KB Output is correct
27 Correct 6 ms 14940 KB Output is correct
28 Execution timed out 1065 ms 31116 KB Time limit exceeded
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 14484 KB Output is correct
2 Correct 20 ms 23728 KB Output is correct
3 Correct 34 ms 25924 KB Output is correct
4 Correct 36 ms 25828 KB Output is correct
5 Correct 63 ms 29780 KB Output is correct
6 Correct 53 ms 29084 KB Output is correct
7 Correct 74 ms 29752 KB Output is correct
8 Correct 72 ms 29876 KB Output is correct
9 Correct 47 ms 29524 KB Output is correct
10 Correct 61 ms 25800 KB Output is correct
11 Correct 82 ms 36952 KB Output is correct
12 Correct 5 ms 14440 KB Output is correct
13 Correct 6 ms 14440 KB Output is correct
14 Correct 5 ms 14440 KB Output is correct
15 Correct 5 ms 14432 KB Output is correct
16 Correct 4 ms 14440 KB Output is correct
17 Correct 6 ms 14432 KB Output is correct
18 Correct 6 ms 14436 KB Output is correct
19 Correct 5 ms 14440 KB Output is correct
20 Correct 17 ms 23920 KB Output is correct
21 Correct 19 ms 23904 KB Output is correct
22 Correct 63 ms 30296 KB Output is correct
23 Correct 85 ms 36956 KB Output is correct
24 Correct 90 ms 37208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 19916 KB Output is correct
2 Correct 26 ms 20676 KB Output is correct
3 Correct 6 ms 14428 KB Output is correct
4 Correct 7 ms 14428 KB Output is correct
5 Correct 69 ms 33104 KB Output is correct
6 Correct 85 ms 35828 KB Output is correct
7 Correct 5 ms 14428 KB Output is correct
8 Correct 59 ms 23648 KB Output is correct
9 Correct 59 ms 25936 KB Output is correct
10 Correct 21 ms 19912 KB Output is correct
11 Correct 34 ms 20680 KB Output is correct
12 Correct 6 ms 14428 KB Output is correct
13 Correct 6 ms 14424 KB Output is correct
14 Correct 5 ms 14424 KB Output is correct
15 Correct 6 ms 14424 KB Output is correct
16 Correct 6 ms 14424 KB Output is correct
17 Correct 5 ms 14428 KB Output is correct
18 Correct 29 ms 19920 KB Output is correct
19 Correct 32 ms 20632 KB Output is correct
20 Correct 27 ms 19440 KB Output is correct
21 Correct 32 ms 19784 KB Output is correct
22 Correct 33 ms 19552 KB Output is correct
23 Correct 29 ms 19916 KB Output is correct
24 Correct 4 ms 14484 KB Output is correct
25 Correct 20 ms 23728 KB Output is correct
26 Correct 34 ms 25924 KB Output is correct
27 Correct 36 ms 25828 KB Output is correct
28 Correct 63 ms 29780 KB Output is correct
29 Correct 53 ms 29084 KB Output is correct
30 Correct 74 ms 29752 KB Output is correct
31 Correct 72 ms 29876 KB Output is correct
32 Correct 6 ms 14472 KB Output is correct
33 Correct 5 ms 14428 KB Output is correct
34 Correct 6 ms 14428 KB Output is correct
35 Correct 4 ms 14428 KB Output is correct
36 Correct 9 ms 14412 KB Output is correct
37 Correct 5 ms 14424 KB Output is correct
38 Correct 5 ms 14428 KB Output is correct
39 Correct 5 ms 14424 KB Output is correct
40 Correct 6 ms 14428 KB Output is correct
41 Correct 6 ms 14684 KB Output is correct
42 Correct 5 ms 14428 KB Output is correct
43 Correct 5 ms 14428 KB Output is correct
44 Correct 6 ms 14428 KB Output is correct
45 Correct 5 ms 14428 KB Output is correct
46 Correct 5 ms 14428 KB Output is correct
47 Correct 7 ms 14640 KB Output is correct
48 Correct 100 ms 17884 KB Output is correct
49 Correct 108 ms 18392 KB Output is correct
50 Correct 98 ms 18256 KB Output is correct
51 Correct 80 ms 18096 KB Output is correct
52 Correct 109 ms 18256 KB Output is correct
53 Correct 261 ms 22096 KB Output is correct
54 Correct 15 ms 15064 KB Output is correct
55 Correct 38 ms 16784 KB Output is correct
56 Correct 5 ms 14428 KB Output is correct
57 Correct 9 ms 15060 KB Output is correct
58 Correct 6 ms 14940 KB Output is correct
59 Execution timed out 1065 ms 31116 KB Time limit exceeded
60 Halted 0 ms 0 KB -