Submission #1056027

# Submission time Handle Problem Language Result Execution time Memory
1056027 2024-08-13T07:16:07 Z Forested Catfish Farm (IOI22_fish) C++17
100 / 100
85 ms 36180 KB
#include <bits/stdc++.h>
using namespace std;

using i32 = int;
using i64 = long long;
template <typename T>
using V = vector<T>;
template <typename T>
using VV = V<V<T>>;
template <typename T>
using VVV = V<V<V<T>>>;

template <typename T>
bool chmin(T &x, const T &y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}
template <typename T>
bool chmax(T &x, const T &y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}

#define OVERRIDE4(a, b, c, d, ...) d
#define REP2(i, n) for (i32 i = 0; i < (i32)(n); ++i)
#define REP3(i, l, r) for (i32 i = (i32)(l); i < (i32)(r); ++i)
#define REP(...) OVERRIDE4(__VA_ARGS__, REP3, REP2)(__VA_ARGS__)
#define PER2(i, n) for (i32 i = (i32)(n)-1; i >= 0; --i)
#define PER3(i, l, r) for (i32 i = (i32)(r)-1; i >= (i32)(l); --i)
#define PER(...) OVERRIDE4(__VA_ARGS__, PER3, PER2)(__VA_ARGS__)
#define ALL(x) begin(x), end(x)
#define LEN(x) (i32) size(x)

void dbg(i32 x) { cerr << x; }
void dbg(i64 x) { cerr << x; }
template <typename T, typename U>
void dbg(pair<T, U> p) {
    cerr << '(' << p.first << ", " << p.second << ')';
}
template <typename T>
void dbg(V<T> arr) {
    cerr << '[';
    REP(i, LEN(arr)) {
        if (i) {
            cerr << ", ";
        }
        dbg(arr[i]);
    }
    cerr << ']';
}
void debug() { cerr << '\n'; }
template <typename Head, typename... Tail>
void debug(Head head, Tail... tail) {
    dbg(head);
    cerr << ", ";
    debug(tail...);
}
#ifdef DEBUGF
#define DBG(...)                       \
    do {                               \
        cerr << #__VA_ARGS__ << " : "; \
        debug(__VA_ARGS__);            \
    } while (false)
#else
#define DBG(...) (void)0
#endif

#include "fish.h"

constexpr i64 INF = 3003003003003003003;

long long max_weights(i32 n, i32 m, V<i32> x, V<i32> y, V<i32> w) {
    VV<pair<i32, i64>> wts(n);
    REP(i, m) {
        wts[x[i]].emplace_back(y[i], w[i]);
    }
    REP(i, n) {
        sort(ALL(wts[i]));
    }
    V<i64> mxr(n + 1, 0);
    VV<i64> up(n), down(n);
    REP(i, n) {
        up[i].resize(LEN(wts[i]), -INF);
        down[i].resize(LEN(wts[i]), -INF);
    }
    REP(i, LEN(wts[0])) {
        up[0][i] = wts[0][i].second;
    }
    REP(i, n) {
        if (i > 0) {
            REP(j, LEN(wts[i])) {
                chmax(up[i][j], mxr[i - 1] + wts[i][j].second);
                chmax(down[i][j], mxr[i - 1] + wts[i][j].second);
                {
                    auto itr = lower_bound(ALL(wts[i - 1]), pair<i32, i64>(wts[i][j].first, 0LL));
                    if (itr != begin(wts[i - 1])) {
                        i32 idx = itr - begin(wts[i - 1]) - 1;
                        chmax(up[i][j], up[i - 1][idx] + wts[i][j].second);
                    }
                }
                {
                    auto itr = lower_bound(ALL(wts[i - 1]), pair<i32, i64>(wts[i][j].first + 1, 0LL));
                    if (itr != end(wts[i - 1])) {
                        i32 idx = itr - begin(wts[i - 1]);
                        chmax(down[i][j], down[i - 1][idx] + wts[i][j].second);
                    }
                }
            }
            i64 pmax = -INF;
            REP(j, LEN(wts[i - 1])) {
                chmax(pmax, down[i - 1][j]);                
            }
            REP(j, LEN(wts[i])) {
                chmax(up[i][j], pmax + wts[i][j].second);
            }
        }
        PER(j, LEN(wts[i]) - 1) {
            chmax(down[i][j], down[i][j + 1] + wts[i][j].second);
        }
        REP(j, 1, LEN(wts[i])) {
            chmax(up[i][j], up[i][j - 1] + wts[i][j].second);
        }
        chmax(mxr[i + 1], mxr[i]);
        REP(j, LEN(wts[i])) {
            chmax(mxr[i + 1], up[i][j]);
            chmax(mxr[i + 1], down[i][j]);
        }
    }
    i64 ans = mxr[n - 1];
    REP(i, LEN(wts[n - 1])) {
        chmax(ans, down[n - 1][i]);
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 23 ms 11724 KB Output is correct
2 Correct 24 ms 13516 KB Output is correct
3 Correct 3 ms 8028 KB Output is correct
4 Correct 3 ms 8024 KB Output is correct
5 Correct 68 ms 24512 KB Output is correct
6 Correct 77 ms 28240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 48 ms 18540 KB Output is correct
3 Correct 53 ms 22588 KB Output is correct
4 Correct 20 ms 13256 KB Output is correct
5 Correct 27 ms 15304 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 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 3 ms 8028 KB Output is correct
11 Correct 3 ms 8028 KB Output is correct
12 Correct 20 ms 13260 KB Output is correct
13 Correct 24 ms 15428 KB Output is correct
14 Correct 21 ms 13284 KB Output is correct
15 Correct 26 ms 14772 KB Output is correct
16 Correct 23 ms 13256 KB Output is correct
17 Correct 25 ms 14528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8024 KB Output is correct
2 Correct 3 ms 8028 KB Output is correct
3 Correct 19 ms 13624 KB Output is correct
4 Correct 16 ms 12892 KB Output is correct
5 Correct 38 ms 21340 KB Output is correct
6 Correct 31 ms 20816 KB Output is correct
7 Correct 33 ms 21332 KB Output is correct
8 Correct 34 ms 21332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 436 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 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 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
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 436 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 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 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 1 ms 604 KB Output is correct
17 Correct 11 ms 3788 KB Output is correct
18 Correct 11 ms 4188 KB Output is correct
19 Correct 10 ms 4180 KB Output is correct
20 Correct 10 ms 4184 KB Output is correct
21 Correct 12 ms 4188 KB Output is correct
22 Correct 21 ms 8020 KB Output is correct
23 Correct 2 ms 1116 KB Output is correct
24 Correct 7 ms 2652 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 2 ms 904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 436 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 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 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 1 ms 604 KB Output is correct
17 Correct 11 ms 3788 KB Output is correct
18 Correct 11 ms 4188 KB Output is correct
19 Correct 10 ms 4180 KB Output is correct
20 Correct 10 ms 4184 KB Output is correct
21 Correct 12 ms 4188 KB Output is correct
22 Correct 21 ms 8020 KB Output is correct
23 Correct 2 ms 1116 KB Output is correct
24 Correct 7 ms 2652 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 2 ms 904 KB Output is correct
27 Correct 1 ms 860 KB Output is correct
28 Correct 56 ms 17916 KB Output is correct
29 Correct 79 ms 24916 KB Output is correct
30 Correct 70 ms 24300 KB Output is correct
31 Correct 75 ms 24300 KB Output is correct
32 Correct 67 ms 25428 KB Output is correct
33 Correct 67 ms 24144 KB Output is correct
34 Correct 66 ms 24280 KB Output is correct
35 Correct 27 ms 10076 KB Output is correct
36 Correct 80 ms 25432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8024 KB Output is correct
2 Correct 3 ms 8028 KB Output is correct
3 Correct 19 ms 13624 KB Output is correct
4 Correct 16 ms 12892 KB Output is correct
5 Correct 38 ms 21340 KB Output is correct
6 Correct 31 ms 20816 KB Output is correct
7 Correct 33 ms 21332 KB Output is correct
8 Correct 34 ms 21332 KB Output is correct
9 Correct 32 ms 21336 KB Output is correct
10 Correct 35 ms 13660 KB Output is correct
11 Correct 61 ms 27472 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 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 4 ms 8028 KB Output is correct
19 Correct 4 ms 8028 KB Output is correct
20 Correct 4 ms 8024 KB Output is correct
21 Correct 3 ms 8028 KB Output is correct
22 Correct 32 ms 19344 KB Output is correct
23 Correct 56 ms 27480 KB Output is correct
24 Correct 66 ms 27980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 11724 KB Output is correct
2 Correct 24 ms 13516 KB Output is correct
3 Correct 3 ms 8028 KB Output is correct
4 Correct 3 ms 8024 KB Output is correct
5 Correct 68 ms 24512 KB Output is correct
6 Correct 77 ms 28240 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 48 ms 18540 KB Output is correct
9 Correct 53 ms 22588 KB Output is correct
10 Correct 20 ms 13256 KB Output is correct
11 Correct 27 ms 15304 KB Output is correct
12 Correct 1 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 3 ms 8028 KB Output is correct
17 Correct 3 ms 8028 KB Output is correct
18 Correct 20 ms 13260 KB Output is correct
19 Correct 24 ms 15428 KB Output is correct
20 Correct 21 ms 13284 KB Output is correct
21 Correct 26 ms 14772 KB Output is correct
22 Correct 23 ms 13256 KB Output is correct
23 Correct 25 ms 14528 KB Output is correct
24 Correct 3 ms 8024 KB Output is correct
25 Correct 3 ms 8028 KB Output is correct
26 Correct 19 ms 13624 KB Output is correct
27 Correct 16 ms 12892 KB Output is correct
28 Correct 38 ms 21340 KB Output is correct
29 Correct 31 ms 20816 KB Output is correct
30 Correct 33 ms 21332 KB Output is correct
31 Correct 34 ms 21332 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 436 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 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 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 344 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 11 ms 3788 KB Output is correct
49 Correct 11 ms 4188 KB Output is correct
50 Correct 10 ms 4180 KB Output is correct
51 Correct 10 ms 4184 KB Output is correct
52 Correct 12 ms 4188 KB Output is correct
53 Correct 21 ms 8020 KB Output is correct
54 Correct 2 ms 1116 KB Output is correct
55 Correct 7 ms 2652 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 2 ms 904 KB Output is correct
58 Correct 1 ms 860 KB Output is correct
59 Correct 56 ms 17916 KB Output is correct
60 Correct 79 ms 24916 KB Output is correct
61 Correct 70 ms 24300 KB Output is correct
62 Correct 75 ms 24300 KB Output is correct
63 Correct 67 ms 25428 KB Output is correct
64 Correct 67 ms 24144 KB Output is correct
65 Correct 66 ms 24280 KB Output is correct
66 Correct 27 ms 10076 KB Output is correct
67 Correct 80 ms 25432 KB Output is correct
68 Correct 32 ms 21336 KB Output is correct
69 Correct 35 ms 13660 KB Output is correct
70 Correct 61 ms 27472 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 0 ms 348 KB Output is correct
73 Correct 0 ms 348 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 4 ms 8028 KB Output is correct
78 Correct 4 ms 8028 KB Output is correct
79 Correct 4 ms 8024 KB Output is correct
80 Correct 3 ms 8028 KB Output is correct
81 Correct 32 ms 19344 KB Output is correct
82 Correct 56 ms 27480 KB Output is correct
83 Correct 66 ms 27980 KB Output is correct
84 Correct 82 ms 30112 KB Output is correct
85 Correct 79 ms 30428 KB Output is correct
86 Correct 82 ms 34936 KB Output is correct
87 Correct 84 ms 36180 KB Output is correct
88 Correct 0 ms 348 KB Output is correct
89 Correct 85 ms 36112 KB Output is correct
90 Correct 76 ms 33360 KB Output is correct
91 Correct 74 ms 32592 KB Output is correct