답안 #115522

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
115522 2019-06-08T04:05:30 Z onjo0127 통행료 (IOI18_highway) C++11
11 / 100
424 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 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;
    }
    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:22:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int m = l+r >> 1;
                 ~^~
highway.cpp:38: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:55:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int m = l+r >> 1;
                 ~^~
highway.cpp:71: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]);
                                         ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2424 KB Output is correct
2 Correct 4 ms 2424 KB Output is correct
3 Correct 4 ms 2420 KB Output is correct
4 Correct 4 ms 2448 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 2468 KB Output is correct
9 Correct 4 ms 2424 KB Output is correct
10 Correct 4 ms 2440 KB Output is correct
11 Correct 4 ms 2424 KB Output is correct
12 Correct 4 ms 2440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2588 KB Output is correct
2 Correct 21 ms 3176 KB Output is correct
3 Correct 217 ms 9892 KB Output is correct
4 Correct 190 ms 9828 KB Output is correct
5 Incorrect 208 ms 10116 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 3652 KB Output is correct
2 Correct 43 ms 4780 KB Output is correct
3 Correct 61 ms 6196 KB Output is correct
4 Correct 163 ms 13656 KB Output is correct
5 Correct 177 ms 13480 KB Output is correct
6 Correct 167 ms 13488 KB Output is correct
7 Correct 144 ms 13824 KB Output is correct
8 Correct 156 ms 13392 KB Output is correct
9 Correct 144 ms 13740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2552 KB Output is correct
2 Correct 20 ms 3272 KB Output is correct
3 Correct 144 ms 8228 KB Output is correct
4 Correct 223 ms 9756 KB Output is correct
5 Correct 180 ms 9752 KB Output is correct
6 Correct 189 ms 9844 KB Output is correct
7 Correct 219 ms 9764 KB Output is correct
8 Correct 220 ms 9824 KB Output is correct
9 Correct 219 ms 9860 KB Output is correct
10 Incorrect 217 ms 10084 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 424 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 382 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -