Submission #116166

# Submission time Handle Problem Language Result Execution time Memory
116166 2019-06-11T04:09:31 Z RezwanArefin01 Highway Tolls (IOI18_highway) C++17
100 / 100
366 ms 9820 KB
#include <bits/stdc++.h>
using namespace std;
#include "highway.h"

typedef long long ll; 

const int MX = 9e4 + 5; 
vector<int> adj[MX], q, t[2];
int d[MX]; 
bool vis[MX]; 

void find_pair(int n, vector<int> l, vector<int> r, int a, int b) {
    int m = l.size(); 

    for(int i = 0; i < m; ++i) {
        adj[l[i]].push_back(i);
        adj[r[i]].push_back(i);
    }

    q = vector<int> (m, 0);
    ll base = ask(q); 

    int lo = 0, hi = m - 1, e;
    while(lo <= hi) {
        int mid = lo + hi >> 1; 
        for(int i = 0; i < m; ++i) 
            q[i] = i <= mid;
        if(ask(q) != base) 
            e = mid, hi = mid - 1; 
        else lo = mid + 1; 
    }

    int x = l[e], y = r[e]; 

    memset(d, 63, sizeof d);
    queue<pair<int, int>> Q; 
    d[x] = d[y] = 0;
    Q.emplace(x, 0); 
    Q.emplace(y, 1);

    while(!Q.empty()) {
        auto it = Q.front(); Q.pop();
        int u = it.first, c = it.second;
        t[c].push_back(u); 
        for(int i : adj[u]) {
            int v = u ^ l[i] ^ r[i]; 
            if(d[v] > d[u] + 1) {
                d[v] = d[u] + 1;
                Q.emplace(v, c); 
            }
        }
    }

    int S, T; 
    for(int i = 0; i < 2; ++i) {
        int sz = t[i].size(); 
        lo = 0, hi = sz - 1;
        while(lo <= hi) {
            int mid = lo + hi >> 1; 
            q = vector<int> (m, 0); 
            for(int j = mid + 1; j < sz; ++j) 
                vis[t[i][j]] = 1; 
            for(int i = 0; i < m; ++i) 
                if(vis[l[i]] || vis[r[i]]) 
                    q[i] = 1; 
            if(ask(q) == base) e = mid, hi = mid - 1; 
            else lo = mid + 1;
            for(int j = mid + 1; j < sz; ++j) 
                vis[t[i][j]] = 0; 
        }
        if(i) S = t[i][e]; 
        else T = t[i][e];
    }
    answer(S, T);
}

Compilation message

highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:25:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int mid = lo + hi >> 1; 
                   ~~~^~~~
highway.cpp:59:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
             int mid = lo + hi >> 1; 
                       ~~~^~~~
highway.cpp:33:16: warning: 'e' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int x = l[e], y = r[e]; 
                ^
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2808 KB Output is correct
2 Correct 5 ms 2696 KB Output is correct
3 Correct 5 ms 2784 KB Output is correct
4 Correct 4 ms 2684 KB Output is correct
5 Correct 4 ms 2808 KB Output is correct
6 Correct 4 ms 2780 KB Output is correct
7 Correct 4 ms 2680 KB Output is correct
8 Correct 5 ms 2692 KB Output is correct
9 Correct 7 ms 2680 KB Output is correct
10 Correct 4 ms 2696 KB Output is correct
11 Correct 4 ms 2696 KB Output is correct
12 Correct 4 ms 2808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2768 KB Output is correct
2 Correct 19 ms 3340 KB Output is correct
3 Correct 216 ms 8368 KB Output is correct
4 Correct 207 ms 8376 KB Output is correct
5 Correct 212 ms 8472 KB Output is correct
6 Correct 185 ms 8336 KB Output is correct
7 Correct 237 ms 8368 KB Output is correct
8 Correct 182 ms 8516 KB Output is correct
9 Correct 199 ms 8384 KB Output is correct
10 Correct 210 ms 8372 KB Output is correct
11 Correct 229 ms 8204 KB Output is correct
12 Correct 266 ms 8248 KB Output is correct
13 Correct 212 ms 8200 KB Output is correct
14 Correct 232 ms 8364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 3320 KB Output is correct
2 Correct 37 ms 4044 KB Output is correct
3 Correct 51 ms 4608 KB Output is correct
4 Correct 166 ms 8180 KB Output is correct
5 Correct 170 ms 8244 KB Output is correct
6 Correct 178 ms 8324 KB Output is correct
7 Correct 155 ms 8256 KB Output is correct
8 Correct 170 ms 8324 KB Output is correct
9 Correct 208 ms 8208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2808 KB Output is correct
2 Correct 25 ms 3456 KB Output is correct
3 Correct 144 ms 7124 KB Output is correct
4 Correct 195 ms 8340 KB Output is correct
5 Correct 183 ms 8340 KB Output is correct
6 Correct 188 ms 8328 KB Output is correct
7 Correct 224 ms 8388 KB Output is correct
8 Correct 190 ms 8332 KB Output is correct
9 Correct 224 ms 8520 KB Output is correct
10 Correct 224 ms 8392 KB Output is correct
11 Correct 228 ms 8200 KB Output is correct
12 Correct 259 ms 8300 KB Output is correct
13 Correct 255 ms 8220 KB Output is correct
14 Correct 271 ms 8224 KB Output is correct
15 Correct 174 ms 8372 KB Output is correct
16 Correct 190 ms 8452 KB Output is correct
17 Correct 198 ms 8308 KB Output is correct
18 Correct 225 ms 8296 KB Output is correct
19 Correct 226 ms 8460 KB Output is correct
20 Correct 223 ms 8220 KB Output is correct
21 Correct 161 ms 9196 KB Output is correct
22 Correct 250 ms 9172 KB Output is correct
23 Correct 207 ms 8932 KB Output is correct
24 Correct 169 ms 8896 KB Output is correct
25 Correct 207 ms 8340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 3464 KB Output is correct
2 Correct 22 ms 3476 KB Output is correct
3 Correct 212 ms 8732 KB Output is correct
4 Correct 234 ms 9108 KB Output is correct
5 Correct 340 ms 9820 KB Output is correct
6 Correct 336 ms 9756 KB Output is correct
7 Correct 344 ms 9720 KB Output is correct
8 Correct 314 ms 9700 KB Output is correct
9 Correct 250 ms 7932 KB Output is correct
10 Correct 269 ms 8384 KB Output is correct
11 Correct 262 ms 8412 KB Output is correct
12 Correct 318 ms 9344 KB Output is correct
13 Correct 349 ms 9516 KB Output is correct
14 Correct 321 ms 9468 KB Output is correct
15 Correct 320 ms 9536 KB Output is correct
16 Correct 284 ms 8640 KB Output is correct
17 Correct 201 ms 9124 KB Output is correct
18 Correct 215 ms 9180 KB Output is correct
19 Correct 202 ms 9184 KB Output is correct
20 Correct 236 ms 9236 KB Output is correct
21 Correct 308 ms 9408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 3368 KB Output is correct
2 Correct 27 ms 3388 KB Output is correct
3 Correct 271 ms 8752 KB Output is correct
4 Correct 279 ms 8892 KB Output is correct
5 Correct 280 ms 9236 KB Output is correct
6 Correct 331 ms 9676 KB Output is correct
7 Correct 220 ms 8744 KB Output is correct
8 Correct 260 ms 8836 KB Output is correct
9 Correct 288 ms 9132 KB Output is correct
10 Correct 366 ms 9676 KB Output is correct
11 Correct 335 ms 9652 KB Output is correct
12 Correct 249 ms 9712 KB Output is correct
13 Correct 274 ms 8412 KB Output is correct
14 Correct 285 ms 8352 KB Output is correct
15 Correct 247 ms 8488 KB Output is correct
16 Correct 305 ms 8468 KB Output is correct
17 Correct 276 ms 8328 KB Output is correct
18 Correct 232 ms 8408 KB Output is correct
19 Correct 329 ms 9108 KB Output is correct
20 Correct 327 ms 9304 KB Output is correct
21 Correct 315 ms 9588 KB Output is correct
22 Correct 348 ms 9468 KB Output is correct
23 Correct 336 ms 9556 KB Output is correct
24 Correct 327 ms 9480 KB Output is correct
25 Correct 293 ms 9588 KB Output is correct
26 Correct 323 ms 9664 KB Output is correct
27 Correct 188 ms 9204 KB Output is correct
28 Correct 228 ms 9104 KB Output is correct
29 Correct 231 ms 9348 KB Output is correct
30 Correct 218 ms 9120 KB Output is correct
31 Correct 238 ms 9168 KB Output is correct
32 Correct 224 ms 9096 KB Output is correct
33 Correct 208 ms 9264 KB Output is correct
34 Correct 211 ms 9204 KB Output is correct
35 Correct 218 ms 9128 KB Output is correct
36 Correct 197 ms 9088 KB Output is correct
37 Correct 191 ms 9392 KB Output is correct
38 Correct 188 ms 9084 KB Output is correct
39 Correct 311 ms 9368 KB Output is correct
40 Correct 324 ms 9552 KB Output is correct
41 Correct 259 ms 9384 KB Output is correct
42 Correct 318 ms 9664 KB Output is correct