Submission #613999

# Submission time Handle Problem Language Result Execution time Memory
613999 2022-07-30T16:03:53 Z cheissmart Highway Tolls (IOI18_highway) C++14
100 / 100
321 ms 16408 KB
#include "highway.h"
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

void find_pair(int n, vi _u, vi _v, int a, int b) {
    V<vi> G(n), g(n);
    int m = SZ(_u);
    for(int i = 0; i < m; i++) {
        int u = _u[i], v = _v[i];
        G[u].PB(v);
        G[v].PB(u);
        g[u].PB(i);
        g[v].PB(i);
    }
    auto qry = [&] (vi s) -> ll {
        vi w(m);
        for(int i:s)
            w[i] = 1;
        return ask(w);
    };
    ll he = qry(vi());
    int lb = 0, rb = m - 1;
    while(lb <= rb) {
        int mb = (lb + rb) / 2;
        vi bad(mb + 1); iota(ALL(bad), 0);
        if(qry(bad) != he) rb = mb - 1;
        else lb = mb + 1;
    }

    auto BFS = [&] (int s) {
        vi d(n, -1);
        d[s] = 0;
        queue<int> q({s});
        while(q.size()) {
            int u = q.front(); q.pop();
            for(int v:G[u]) if(d[v] == -1) {
                d[v] = d[u] + 1;
                q.push(v);
            }
        }
        return d;
    };

    int u = _u[lb], v = _v[lb];
    vi du = BFS(u), dv = BFS(v);

    vi s, t;
    for(int i = 0; i < n; i++) {
        if(du[i] < dv[i]) {
            s.PB(i);
        } else if(du[i] > dv[i]) {
            t.PB(i);
        }
    }

    sort(ALL(s), [&] (int i, int j) {
        return du[i] > du[j];
    });

    sort(ALL(t), [&] (int i, int j) {
        return dv[i] > dv[j];
    });

    lb = 0, rb = SZ(s) - 1;
    while(lb <= rb) {
        int mb = (lb + rb) / 2;
        vi bad;
        for(int i = 0; i <= mb; i++)
            for(int e:g[s[i]])
                bad.PB(e);

        if(qry(bad) != he) rb = mb - 1;
        else lb = mb + 1;
    }

    int S = s[lb];

    lb = 0, rb = SZ(t) - 1;
    while(lb <= rb) {
        int mb = (lb + rb) / 2;
        vi bad;
        for(int i = 0; i <= mb; i++)
            for(int e:g[t[i]])
                bad.PB(e);

        if(qry(bad) != he) rb = mb - 1;
        else lb = mb + 1;
    }

    int T = t[lb];

    answer(S, T);

}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 208 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 396 KB Output is correct
2 Correct 21 ms 1964 KB Output is correct
3 Correct 206 ms 14044 KB Output is correct
4 Correct 161 ms 13792 KB Output is correct
5 Correct 170 ms 13800 KB Output is correct
6 Correct 182 ms 13864 KB Output is correct
7 Correct 178 ms 14004 KB Output is correct
8 Correct 213 ms 14944 KB Output is correct
9 Correct 199 ms 14976 KB Output is correct
10 Correct 194 ms 13980 KB Output is correct
11 Correct 239 ms 14528 KB Output is correct
12 Correct 210 ms 14192 KB Output is correct
13 Correct 195 ms 14168 KB Output is correct
14 Correct 247 ms 14136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 1932 KB Output is correct
2 Correct 27 ms 3444 KB Output is correct
3 Correct 57 ms 4988 KB Output is correct
4 Correct 157 ms 14152 KB Output is correct
5 Correct 127 ms 14488 KB Output is correct
6 Correct 129 ms 13684 KB Output is correct
7 Correct 134 ms 14728 KB Output is correct
8 Correct 159 ms 13804 KB Output is correct
9 Correct 117 ms 14224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 424 KB Output is correct
2 Correct 19 ms 1880 KB Output is correct
3 Correct 140 ms 11824 KB Output is correct
4 Correct 187 ms 14516 KB Output is correct
5 Correct 257 ms 14932 KB Output is correct
6 Correct 183 ms 15096 KB Output is correct
7 Correct 229 ms 14968 KB Output is correct
8 Correct 206 ms 15048 KB Output is correct
9 Correct 202 ms 14264 KB Output is correct
10 Correct 187 ms 14184 KB Output is correct
11 Correct 198 ms 14152 KB Output is correct
12 Correct 180 ms 13716 KB Output is correct
13 Correct 205 ms 14028 KB Output is correct
14 Correct 271 ms 14256 KB Output is correct
15 Correct 197 ms 14944 KB Output is correct
16 Correct 229 ms 14960 KB Output is correct
17 Correct 212 ms 13840 KB Output is correct
18 Correct 215 ms 14132 KB Output is correct
19 Correct 213 ms 15024 KB Output is correct
20 Correct 244 ms 14684 KB Output is correct
21 Correct 147 ms 14532 KB Output is correct
22 Correct 121 ms 14216 KB Output is correct
23 Correct 187 ms 14452 KB Output is correct
24 Correct 144 ms 14008 KB Output is correct
25 Correct 182 ms 13804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 1824 KB Output is correct
2 Correct 18 ms 1996 KB Output is correct
3 Correct 212 ms 14208 KB Output is correct
4 Correct 204 ms 14496 KB Output is correct
5 Correct 286 ms 16152 KB Output is correct
6 Correct 279 ms 16088 KB Output is correct
7 Correct 285 ms 16200 KB Output is correct
8 Correct 289 ms 15780 KB Output is correct
9 Correct 234 ms 9580 KB Output is correct
10 Correct 205 ms 9972 KB Output is correct
11 Correct 220 ms 10504 KB Output is correct
12 Correct 237 ms 13460 KB Output is correct
13 Correct 302 ms 14676 KB Output is correct
14 Correct 321 ms 15624 KB Output is correct
15 Correct 251 ms 15884 KB Output is correct
16 Correct 175 ms 10556 KB Output is correct
17 Correct 167 ms 14580 KB Output is correct
18 Correct 135 ms 14396 KB Output is correct
19 Correct 159 ms 14256 KB Output is correct
20 Correct 149 ms 14528 KB Output is correct
21 Correct 284 ms 16188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 1952 KB Output is correct
2 Correct 18 ms 1912 KB Output is correct
3 Correct 262 ms 14924 KB Output is correct
4 Correct 248 ms 15156 KB Output is correct
5 Correct 243 ms 15452 KB Output is correct
6 Correct 227 ms 15232 KB Output is correct
7 Correct 256 ms 15228 KB Output is correct
8 Correct 215 ms 15432 KB Output is correct
9 Correct 257 ms 14704 KB Output is correct
10 Correct 314 ms 16220 KB Output is correct
11 Correct 264 ms 15728 KB Output is correct
12 Correct 299 ms 15756 KB Output is correct
13 Correct 237 ms 10844 KB Output is correct
14 Correct 207 ms 10008 KB Output is correct
15 Correct 163 ms 10796 KB Output is correct
16 Correct 177 ms 10060 KB Output is correct
17 Correct 161 ms 10572 KB Output is correct
18 Correct 189 ms 9844 KB Output is correct
19 Correct 278 ms 13524 KB Output is correct
20 Correct 249 ms 14996 KB Output is correct
21 Correct 315 ms 15680 KB Output is correct
22 Correct 268 ms 15384 KB Output is correct
23 Correct 309 ms 15516 KB Output is correct
24 Correct 320 ms 15568 KB Output is correct
25 Correct 290 ms 15896 KB Output is correct
26 Correct 301 ms 15616 KB Output is correct
27 Correct 141 ms 14528 KB Output is correct
28 Correct 158 ms 14568 KB Output is correct
29 Correct 156 ms 14984 KB Output is correct
30 Correct 150 ms 14412 KB Output is correct
31 Correct 193 ms 14696 KB Output is correct
32 Correct 122 ms 14224 KB Output is correct
33 Correct 156 ms 14648 KB Output is correct
34 Correct 118 ms 14388 KB Output is correct
35 Correct 157 ms 14664 KB Output is correct
36 Correct 130 ms 14200 KB Output is correct
37 Correct 128 ms 14596 KB Output is correct
38 Correct 142 ms 14428 KB Output is correct
39 Correct 318 ms 16408 KB Output is correct
40 Correct 276 ms 16084 KB Output is correct
41 Correct 225 ms 15124 KB Output is correct
42 Correct 283 ms 15956 KB Output is correct