Submission #422165

# Submission time Handle Problem Language Result Execution time Memory
422165 2021-06-09T19:51:16 Z Peti Highway Tolls (IOI18_highway) C++14
100 / 100
328 ms 11892 KB
#include <bits/stdc++.h>
#include "highway.h"

using namespace std;

const int maxn = (int)1e5;

vector<vector<pair<int, int>>> g;
vector<int> ose, el, gTav;
long long tav, A, B;
int N, M;

int el_keres(){
    vector<int> query(M, 0);
    int l = 0, r = M;
    while(l+1 < r){
        vector<int> query2 = query;
        int m = (l+r)/2;
        for(int i = l; i < m; i++)
            query2[i] = 1;
        long long ans = ask(query2);
        if(ans != tav*A){
            r = m;
        } else{
            for(int i = l; i < m; i++)
                query[i] = 1;
            l = m;
        }
    }
    return l;
}

int sor[maxn];
void bejar(int x, int y, int elInd){
    vector<bool> volt(N, false);
    sor[0] = x;
    sor[1] = y;
    volt[x] = volt[y] = true;
    ose[x] = x;
    ose[y] = y;
    el[x] = el[y] = elInd;
    gTav[x] = gTav[y] = 0;
    int ind = 0, veg = 2;
    while(ind < veg){
        int akt = sor[ind];
        for(auto e : g[akt]){
            if(!volt[e.first]){
                volt[e.first] = true;
                el[e.first] = e.second;
                ose[e.first] = ose[akt];
                gTav[e.first] = gTav[akt]+1;
                sor[veg++] = e.first;
            }
        }
        ind++;
    }
}

int get(int os){
    vector<int> v;
    for(int i = 0; i < N; i++)
        if(ose[i] == os)
            v.push_back(i);
    sort(v.begin(), v.end(), [](int a, int b){return gTav[a] < gTav[b]; });
    int l = -1, r = (int)v.size()-1;
    while(l+1 < r){
        int m = (l+r+1)/2;
        vector<int> query(M, 1);
        for(int i = 0; i < N; i++)
            if(ose[i] != os)
                query[el[i]] = 0;
        for(int i = 0; i <= m; i++)
            query[el[v[i]]] = 0;
        long long ans = ask(query);
        if(ans == tav*A)
            r = m;
        else
            l = m;
    }
    return v[r];
}

void find_pair(int n, std::vector<int> U, std::vector<int> V, int CA, int CB) {
    //cout<<"called"<<endl;
    N = n;
    M = (int)U.size();
    A = CA;
    B = CB;
    g.resize(N);
    el.resize(N);
    ose.resize(N);
    gTav.resize(N);
    for(int i = 0; i < M; i++){
        g[U[i]].emplace_back(V[i], i);
        g[V[i]].emplace_back(U[i], i);
    }

    vector<int> query(M, 0);
    tav = ask(query)/A;

    //cout<<"tav: "<<tav<<endl;

    int ind = el_keres();
    //cout<<"keres kesz | ind: "<<ind<<endl;
    bejar(U[ind], V[ind], ind);

    //cout<<"bejar kesz"<<endl;
    answer(get(U[ind]), get(V[ind]));
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 200 KB Output is correct
6 Correct 1 ms 200 KB Output is correct
7 Correct 1 ms 200 KB Output is correct
8 Correct 1 ms 200 KB Output is correct
9 Correct 1 ms 200 KB Output is correct
10 Correct 1 ms 200 KB Output is correct
11 Correct 1 ms 300 KB Output is correct
12 Correct 1 ms 200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 328 KB Output is correct
2 Correct 15 ms 1352 KB Output is correct
3 Correct 243 ms 9872 KB Output is correct
4 Correct 195 ms 9812 KB Output is correct
5 Correct 183 ms 9844 KB Output is correct
6 Correct 173 ms 9820 KB Output is correct
7 Correct 146 ms 9820 KB Output is correct
8 Correct 176 ms 9908 KB Output is correct
9 Correct 177 ms 9836 KB Output is correct
10 Correct 150 ms 9816 KB Output is correct
11 Correct 179 ms 9216 KB Output is correct
12 Correct 196 ms 9192 KB Output is correct
13 Correct 171 ms 9272 KB Output is correct
14 Correct 197 ms 9244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 1300 KB Output is correct
2 Correct 28 ms 2204 KB Output is correct
3 Correct 55 ms 3224 KB Output is correct
4 Correct 163 ms 9236 KB Output is correct
5 Correct 111 ms 9236 KB Output is correct
6 Correct 157 ms 9192 KB Output is correct
7 Correct 118 ms 9280 KB Output is correct
8 Correct 160 ms 9432 KB Output is correct
9 Correct 145 ms 9188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 16 ms 1272 KB Output is correct
3 Correct 132 ms 7780 KB Output is correct
4 Correct 172 ms 9828 KB Output is correct
5 Correct 178 ms 9832 KB Output is correct
6 Correct 138 ms 9820 KB Output is correct
7 Correct 135 ms 9824 KB Output is correct
8 Correct 148 ms 9820 KB Output is correct
9 Correct 179 ms 9816 KB Output is correct
10 Correct 191 ms 9824 KB Output is correct
11 Correct 182 ms 9268 KB Output is correct
12 Correct 210 ms 9300 KB Output is correct
13 Correct 214 ms 9292 KB Output is correct
14 Correct 174 ms 9364 KB Output is correct
15 Correct 176 ms 9920 KB Output is correct
16 Correct 169 ms 9824 KB Output is correct
17 Correct 197 ms 9320 KB Output is correct
18 Correct 193 ms 9320 KB Output is correct
19 Correct 135 ms 9824 KB Output is correct
20 Correct 190 ms 9260 KB Output is correct
21 Correct 168 ms 9980 KB Output is correct
22 Correct 156 ms 9976 KB Output is correct
23 Correct 143 ms 9896 KB Output is correct
24 Correct 201 ms 9824 KB Output is correct
25 Correct 226 ms 9336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 1360 KB Output is correct
2 Correct 17 ms 1416 KB Output is correct
3 Correct 181 ms 10200 KB Output is correct
4 Correct 188 ms 10860 KB Output is correct
5 Correct 220 ms 11484 KB Output is correct
6 Correct 233 ms 11716 KB Output is correct
7 Correct 231 ms 11720 KB Output is correct
8 Correct 281 ms 11704 KB Output is correct
9 Correct 131 ms 7796 KB Output is correct
10 Correct 163 ms 8148 KB Output is correct
11 Correct 210 ms 8964 KB Output is correct
12 Correct 328 ms 10804 KB Output is correct
13 Correct 239 ms 11236 KB Output is correct
14 Correct 285 ms 11816 KB Output is correct
15 Correct 259 ms 11644 KB Output is correct
16 Correct 197 ms 9152 KB Output is correct
17 Correct 137 ms 10040 KB Output is correct
18 Correct 187 ms 10244 KB Output is correct
19 Correct 176 ms 10152 KB Output is correct
20 Correct 166 ms 10248 KB Output is correct
21 Correct 208 ms 11584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 1392 KB Output is correct
2 Correct 24 ms 1380 KB Output is correct
3 Correct 165 ms 10260 KB Output is correct
4 Correct 257 ms 10400 KB Output is correct
5 Correct 228 ms 10676 KB Output is correct
6 Correct 244 ms 11736 KB Output is correct
7 Correct 180 ms 10208 KB Output is correct
8 Correct 229 ms 10340 KB Output is correct
9 Correct 189 ms 10700 KB Output is correct
10 Correct 245 ms 11704 KB Output is correct
11 Correct 230 ms 11708 KB Output is correct
12 Correct 235 ms 11720 KB Output is correct
13 Correct 220 ms 8952 KB Output is correct
14 Correct 153 ms 8172 KB Output is correct
15 Correct 154 ms 8948 KB Output is correct
16 Correct 215 ms 8164 KB Output is correct
17 Correct 161 ms 8968 KB Output is correct
18 Correct 210 ms 8172 KB Output is correct
19 Correct 276 ms 10820 KB Output is correct
20 Correct 271 ms 11152 KB Output is correct
21 Correct 276 ms 11748 KB Output is correct
22 Correct 316 ms 11708 KB Output is correct
23 Correct 289 ms 11712 KB Output is correct
24 Correct 269 ms 11728 KB Output is correct
25 Correct 270 ms 11756 KB Output is correct
26 Correct 218 ms 11796 KB Output is correct
27 Correct 181 ms 10176 KB Output is correct
28 Correct 136 ms 10088 KB Output is correct
29 Correct 145 ms 10336 KB Output is correct
30 Correct 183 ms 10204 KB Output is correct
31 Correct 141 ms 10216 KB Output is correct
32 Correct 129 ms 10096 KB Output is correct
33 Correct 145 ms 10376 KB Output is correct
34 Correct 176 ms 10160 KB Output is correct
35 Correct 126 ms 10212 KB Output is correct
36 Correct 182 ms 10032 KB Output is correct
37 Correct 155 ms 10300 KB Output is correct
38 Correct 183 ms 10216 KB Output is correct
39 Correct 251 ms 11592 KB Output is correct
40 Correct 278 ms 11852 KB Output is correct
41 Correct 294 ms 11704 KB Output is correct
42 Correct 225 ms 11892 KB Output is correct