Submission #1057605

# Submission time Handle Problem Language Result Execution time Memory
1057605 2024-08-14T00:00:04 Z efishel Highway Tolls (IOI18_highway) C++17
90 / 100
140 ms 26516 KB
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector <ll>;
using vi = vector <int>;
using ii = pair <ll, ll>;
using vii = vector <ii>;

const ll MAXN = 1.3E5+16;
vii adj[MAXN];
vii adjT[MAXN];
bool vis[MAXN];
ll toPar[MAXN];
ll dep[MAXN];

vll ord;
void dfs (ll u) {
    vis[u] = true;
    for (auto [v, id] : adjT[u]) {
        if (vis[v]) continue;
        dep[v] = dep[u]+1;
        dfs(v);
        toPar[v] = id;
    }
    ord.push_back(u);
}

void find_pair (int n, vi us, vi vs, int a, int b) {
    ll m = us.size();
    for (ll i = 0; i < m; i++) {
        adj[us[i]].push_back({ vs[i], i });
        adj[vs[i]].push_back({ us[i], i });
    }
    ll raw = ask(vi(m, 0));
    ll dis = raw/a;
    vi askMask(m, -15);
    ll src1 = -15, src2 = -15;
    {ll l = -1, r = m-1;
    while (l+1 < r) {
        ll mid = (l+r)>>1;
        vi vask(m, 0);
        for (ll i = 0; i <= mid; i++) vask[i] = 1;
        if (ask(vask) == raw)
            l = mid;
        else
            r = mid;
    }
    askMask = vi(m, 1);
    src1 = us[r];
    src2 = vs[r];
    queue <ll> q;
    vector <char> vis(n, false);
    vis[src1] = true; q.push(src1);
    vis[src2] = true; q.push(src2);
    adjT[src1].push_back({ src2, r });
    adjT[src2].push_back({ src1, r });
    askMask[r] = 0;
    while (q.size()) {
        ll u = q.front(); q.pop();
        for (auto [v, id] : adj[u]) {
            if (vis[v] || id <= l) continue;
            vis[v] = true; q.push(v);
            // cerr << u << ' ' << v << '\n';
            adjT[u].push_back({ v, id });
            adjT[v].push_back({ u, id });
            askMask[id] = 0;
        }
    }}
    dep[src1] = 0;
    dfs(src1);
    // for (ll i : askMask) cout << i << ' ';
    // cout << " askMask\n";
    // for (ll i : ord) cout << i << ' ';
    // cout << " ord\n";
    // for (ll i : ord) cout << toPar[i] << ' ';
    // cout << " par[ord]\n";
    ll u1 = -15, u2 = -15;
    {ll l = -1, r = ord.size();
    // l es normal
    // r lo corta
    while (l+1 < r) {
        ll mid = (l+r)>>1;
        vi vask(askMask.begin(), askMask.end());
        for (ll i = 0; i <= mid; i++) vask[toPar[ord[i]]] = 1;
        if (ask(vask) == raw)
            l = mid;
        else
            r = mid;
    }
    u1 = ord[r];}
    // cout << u1 << " u1\n";
    fill(vis, vis+MAXN, false);
    ord.clear();
    dep[u1] = 0;
    dfs(u1);
    {vll nord;
    for (ll i : ord)
        if (dep[i] == dis) nord.push_back(i);
    swap(ord, nord);}
    // for (ll i : ord) cout << i << ' ';
    // cout << " ord\n";
    {ll l = -1, r = ord.size();
    // l es normal
    // r lo corta
    while (l+1 < r) {
        ll mid = (l+r)>>1;
        vi vask(askMask.begin(), askMask.end());
        for (ll i = 0; i <= mid; i++) vask[toPar[ord[i]]] = 1;
        if (ask(vask) == raw)
            l = mid;
        else
            r = mid;
    }
    // cout << "l, r: " << l << ' ' << r << '\n';
    // cout << "ord[l, r]: " << ord[l] << ' ' << ord[r] << '\n';
    u2 = ord[r];}
    // cout << "u1 " << u1 << '\n';
    // cout << "u2 " << u2 << '\n';
    answer(u1, u2);
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Correct 1 ms 8536 KB Output is correct
3 Correct 1 ms 8360 KB Output is correct
4 Correct 2 ms 8536 KB Output is correct
5 Correct 1 ms 8536 KB Output is correct
6 Correct 1 ms 8536 KB Output is correct
7 Correct 2 ms 8536 KB Output is correct
8 Correct 2 ms 8536 KB Output is correct
9 Correct 2 ms 8536 KB Output is correct
10 Correct 2 ms 8536 KB Output is correct
11 Correct 1 ms 8536 KB Output is correct
12 Correct 1 ms 8536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Correct 8 ms 9816 KB Output is correct
3 Correct 87 ms 20384 KB Output is correct
4 Correct 86 ms 20384 KB Output is correct
5 Correct 90 ms 21140 KB Output is correct
6 Correct 86 ms 18600 KB Output is correct
7 Correct 72 ms 17964 KB Output is correct
8 Correct 76 ms 21204 KB Output is correct
9 Correct 78 ms 18120 KB Output is correct
10 Correct 87 ms 19460 KB Output is correct
11 Correct 64 ms 16776 KB Output is correct
12 Correct 81 ms 22256 KB Output is correct
13 Correct 82 ms 22492 KB Output is correct
14 Correct 86 ms 22752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 10328 KB Output is correct
2 Correct 14 ms 12472 KB Output is correct
3 Correct 19 ms 11040 KB Output is correct
4 Correct 60 ms 22436 KB Output is correct
5 Correct 61 ms 22564 KB Output is correct
6 Correct 63 ms 25008 KB Output is correct
7 Correct 50 ms 15632 KB Output is correct
8 Correct 61 ms 23492 KB Output is correct
9 Correct 66 ms 18240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Correct 8 ms 9816 KB Output is correct
3 Correct 72 ms 18420 KB Output is correct
4 Correct 69 ms 19940 KB Output is correct
5 Correct 59 ms 15788 KB Output is correct
6 Correct 56 ms 15780 KB Output is correct
7 Correct 65 ms 17944 KB Output is correct
8 Correct 61 ms 16088 KB Output is correct
9 Correct 83 ms 20372 KB Output is correct
10 Correct 87 ms 18860 KB Output is correct
11 Correct 81 ms 21912 KB Output is correct
12 Correct 82 ms 22500 KB Output is correct
13 Correct 82 ms 20888 KB Output is correct
14 Correct 67 ms 17576 KB Output is correct
15 Correct 57 ms 15800 KB Output is correct
16 Correct 61 ms 15652 KB Output is correct
17 Correct 91 ms 21824 KB Output is correct
18 Correct 81 ms 22948 KB Output is correct
19 Correct 53 ms 15564 KB Output is correct
20 Correct 58 ms 15932 KB Output is correct
21 Correct 68 ms 19004 KB Output is correct
22 Correct 63 ms 16804 KB Output is correct
23 Correct 86 ms 21120 KB Output is correct
24 Correct 79 ms 21688 KB Output is correct
25 Correct 99 ms 26516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 10072 KB Output is correct
2 Correct 10 ms 10096 KB Output is correct
3 Correct 94 ms 21648 KB Output is correct
4 Correct 105 ms 21656 KB Output is correct
5 Correct 119 ms 22812 KB Output is correct
6 Correct 122 ms 23612 KB Output is correct
7 Correct 115 ms 23408 KB Output is correct
8 Correct 114 ms 23408 KB Output is correct
9 Correct 78 ms 17192 KB Output is correct
10 Correct 90 ms 19348 KB Output is correct
11 Correct 108 ms 20044 KB Output is correct
12 Correct 112 ms 22632 KB Output is correct
13 Correct 116 ms 23164 KB Output is correct
14 Correct 126 ms 23608 KB Output is correct
15 Correct 114 ms 23596 KB Output is correct
16 Correct 112 ms 20356 KB Output is correct
17 Correct 76 ms 19264 KB Output is correct
18 Correct 63 ms 16616 KB Output is correct
19 Correct 78 ms 21288 KB Output is correct
20 Correct 68 ms 17828 KB Output is correct
21 Correct 114 ms 24128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 10072 KB Output is correct
2 Correct 12 ms 9984 KB Output is correct
3 Correct 93 ms 21688 KB Output is correct
4 Correct 115 ms 21776 KB Output is correct
5 Correct 101 ms 22012 KB Output is correct
6 Correct 134 ms 23300 KB Output is correct
7 Correct 96 ms 21724 KB Output is correct
8 Correct 105 ms 21960 KB Output is correct
9 Correct 98 ms 21900 KB Output is correct
10 Correct 114 ms 23352 KB Output is correct
11 Correct 123 ms 23684 KB Output is correct
12 Correct 116 ms 23328 KB Output is correct
13 Correct 79 ms 18088 KB Output is correct
14 Correct 74 ms 18652 KB Output is correct
15 Correct 91 ms 20620 KB Output is correct
16 Correct 88 ms 19260 KB Output is correct
17 Correct 96 ms 19992 KB Output is correct
18 Correct 84 ms 19572 KB Output is correct
19 Correct 118 ms 22588 KB Output is correct
20 Correct 129 ms 23084 KB Output is correct
21 Correct 133 ms 23708 KB Output is correct
22 Correct 115 ms 23604 KB Output is correct
23 Correct 140 ms 23612 KB Output is correct
24 Correct 125 ms 23724 KB Output is correct
25 Correct 138 ms 23444 KB Output is correct
26 Correct 135 ms 23596 KB Output is correct
27 Correct 77 ms 17968 KB Output is correct
28 Correct 77 ms 20200 KB Output is correct
29 Correct 87 ms 22528 KB Output is correct
30 Correct 75 ms 21780 KB Output is correct
31 Correct 71 ms 20396 KB Output is correct
32 Correct 79 ms 21188 KB Output is correct
33 Partially correct 81 ms 22688 KB Output is partially correct
34 Correct 80 ms 19644 KB Output is correct
35 Correct 72 ms 20200 KB Output is correct
36 Correct 82 ms 21472 KB Output is correct
37 Correct 75 ms 20624 KB Output is correct
38 Correct 80 ms 21508 KB Output is correct
39 Correct 116 ms 24408 KB Output is correct
40 Correct 133 ms 24632 KB Output is correct
41 Correct 117 ms 24104 KB Output is correct
42 Correct 113 ms 23864 KB Output is correct