Submission #115523

# Submission time Handle Problem Language Result Execution time Memory
115523 2019-06-08T04:15:59 Z onjo0127 Highway Tolls (IOI18_highway) C++11
51 / 100
431 ms 262148 KB
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;

vector<pii> adj[90009];
int dep[90009], pid[90009];
long long gi;

void go(int x, int p, int d, int id) {
    dep[x] = d; pid[x] = id;
    for(auto& it: adj[x]) if(it.first != p) go(it.first, x, d+1, it.second);
}

void solveRoot(int N, vector<int> U, vector<int> V, int A, int B, int root) {
    int M = U.size();
    go(root, root, 0, -1);
    vector<int> W(M, 0);
    int r = ask(W) / A;
    vector<int> P;
    for(int i=0; i<N; i++) if(dep[i] == r) P.push_back(i);
    while((int)P.size() > 1) {
        vector<int> NP;
        W = vector<int>(M, 0);
        for(int i=0; i<(int)P.size()/2; i++) W[pid[P[i]]] = 1;
        long long t = ask(W);
        if(t != gi) for(int i=0; i<(int)P.size()/2; i++) NP.push_back(P[i]);
        else for(int i=(int)P.size()/2; i<P.size(); i++) NP.push_back(P[i]);
        P = NP;
    }
    answer(root, P[0]);
}

void find_pair(int N, vector<int> U, vector<int> V, int A, int B) {
    int M = U.size();
    for(int i=0; i<M; i++) {
        adj[U[i]].push_back({V[i], i});
        adj[V[i]].push_back({U[i], i});
    }
    go(0, 0, 0, -1);
    vector<int> W(M, 0); gi = ask(W);
    int l = 1, r = N-1;
    while(l <= r) {
        W = vector<int>(M, 0);
        int m = l+r >> 1;
        for(int i=0; i<N; i++) {
            if(dep[i] >= m) W[pid[i]] = 1;
        }
        long long t = ask(W);
        if(t != gi) l = m+1;
        else r = m-1;
    }
    vector<int> P;
    for(int i=0; i<N; i++) if(dep[i] == r) P.push_back(i);
    while((int)P.size() > 1) {
        vector<int> NP;
        W = vector<int>(M, 0);
        for(int i=0; i<(int)P.size()/2; i++) W[pid[P[i]]] = 1;
        long long t = ask(W);
        if(t != gi) for(int i=0; i<(int)P.size()/2; i++) NP.push_back(P[i]);
        else for(int i=(int)P.size()/2; i<P.size(); i++) NP.push_back(P[i]);
        P = NP;
    }
    solveRoot(N, U, V, A, B, P[0]);
}

Compilation message

highway.cpp: In function 'void solveRoot(int, std::vector<int>, std::vector<int>, int, int, int)':
highway.cpp:28:42: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         else for(int i=(int)P.size()/2; i<P.size(); i++) NP.push_back(P[i]);
                                         ~^~~~~~~~~
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:45:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int m = l+r >> 1;
                 ~^~
highway.cpp:61:42: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         else for(int i=(int)P.size()/2; i<P.size(); i++) NP.push_back(P[i]);
                                         ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2344 KB Output is correct
2 Correct 4 ms 2424 KB Output is correct
3 Correct 4 ms 2444 KB Output is correct
4 Correct 5 ms 2424 KB Output is correct
5 Correct 4 ms 2424 KB Output is correct
6 Correct 4 ms 2424 KB Output is correct
7 Correct 4 ms 2424 KB Output is correct
8 Correct 4 ms 2428 KB Output is correct
9 Correct 4 ms 2424 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 2424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2508 KB Output is correct
2 Correct 21 ms 3280 KB Output is correct
3 Correct 195 ms 9864 KB Output is correct
4 Correct 205 ms 9832 KB Output is correct
5 Correct 194 ms 9880 KB Output is correct
6 Correct 202 ms 9744 KB Output is correct
7 Correct 177 ms 9932 KB Output is correct
8 Correct 194 ms 9820 KB Output is correct
9 Correct 252 ms 9896 KB Output is correct
10 Correct 192 ms 9824 KB Output is correct
11 Correct 226 ms 10132 KB Output is correct
12 Correct 212 ms 10676 KB Output is correct
13 Correct 219 ms 10176 KB Output is correct
14 Correct 214 ms 10244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 3624 KB Output is correct
2 Correct 36 ms 4764 KB Output is correct
3 Correct 45 ms 6136 KB Output is correct
4 Correct 174 ms 13340 KB Output is correct
5 Correct 168 ms 13368 KB Output is correct
6 Correct 162 ms 12984 KB Output is correct
7 Correct 165 ms 13624 KB Output is correct
8 Correct 168 ms 12972 KB Output is correct
9 Correct 148 ms 13704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2592 KB Output is correct
2 Correct 19 ms 3216 KB Output is correct
3 Correct 150 ms 8112 KB Output is correct
4 Correct 215 ms 9772 KB Output is correct
5 Correct 176 ms 9720 KB Output is correct
6 Correct 208 ms 9752 KB Output is correct
7 Correct 204 ms 9696 KB Output is correct
8 Correct 186 ms 9784 KB Output is correct
9 Correct 192 ms 9832 KB Output is correct
10 Correct 210 ms 9796 KB Output is correct
11 Correct 198 ms 9972 KB Output is correct
12 Correct 195 ms 10256 KB Output is correct
13 Correct 204 ms 10288 KB Output is correct
14 Correct 236 ms 10544 KB Output is correct
15 Correct 166 ms 9764 KB Output is correct
16 Correct 168 ms 9368 KB Output is correct
17 Correct 148 ms 10440 KB Output is correct
18 Correct 191 ms 10448 KB Output is correct
19 Correct 191 ms 9708 KB Output is correct
20 Correct 212 ms 10892 KB Output is correct
21 Correct 272 ms 10932 KB Output is correct
22 Correct 220 ms 10968 KB Output is correct
23 Correct 184 ms 10508 KB Output is correct
24 Correct 204 ms 10836 KB Output is correct
25 Correct 186 ms 13088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 431 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 366 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -