Submission #236759

# Submission time Handle Problem Language Result Execution time Memory
236759 2020-06-03T08:39:11 Z lyc Highway Tolls (IOI18_highway) C++14
100 / 100
313 ms 10988 KB
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;

#define TRACE(x) cout << #x << " :: " << x << endl;
#define _ << " " <<
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
typedef long long ll;
typedef pair<int,int> ii;

const int mxN = 90005;
const int mxM = 130005;
int N, M, A, B;
int E[mxM];
vector<int> al[mxN], num;
vector<ii> pa;

vector<int> w;
ll L;
int qcnt = 0;
bool query() { 
    ++qcnt;
    assert(qcnt <= 100);
    ll r = ask(w);
    //cout << qcnt << " :: ";
    //FOR(i,0,M-1) cout << w[i] << ' ';
    //cout << " :: " << r << endl;
    return r == L;
}

void bfs(vector<int> s) {
    int cnt = 0;
    num.assign(N,-1);
    pa.assign(N,ii(-1,-1));
    queue<int> q;
    for (auto& u : s) { num[u] = cnt++, pa[u].second = u, q.push(u); }
    while (!q.empty()) {
        int u = q.front(); q.pop();
        for (int e : al[u]) {
            int v = E[e]^u;
            if (num[v] == -1) { num[v] = cnt++, pa[v] = ii(e,pa[u].second), q.push(v); }
        }
    }
}

void setW(vector<int>::iterator s, vector<int>::iterator e, int p) {
    vector<int> vis(N,0);
    for (auto it = s; it != e; ++it) {
        for (int x = *it; pa[x].first != -1 && !vis[x]; x = E[pa[x].first]^x) {
            vis[x] = 1;
            w[pa[x].first] = p;
        }
    }
}

int solve(int s) {
    vector<int> vtx;
    FOR(i,0,N-1) if (pa[i].second == s) vtx.push_back(i);
    sort(ALL(vtx),[](int a, int b) { return num[a] < num[b]; });
    //cout << "VTX: ";
    //for (auto& x : vtx) cout << x << ' ';
    //cout << endl;
    setW(ALL(vtx),1);
    int lo = -1, hi = SZ(vtx)-1;
    while (hi-lo > 1) {
        int mid = (lo+hi)/2;
        setW(vtx.begin(),vtx.begin()+mid+1,0);
        if (query()) hi = mid;
        else lo = mid;
        setW(vtx.begin(),vtx.begin()+mid+1,1);
    }
    setW(ALL(vtx),0);
    //TRACE(hi _ vtx[hi]);
    return vtx[hi];
}

void find_pair(int _N, vector<int> U, vector<int> V, int _A, int _B) {
    N = _N;
    M = U.size();
    FOR(i,0,M-1){
        E[i] = U[i]^V[i];
        al[U[i]].push_back(i);
        al[V[i]].push_back(i);
    }
    A = _A, B = _B;

    w.assign(M,0);
    L = ask(w);

    int lo = -1, hi = M;
    while (hi-lo > 1) {
        int mid = (lo+hi)/2;
        FOR(i,lo+1,mid) w[i] = 1;
        if (query()) lo = mid;
        else {
            FOR(i,lo+1,mid) w[i] = 0;
            hi = mid;
        }
    }

    bfs({U[hi],V[hi]});
    w.assign(M,1);
    vector<int> vtx(N); iota(ALL(vtx),0);
    setW(ALL(vtx),0);
    w[hi] = 0;
    int S = solve(U[hi]), T = solve(V[hi]);
    //TRACE(S _ T);
    answer(S,T);
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2432 KB Output is correct
2 Correct 6 ms 2432 KB Output is correct
3 Correct 6 ms 2432 KB Output is correct
4 Correct 6 ms 2432 KB Output is correct
5 Correct 6 ms 2432 KB Output is correct
6 Correct 6 ms 2432 KB Output is correct
7 Correct 6 ms 2432 KB Output is correct
8 Correct 6 ms 2432 KB Output is correct
9 Correct 6 ms 2432 KB Output is correct
10 Correct 6 ms 2432 KB Output is correct
11 Correct 6 ms 2432 KB Output is correct
12 Correct 6 ms 2496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 2572 KB Output is correct
2 Correct 19 ms 3200 KB Output is correct
3 Correct 211 ms 9932 KB Output is correct
4 Correct 214 ms 9824 KB Output is correct
5 Correct 226 ms 9832 KB Output is correct
6 Correct 203 ms 9928 KB Output is correct
7 Correct 233 ms 9820 KB Output is correct
8 Correct 164 ms 9820 KB Output is correct
9 Correct 176 ms 9824 KB Output is correct
10 Correct 202 ms 9820 KB Output is correct
11 Correct 186 ms 9700 KB Output is correct
12 Correct 235 ms 9744 KB Output is correct
13 Correct 222 ms 9704 KB Output is correct
14 Correct 196 ms 9768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 3200 KB Output is correct
2 Correct 34 ms 4048 KB Output is correct
3 Correct 43 ms 4844 KB Output is correct
4 Correct 124 ms 9672 KB Output is correct
5 Correct 119 ms 9696 KB Output is correct
6 Correct 133 ms 9664 KB Output is correct
7 Correct 129 ms 9700 KB Output is correct
8 Correct 132 ms 9840 KB Output is correct
9 Correct 127 ms 9628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2560 KB Output is correct
2 Correct 18 ms 3176 KB Output is correct
3 Correct 116 ms 8280 KB Output is correct
4 Correct 180 ms 9956 KB Output is correct
5 Correct 160 ms 9816 KB Output is correct
6 Correct 205 ms 9832 KB Output is correct
7 Correct 153 ms 9832 KB Output is correct
8 Correct 145 ms 9820 KB Output is correct
9 Correct 194 ms 9792 KB Output is correct
10 Correct 184 ms 9812 KB Output is correct
11 Correct 203 ms 9912 KB Output is correct
12 Correct 223 ms 9676 KB Output is correct
13 Correct 207 ms 9696 KB Output is correct
14 Correct 196 ms 9780 KB Output is correct
15 Correct 148 ms 9824 KB Output is correct
16 Correct 148 ms 9824 KB Output is correct
17 Correct 194 ms 9688 KB Output is correct
18 Correct 202 ms 9808 KB Output is correct
19 Correct 147 ms 9816 KB Output is correct
20 Correct 167 ms 9700 KB Output is correct
21 Correct 167 ms 10068 KB Output is correct
22 Correct 174 ms 10160 KB Output is correct
23 Correct 183 ms 9984 KB Output is correct
24 Correct 226 ms 9960 KB Output is correct
25 Correct 217 ms 9736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 3320 KB Output is correct
2 Correct 26 ms 3320 KB Output is correct
3 Correct 281 ms 10188 KB Output is correct
4 Correct 229 ms 10292 KB Output is correct
5 Correct 224 ms 10860 KB Output is correct
6 Correct 241 ms 10932 KB Output is correct
7 Correct 298 ms 10896 KB Output is correct
8 Correct 262 ms 10888 KB Output is correct
9 Correct 155 ms 7932 KB Output is correct
10 Correct 159 ms 8324 KB Output is correct
11 Correct 184 ms 8488 KB Output is correct
12 Correct 218 ms 10180 KB Output is correct
13 Correct 248 ms 10564 KB Output is correct
14 Correct 247 ms 10728 KB Output is correct
15 Correct 286 ms 10920 KB Output is correct
16 Correct 204 ms 8932 KB Output is correct
17 Correct 222 ms 10180 KB Output is correct
18 Correct 180 ms 10192 KB Output is correct
19 Correct 213 ms 10200 KB Output is correct
20 Correct 166 ms 10264 KB Output is correct
21 Correct 229 ms 10868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 3328 KB Output is correct
2 Correct 24 ms 3320 KB Output is correct
3 Correct 229 ms 10132 KB Output is correct
4 Correct 197 ms 10292 KB Output is correct
5 Correct 228 ms 10464 KB Output is correct
6 Correct 313 ms 10912 KB Output is correct
7 Correct 177 ms 10148 KB Output is correct
8 Correct 186 ms 10184 KB Output is correct
9 Correct 221 ms 10392 KB Output is correct
10 Correct 274 ms 10928 KB Output is correct
11 Correct 222 ms 10936 KB Output is correct
12 Correct 226 ms 10988 KB Output is correct
13 Correct 226 ms 8600 KB Output is correct
14 Correct 171 ms 8280 KB Output is correct
15 Correct 203 ms 8628 KB Output is correct
16 Correct 192 ms 8408 KB Output is correct
17 Correct 215 ms 8556 KB Output is correct
18 Correct 206 ms 8272 KB Output is correct
19 Correct 225 ms 10148 KB Output is correct
20 Correct 236 ms 10516 KB Output is correct
21 Correct 252 ms 10912 KB Output is correct
22 Correct 263 ms 10720 KB Output is correct
23 Correct 237 ms 10760 KB Output is correct
24 Correct 304 ms 10812 KB Output is correct
25 Correct 242 ms 10872 KB Output is correct
26 Correct 278 ms 10740 KB Output is correct
27 Correct 190 ms 10208 KB Output is correct
28 Correct 197 ms 10140 KB Output is correct
29 Correct 200 ms 10392 KB Output is correct
30 Correct 242 ms 10216 KB Output is correct
31 Correct 229 ms 10180 KB Output is correct
32 Correct 226 ms 10232 KB Output is correct
33 Correct 218 ms 10308 KB Output is correct
34 Correct 226 ms 10308 KB Output is correct
35 Correct 193 ms 10244 KB Output is correct
36 Correct 193 ms 10108 KB Output is correct
37 Correct 195 ms 10500 KB Output is correct
38 Correct 202 ms 10264 KB Output is correct
39 Correct 239 ms 10952 KB Output is correct
40 Correct 277 ms 10932 KB Output is correct
41 Correct 298 ms 10972 KB Output is correct
42 Correct 256 ms 10880 KB Output is correct