Submission #1017065

# Submission time Handle Problem Language Result Execution time Memory
1017065 2024-07-08T20:08:42 Z Unforgettablepl Highway Tolls (IOI18_highway) C++17
51 / 100
108 ms 10728 KB
#include <bits/stdc++.h>
using namespace std;
 
#define all(x) x.begin(),x.end()
 
long long ask(const std::vector<int> &w);
void answer(int s, int t);
 
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
    vector<vector<pair<int,int>>> adj(N);
    int M = U.size();
    for(int i=0;i<U.size();i++){
        adj[U[i]].emplace_back(V[i],i);
        adj[V[i]].emplace_back(U[i],i);
    }
    auto base = ask(vector<int>(M,1));
    int pathver = 0;
    int ue = 0;
    int ve = 0;
    {
        auto check = [&](int x){
            vector<int> a(M,1);
            for(int i=0;i<x;i++)a[i]=0;
            return base==ask(a);
        };
        for(int jump = 65536;jump;jump/=2){
            if(pathver+jump>=M)continue;
            if(check(pathver+jump))pathver+=jump;
        }
        ue = U[pathver];
        ve = V[pathver];
    }
    vector<int> pedge;
    vector<int> depth;
    auto bfs = [&](int x){
        depth = vector<int>(N);
        pedge = vector<int>(N);
        queue<tuple<int,int,int,int>> q;
        q.emplace(0,-1,x,-1);
        vector<bool> visited(N);
        while(!q.empty()){
            auto [dep,par,idx,actpar] = q.front();q.pop();
            if(visited[idx])continue;
            visited[idx]=true;
            pedge[idx]=par;
            depth[idx]=dep;
            for(auto[v,i]:adj[idx])if(v!=actpar)q.emplace(dep+1,i,v,idx);
        }
    };
    auto getsol = [&](vector<bool> activeidx){
        vector<pair<int,int>> arr;
        for(int i=0;i<N;i++)if(activeidx[i])arr.emplace_back(depth[i],i);
        sort(arr.rbegin(),arr.rend());
        auto check = [&](int x){
            vector<int> wt(M,1);
            for(int i=0;i<x;i++)wt[pedge[arr[i].second]]=0;
            return base==ask(wt);
        };
        int st = 0;
        for(int jump = 65536;jump;jump/=2){
            if(st+jump>=arr.size())continue;
            if(check(st+jump))st+=jump;
        }
        return arr[st].second;
    };
    vector<int> depthu,pedgeu,depthv,pedgev;
    bfs(ue);
    swap(depth,depthu);
    swap(pedge,pedgeu);
    bfs(ve);
    swap(depth,depthv);
    swap(pedge,pedgev);
    int a,b;
    vector<bool> activeu(N),activev(N);
    for(int i=0;i<N;i++){
        if(depthu[i]<depthv[i])activeu[i]=true;
        else if(depthu[i]>depthv[i])activev[i]=true;
    }
    swap(depth,depthu);
    swap(pedge,pedgeu);
    a = getsol(activeu);
    swap(depth,depthv);
    swap(pedge,pedgev);
    b = getsol(activev);
    answer(a,b);
}

Compilation message

highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:12:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for(int i=0;i<U.size();i++){
      |                 ~^~~~~~~~~
highway.cpp: In lambda function:
highway.cpp:61:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |             if(st+jump>=arr.size())continue;
      |                ~~~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 11 ms 1368 KB Output is correct
3 Correct 96 ms 10276 KB Output is correct
4 Correct 96 ms 10380 KB Output is correct
5 Correct 91 ms 10276 KB Output is correct
6 Correct 85 ms 10184 KB Output is correct
7 Correct 92 ms 10236 KB Output is correct
8 Correct 87 ms 10304 KB Output is correct
9 Correct 82 ms 10292 KB Output is correct
10 Correct 91 ms 10332 KB Output is correct
11 Correct 92 ms 9136 KB Output is correct
12 Correct 94 ms 9648 KB Output is correct
13 Correct 92 ms 9564 KB Output is correct
14 Correct 94 ms 9676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1368 KB Output is correct
2 Correct 15 ms 2300 KB Output is correct
3 Correct 27 ms 3412 KB Output is correct
4 Correct 85 ms 9156 KB Output is correct
5 Correct 85 ms 9036 KB Output is correct
6 Correct 63 ms 9704 KB Output is correct
7 Correct 71 ms 9680 KB Output is correct
8 Correct 63 ms 9228 KB Output is correct
9 Correct 62 ms 9608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 10 ms 1492 KB Output is correct
3 Correct 61 ms 8044 KB Output is correct
4 Correct 97 ms 10176 KB Output is correct
5 Correct 84 ms 10132 KB Output is correct
6 Correct 91 ms 10168 KB Output is correct
7 Correct 74 ms 10408 KB Output is correct
8 Correct 81 ms 10156 KB Output is correct
9 Correct 93 ms 10172 KB Output is correct
10 Correct 103 ms 10556 KB Output is correct
11 Correct 93 ms 9676 KB Output is correct
12 Correct 92 ms 9732 KB Output is correct
13 Correct 96 ms 9644 KB Output is correct
14 Correct 97 ms 9112 KB Output is correct
15 Correct 90 ms 10216 KB Output is correct
16 Correct 82 ms 10540 KB Output is correct
17 Correct 108 ms 9664 KB Output is correct
18 Correct 91 ms 9628 KB Output is correct
19 Correct 81 ms 10356 KB Output is correct
20 Correct 89 ms 9684 KB Output is correct
21 Correct 78 ms 10728 KB Output is correct
22 Correct 78 ms 10436 KB Output is correct
23 Correct 89 ms 10004 KB Output is correct
24 Correct 85 ms 10220 KB Output is correct
25 Correct 96 ms 9636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 1624 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 1540 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -