답안 #116160

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
116160 2019-06-11T03:41:58 Z RezwanArefin01 통행료 (IOI18_highway) C++17
51 / 100
325 ms 9980 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;
int l[MX], r[MX], a, b, n, m, comp[MX];
ll base0;

int findEdge() {
    int lo = 0, hi = m - 1, e;
    base0 = ask(q);

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

    return e;
}

void bfs(int root, vector<int> &d, int c, bool store = 0) {
    queue<int> Q; 
    d[root] = 0; 
    Q.push(root); 

    while(!Q.empty()) {
        int u = Q.front(); Q.pop();
        for(int i : adj[u]) {
            int v = u ^ l[i] ^ r[i]; 
            if(comp[v] == c && d[v] == -1) {
                d[v] = d[u] + 1; 
                Q.push(v);
                if(store) t.push_back(i);
            }
        }
    }
}

int find(int c, vector<int> &d) {
    if(!t.size()) return -1; 

    sort(t.begin(), t.end(), [&](int i, int j) {
        return max(d[l[i]], d[r[i]]) < max(d[l[j]], d[r[j]]); 
    });

    q = vector<int> (m, 0);
    for(int i : t) q[i] = 1; 

    ll base = ask(q); 
    if(base == base0) return -1;

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

    return d[l[e]] > d[r[e]] ? l[e] : r[e];
}

void find_pair(int _n, vector<int> U, vector<int> V, int _a, int _b) {
    n = _n, a = _a, b = _b;
    m = U.size(); 
    copy(U.begin(), U.end(), l); 
    copy(V.begin(), V.end(), r); 

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

    int e = findEdge(); 

    vector<int> du (n, -1), dv (n, -1); 
    bfs(l[e], du, 0); 
    bfs(r[e], dv, 0); 

    for(int i = 0; i < n; ++i) {
        comp[i] = du[i] > dv[i];
    }   

    du = vector<int> (n, -1); 
    bfs(l[e], du, 0, 1); 
    int S = find(0, du); 

    t.clear(); 

    dv = vector<int> (n, -1);
    bfs(r[e], dv, 1, 1);
    int T = find(0, dv); 

    if(S == -1) S = l[e]; 
    if(T == -1) T = r[e];
    answer(S, T);
}

Compilation message

highway.cpp: In function 'int findEdge()':
highway.cpp:17:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int mid = lo + hi >> 1; 
                   ~~~^~~~
highway.cpp: In function 'int find(int, std::vector<int>&)':
highway.cpp:61:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int mid = lo + hi >> 1; 
                   ~~~^~~~
highway.cpp: In function 'int findEdge()':
highway.cpp:25:12: warning: 'e' may be used uninitialized in this function [-Wmaybe-uninitialized]
     return e;
            ^
highway.cpp: In function 'int find(int, std::vector<int>&)':
highway.cpp:70:27: warning: 'e' may be used uninitialized in this function [-Wmaybe-uninitialized]
     return d[l[e]] > d[r[e]] ? l[e] : r[e];
                        ~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2452 KB Output is correct
2 Correct 4 ms 2448 KB Output is correct
3 Correct 4 ms 2424 KB Output is correct
4 Correct 4 ms 2452 KB Output is correct
5 Correct 4 ms 2424 KB Output is correct
6 Correct 4 ms 2452 KB Output is correct
7 Correct 4 ms 2444 KB Output is correct
8 Correct 4 ms 2524 KB Output is correct
9 Correct 4 ms 2448 KB Output is correct
10 Correct 4 ms 2456 KB Output is correct
11 Correct 4 ms 2424 KB Output is correct
12 Correct 4 ms 2444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2424 KB Output is correct
2 Correct 27 ms 3240 KB Output is correct
3 Correct 220 ms 9656 KB Output is correct
4 Correct 252 ms 9760 KB Output is correct
5 Correct 325 ms 9752 KB Output is correct
6 Correct 194 ms 9692 KB Output is correct
7 Correct 253 ms 9756 KB Output is correct
8 Correct 234 ms 9756 KB Output is correct
9 Correct 180 ms 9684 KB Output is correct
10 Correct 232 ms 9760 KB Output is correct
11 Correct 282 ms 9616 KB Output is correct
12 Correct 266 ms 9552 KB Output is correct
13 Correct 265 ms 9700 KB Output is correct
14 Correct 250 ms 9560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 3272 KB Output is correct
2 Correct 43 ms 3988 KB Output is correct
3 Correct 54 ms 4908 KB Output is correct
4 Correct 180 ms 9612 KB Output is correct
5 Correct 139 ms 9644 KB Output is correct
6 Correct 169 ms 9696 KB Output is correct
7 Correct 175 ms 9520 KB Output is correct
8 Correct 167 ms 9780 KB Output is correct
9 Correct 185 ms 9560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2472 KB Output is correct
2 Correct 26 ms 3192 KB Output is correct
3 Correct 179 ms 8168 KB Output is correct
4 Correct 225 ms 9772 KB Output is correct
5 Correct 239 ms 9656 KB Output is correct
6 Correct 220 ms 9728 KB Output is correct
7 Correct 216 ms 9644 KB Output is correct
8 Correct 234 ms 9688 KB Output is correct
9 Correct 238 ms 9652 KB Output is correct
10 Correct 220 ms 9656 KB Output is correct
11 Correct 246 ms 9688 KB Output is correct
12 Correct 264 ms 9644 KB Output is correct
13 Correct 271 ms 9584 KB Output is correct
14 Correct 254 ms 9652 KB Output is correct
15 Correct 234 ms 9780 KB Output is correct
16 Correct 272 ms 9692 KB Output is correct
17 Correct 287 ms 9592 KB Output is correct
18 Correct 258 ms 9556 KB Output is correct
19 Correct 213 ms 9664 KB Output is correct
20 Correct 247 ms 9632 KB Output is correct
21 Correct 141 ms 9964 KB Output is correct
22 Correct 184 ms 9912 KB Output is correct
23 Correct 187 ms 9980 KB Output is correct
24 Correct 215 ms 9944 KB Output is correct
25 Correct 279 ms 9612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 30 ms 3324 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 26 ms 3284 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -