Submission #995455

# Submission time Handle Problem Language Result Execution time Memory
995455 2024-06-09T06:14:11 Z Forested Highway Tolls (IOI18_highway) C++17
100 / 100
142 ms 11720 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>>;
#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 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 REP(...) OVERRIDE4(__VA_ARGS__, REP3, REP2)(__VA_ARGS__)
#define PER(...) OVERRIDE4(__VA_ARGS__, PER3, PER2)(__VA_ARGS__)
#define LEN(x) (i32)size(x)
#define ALL(x) begin(x), end(x)
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;
}

#include "highway.h"

void find_pair(i32 n, V<i32> u, V<i32> v, i32 _a, i32 _b) {
    i64 a = _a, b = _b;
    i32 m = LEN(u);
    i64 d = ask(V<i32>(m, 0));
    i32 path = d / a;
    i32 ok = 0, ng = m;
    while (ng - ok > 1) {
        i32 mid = (ok + ng) / 2;
        V<i32> w(m, 0);
        fill(w.begin(), w.begin() + mid, 1);
        if (ask(w) == d) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    i32 ed = ok;
    VV<pair<i32, i32>> g(n);
    REP(i, ed + 1, m) {
        g[u[i]].emplace_back(v[i], i);
        g[v[i]].emplace_back(u[i], i);
    }
    i32 r0 = u[ed], r1 = v[ed];
    V<i32> dist(n, -1), from(n, -1);
    queue<i32> que;
    que.push(r0);
    que.push(r1);
    dist[r0] = 0;
    dist[r1] = 0;
    from[r0] = r0;
    from[r1] = r1;
    while (!que.empty()) {
        i32 v = que.front();
        que.pop();
        for (auto [u, e] : g[v]) {
            if (dist[u] == -1) {
                dist[u] = dist[v] + 1;
                from[u] = from[v];
                que.push(u);
            }
        }
    }
    V<pair<i32, i32>> ss, ts;
    REP(i, n) {
        if (from[i] != r0) {
            continue;
        }
        for (auto [j, e] : g[i]) {
            if (from[j] == r0 && dist[j] == dist[i] - 1) {
                ss.emplace_back(dist[i], e);
            }
        }
    }
    REP(i, n) {
        if (from[i] != r1) {
            continue;
        }
        for (auto [j, e] : g[i]) {
            if (from[j] == r1 && dist[j] == dist[i] - 1) {
                ts.emplace_back(dist[i], e);
            }
        }
    }
    sort(ALL(ss), greater());
    sort(ALL(ts), greater());
    i32 s = -1, t = -1;
    ok = 0;
    ng = LEN(ss) + 1;
    while (ng - ok > 1) {
        i32 mid = (ok + ng) / 2;
        V<i32> w(m, 0);
        fill(w.begin(), w.begin() + ed, 1);
        REP(i, mid) {
            w[ss[i].second] = 1;
        }
        if (ask(w) == d) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    if (ok == LEN(ss)) {
        s = r0;
    } else {
        i32 e = ss[ok].second;
        if (dist[u[e]] > dist[v[e]]) {
            s = u[e];
        } else {
            s = v[e];
        }
    }
    ok = 0;
    ng = LEN(ts) + 1;
    while (ng - ok > 1) {
        i32 mid = (ok + ng) / 2;
        V<i32> w(m, 0);
        fill(w.begin(), w.begin() + ed, 1);
        REP(i, mid) {
            w[ts[i].second] = 1;
        }
        if (ask(w) == d) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    if (ok == LEN(ts)) {
        t = r1;
    } else {
        i32 e = ts[ok].second;
        if (dist[u[e]] > dist[v[e]]) {
            t = u[e];
        } else {
            t = v[e];
        }
    }
    answer(s, t);
}

Compilation message

highway.cpp: In function 'void find_pair(i32, V<int>, V<int>, i32, i32)':
highway.cpp:38:17: warning: unused variable 'b' [-Wunused-variable]
   38 |     i64 a = _a, b = _b;
      |                 ^
highway.cpp:41:9: warning: unused variable 'path' [-Wunused-variable]
   41 |     i32 path = d / a;
      |         ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 424 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 8 ms 1400 KB Output is correct
3 Correct 86 ms 9352 KB Output is correct
4 Correct 77 ms 9492 KB Output is correct
5 Correct 99 ms 9504 KB Output is correct
6 Correct 75 ms 8704 KB Output is correct
7 Correct 75 ms 8648 KB Output is correct
8 Correct 79 ms 9472 KB Output is correct
9 Correct 75 ms 8692 KB Output is correct
10 Correct 80 ms 8964 KB Output is correct
11 Correct 71 ms 8052 KB Output is correct
12 Correct 89 ms 8824 KB Output is correct
13 Correct 89 ms 9040 KB Output is correct
14 Correct 88 ms 8932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1368 KB Output is correct
2 Correct 13 ms 2136 KB Output is correct
3 Correct 19 ms 2080 KB Output is correct
4 Correct 72 ms 7588 KB Output is correct
5 Correct 59 ms 7384 KB Output is correct
6 Correct 62 ms 8388 KB Output is correct
7 Correct 59 ms 5584 KB Output is correct
8 Correct 61 ms 7588 KB Output is correct
9 Correct 58 ms 6176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 9 ms 1280 KB Output is correct
3 Correct 62 ms 7312 KB Output is correct
4 Correct 82 ms 9456 KB Output is correct
5 Correct 60 ms 7900 KB Output is correct
6 Correct 65 ms 8136 KB Output is correct
7 Correct 83 ms 8648 KB Output is correct
8 Correct 65 ms 8164 KB Output is correct
9 Correct 96 ms 9700 KB Output is correct
10 Correct 92 ms 8932 KB Output is correct
11 Correct 85 ms 8992 KB Output is correct
12 Correct 83 ms 8596 KB Output is correct
13 Correct 81 ms 8520 KB Output is correct
14 Correct 68 ms 8116 KB Output is correct
15 Correct 67 ms 8156 KB Output is correct
16 Correct 61 ms 7024 KB Output is correct
17 Correct 87 ms 8932 KB Output is correct
18 Correct 86 ms 8932 KB Output is correct
19 Correct 62 ms 7852 KB Output is correct
20 Correct 81 ms 7688 KB Output is correct
21 Correct 68 ms 7812 KB Output is correct
22 Correct 57 ms 6404 KB Output is correct
23 Correct 81 ms 9456 KB Output is correct
24 Correct 97 ms 9440 KB Output is correct
25 Correct 78 ms 9188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1368 KB Output is correct
2 Correct 10 ms 1440 KB Output is correct
3 Correct 100 ms 9760 KB Output is correct
4 Correct 108 ms 9580 KB Output is correct
5 Correct 114 ms 9856 KB Output is correct
6 Correct 134 ms 11328 KB Output is correct
7 Correct 124 ms 10236 KB Output is correct
8 Correct 124 ms 10092 KB Output is correct
9 Correct 78 ms 4032 KB Output is correct
10 Correct 97 ms 5568 KB Output is correct
11 Correct 93 ms 6644 KB Output is correct
12 Correct 124 ms 10068 KB Output is correct
13 Correct 120 ms 10348 KB Output is correct
14 Correct 124 ms 11016 KB Output is correct
15 Correct 120 ms 11004 KB Output is correct
16 Correct 112 ms 8204 KB Output is correct
17 Correct 74 ms 9284 KB Output is correct
18 Correct 65 ms 7840 KB Output is correct
19 Correct 69 ms 9692 KB Output is correct
20 Correct 80 ms 8796 KB Output is correct
21 Correct 129 ms 11284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 1520 KB Output is correct
2 Correct 10 ms 1368 KB Output is correct
3 Correct 100 ms 9648 KB Output is correct
4 Correct 114 ms 9564 KB Output is correct
5 Correct 112 ms 9828 KB Output is correct
6 Correct 125 ms 10936 KB Output is correct
7 Correct 100 ms 9756 KB Output is correct
8 Correct 100 ms 10172 KB Output is correct
9 Correct 114 ms 9744 KB Output is correct
10 Correct 122 ms 10448 KB Output is correct
11 Correct 130 ms 10892 KB Output is correct
12 Correct 122 ms 10496 KB Output is correct
13 Correct 78 ms 4352 KB Output is correct
14 Correct 82 ms 3828 KB Output is correct
15 Correct 101 ms 8104 KB Output is correct
16 Correct 93 ms 5552 KB Output is correct
17 Correct 99 ms 6544 KB Output is correct
18 Correct 94 ms 6520 KB Output is correct
19 Correct 120 ms 9900 KB Output is correct
20 Correct 124 ms 10888 KB Output is correct
21 Correct 128 ms 10728 KB Output is correct
22 Correct 137 ms 10796 KB Output is correct
23 Correct 135 ms 10892 KB Output is correct
24 Correct 130 ms 10916 KB Output is correct
25 Correct 120 ms 10572 KB Output is correct
26 Correct 131 ms 11720 KB Output is correct
27 Correct 85 ms 8436 KB Output is correct
28 Correct 75 ms 9200 KB Output is correct
29 Correct 80 ms 10200 KB Output is correct
30 Correct 77 ms 9944 KB Output is correct
31 Correct 76 ms 9696 KB Output is correct
32 Correct 79 ms 9904 KB Output is correct
33 Correct 79 ms 10164 KB Output is correct
34 Correct 77 ms 8720 KB Output is correct
35 Correct 76 ms 8948 KB Output is correct
36 Correct 79 ms 9628 KB Output is correct
37 Correct 79 ms 9376 KB Output is correct
38 Correct 82 ms 9672 KB Output is correct
39 Correct 128 ms 11328 KB Output is correct
40 Correct 127 ms 11164 KB Output is correct
41 Correct 142 ms 11160 KB Output is correct
42 Correct 134 ms 11156 KB Output is correct