Submission #624042

# Submission time Handle Problem Language Result Execution time Memory
624042 2022-08-07T07:16:38 Z 79brue Highway Tolls (IOI18_highway) C++17
100 / 100
261 ms 13772 KB
#include "highway.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n, m;
ll A, B;
int ex[130002], ey[130002];
vector<pair<int, int> > link[100002];
ll def;

int U, V;
void findOneEdge(){
    int L = 0, R = m-2, ANS = m-1;
    while(L<=R){
        int MID = (L+R)/2;
        vector<int> tv (m, 0);
        for(int i=0; i<=MID; i++) tv[i] = 1;
        if(ask(tv) != def) ANS = MID, R = MID-1;
        else L = MID+1;
    }
    U = ex[ANS], V = ey[ANS];
}

int uDist[100002], vDist[100002];
void bfs(int st, int *dist){
    queue<pair<int, int> > que;
    vector<bool> vec (n);
    que.push(make_pair(st, 0));
    vec[st] = 1;

    while(!que.empty()){
        pair<int, int> tmp = que.front(); que.pop();
        dist[tmp.first] = tmp.second;
        for(auto y: link[tmp.first]){
            if(vec[y.first]) continue;
            vec[y.first] = 1;
            que.push(make_pair(y.first, tmp.second+1));
        }
    }
}

int group[100002]; /// 1이면 U그룹, 2이면 V그룹
vector<int> base;
vector<int> uVec, vVec;
int uIdx[100002], vIdx[100002];

void binarySearch(int &X, vector<int> &vec, int *idx, int gnum){
    int sz = (int)vec.size();
    int L = 0, R = sz-2, ANS = sz-1;
    while(L<=R){
        int MID = (L+R)/2;
        vector<int> v = base;
        for(int i=0; i<m; i++){
            if(group[ex[i]] == gnum && group[ey[i]] == gnum && ((idx[ex[i]] <= MID) ^ (idx[ey[i]] <= MID))) v[i] = 1;
        }
        if(ask(v) != def) L = MID+1;
        else ANS = MID, R = MID-1;
    }
    X = vec[ANS];
}

void find_pair(int N, vector<int> _U, vector<int> _V, int _A, int _B){
    n = N;
    m = (int)_U.size();
    def = ask(vector<int> (m, 0));
    for(int i=0; i<m; i++){
        ex[i] = _U[i], ey[i] = _V[i];
        link[ex[i]].push_back(make_pair(ey[i], i));
        link[ey[i]].push_back(make_pair(ex[i], i));
    }
    A = _A, B = _B;

    findOneEdge();
    bfs(U, uDist);
    bfs(V, vDist);

    for(int i=0; i<n; i++){
        if(uDist[i] == vDist[i]) continue;
        if(uDist[i] < vDist[i]) group[i] = 1;
        else group[i] = 2;
    }

    base = vector<int> (m, 0);
    for(int i=0; i<m; i++){
        if(!group[ex[i]] || !group[ey[i]] || group[ex[i]] != group[ey[i]]) base[i] = 1;
        else if(group[ex[i]] == 1){
            if(abs(uDist[ex[i]] - uDist[ey[i]]) != 1) base[i] = 1;
        }
        else if(group[ex[i]] == 2){
            if(abs(vDist[ex[i]] - vDist[ey[i]]) != 1) base[i] = 1;
        }
        if((U==ex[i] && V==ey[i]) || (U==ey[i] && V==ex[i])) base[i] = 0;
    }

    for(int i=0; i<n; i++){
        if(group[i] == 1) uVec.push_back(i);
        if(group[i] == 2) vVec.push_back(i);
    }
    sort(uVec.begin(), uVec.end(), [&](int x, int y){
        return uDist[x] < uDist[y];
    });
    sort(vVec.begin(), vVec.end(), [&](int x, int y){
        return vDist[x] < vDist[y];
    });
    for(int i=0; i<(int)uVec.size(); i++) uIdx[uVec[i]] = i;
    for(int i=0; i<(int)vVec.size(); i++) vIdx[vVec[i]] = i;

    binarySearch(U, uVec, uIdx, 1);
    binarySearch(V, vVec, vIdx, 2);
    answer(U, V);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2640 KB Output is correct
2 Correct 2 ms 2640 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 2 ms 2672 KB Output is correct
5 Correct 2 ms 2640 KB Output is correct
6 Correct 2 ms 2640 KB Output is correct
7 Correct 1 ms 2640 KB Output is correct
8 Correct 2 ms 2672 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2640 KB Output is correct
11 Correct 2 ms 2640 KB Output is correct
12 Correct 2 ms 2640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2768 KB Output is correct
2 Correct 18 ms 3552 KB Output is correct
3 Correct 161 ms 10972 KB Output is correct
4 Correct 134 ms 11172 KB Output is correct
5 Correct 155 ms 11288 KB Output is correct
6 Correct 152 ms 10828 KB Output is correct
7 Correct 178 ms 11172 KB Output is correct
8 Correct 128 ms 11184 KB Output is correct
9 Correct 106 ms 10900 KB Output is correct
10 Correct 121 ms 11180 KB Output is correct
11 Correct 158 ms 10712 KB Output is correct
12 Correct 139 ms 10588 KB Output is correct
13 Correct 160 ms 10572 KB Output is correct
14 Correct 118 ms 10560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 3520 KB Output is correct
2 Correct 32 ms 4376 KB Output is correct
3 Correct 49 ms 5116 KB Output is correct
4 Correct 119 ms 10300 KB Output is correct
5 Correct 94 ms 10232 KB Output is correct
6 Correct 138 ms 10240 KB Output is correct
7 Correct 136 ms 10224 KB Output is correct
8 Correct 92 ms 10276 KB Output is correct
9 Correct 135 ms 10248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2684 KB Output is correct
2 Correct 13 ms 3536 KB Output is correct
3 Correct 83 ms 8964 KB Output is correct
4 Correct 139 ms 10884 KB Output is correct
5 Correct 108 ms 10936 KB Output is correct
6 Correct 104 ms 10840 KB Output is correct
7 Correct 103 ms 10864 KB Output is correct
8 Correct 157 ms 10900 KB Output is correct
9 Correct 162 ms 11136 KB Output is correct
10 Correct 135 ms 11204 KB Output is correct
11 Correct 123 ms 10580 KB Output is correct
12 Correct 175 ms 10528 KB Output is correct
13 Correct 140 ms 10604 KB Output is correct
14 Correct 156 ms 10744 KB Output is correct
15 Correct 158 ms 10844 KB Output is correct
16 Correct 110 ms 10864 KB Output is correct
17 Correct 127 ms 10480 KB Output is correct
18 Correct 117 ms 10456 KB Output is correct
19 Correct 137 ms 10856 KB Output is correct
20 Correct 174 ms 10544 KB Output is correct
21 Correct 97 ms 10968 KB Output is correct
22 Correct 98 ms 10956 KB Output is correct
23 Correct 166 ms 11416 KB Output is correct
24 Correct 203 ms 11372 KB Output is correct
25 Correct 132 ms 10660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 3684 KB Output is correct
2 Correct 16 ms 3660 KB Output is correct
3 Correct 175 ms 11640 KB Output is correct
4 Correct 192 ms 12240 KB Output is correct
5 Correct 210 ms 13292 KB Output is correct
6 Correct 261 ms 13636 KB Output is correct
7 Correct 241 ms 13392 KB Output is correct
8 Correct 215 ms 13772 KB Output is correct
9 Correct 140 ms 10392 KB Output is correct
10 Correct 133 ms 10952 KB Output is correct
11 Correct 191 ms 11444 KB Output is correct
12 Correct 209 ms 12720 KB Output is correct
13 Correct 201 ms 13252 KB Output is correct
14 Correct 206 ms 13560 KB Output is correct
15 Correct 202 ms 13576 KB Output is correct
16 Correct 207 ms 11568 KB Output is correct
17 Correct 119 ms 11380 KB Output is correct
18 Correct 124 ms 11648 KB Output is correct
19 Correct 111 ms 11476 KB Output is correct
20 Correct 109 ms 11592 KB Output is correct
21 Correct 212 ms 13344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 3672 KB Output is correct
2 Correct 15 ms 3712 KB Output is correct
3 Correct 149 ms 11944 KB Output is correct
4 Correct 190 ms 11936 KB Output is correct
5 Correct 214 ms 12276 KB Output is correct
6 Correct 238 ms 13568 KB Output is correct
7 Correct 126 ms 11360 KB Output is correct
8 Correct 201 ms 11884 KB Output is correct
9 Correct 167 ms 12392 KB Output is correct
10 Correct 240 ms 13544 KB Output is correct
11 Correct 201 ms 13708 KB Output is correct
12 Correct 251 ms 13524 KB Output is correct
13 Correct 181 ms 11452 KB Output is correct
14 Correct 140 ms 10912 KB Output is correct
15 Correct 144 ms 11448 KB Output is correct
16 Correct 187 ms 10920 KB Output is correct
17 Correct 162 ms 11460 KB Output is correct
18 Correct 187 ms 10920 KB Output is correct
19 Correct 202 ms 12744 KB Output is correct
20 Correct 187 ms 13124 KB Output is correct
21 Correct 214 ms 13592 KB Output is correct
22 Correct 219 ms 13644 KB Output is correct
23 Correct 206 ms 13560 KB Output is correct
24 Correct 199 ms 13728 KB Output is correct
25 Correct 200 ms 13428 KB Output is correct
26 Correct 197 ms 13436 KB Output is correct
27 Correct 126 ms 11524 KB Output is correct
28 Correct 118 ms 11420 KB Output is correct
29 Correct 116 ms 11472 KB Output is correct
30 Correct 108 ms 11204 KB Output is correct
31 Correct 112 ms 11628 KB Output is correct
32 Correct 129 ms 11548 KB Output is correct
33 Correct 159 ms 11640 KB Output is correct
34 Correct 115 ms 11532 KB Output is correct
35 Correct 152 ms 11460 KB Output is correct
36 Correct 116 ms 11384 KB Output is correct
37 Correct 119 ms 11600 KB Output is correct
38 Correct 121 ms 11252 KB Output is correct
39 Correct 194 ms 13448 KB Output is correct
40 Correct 238 ms 13408 KB Output is correct
41 Correct 182 ms 12992 KB Output is correct
42 Correct 197 ms 13552 KB Output is correct