Submission #1017053

# Submission time Handle Problem Language Result Execution time Memory
1017053 2024-07-08T19:19:11 Z Unforgettablepl Highway Tolls (IOI18_highway) C++17
90 / 100
153 ms 12744 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);
    vector<int> baseask;
    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));
    int pathver = 0;
    {
        auto check = [&](int x){
            vector<int> a(M);
            for(int i=0;i<x;i++)a[i]=1;
            return base==ask(a);
        };
        for(int jump = 65536;jump;jump/=2){
            if(pathver+jump>=M)continue;
            if(check(pathver+jump))pathver+=jump;
        }
        pathver = U[pathver];
    }
    vector<int> pedge(N);
    vector<int> depth(N);
    auto bfs = [&](int x){
        baseask = vector<int>(M);
        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]){
                baseask[par]=1;
                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);
        }
    };
    bfs(pathver);
    auto basedep = base/((long long)A);
    // Calculate st
    vector<pair<int,int>> arr;
    for(int i=0;i<N;i++)arr.emplace_back(depth[i],i);
    sort(arr.rbegin(),arr.rend());
    auto check = [&](int x){
        vector<int> wt = baseask;
        for(int i=0;i<x;i++)wt[pedge[arr[i].second]]=1;
        return base==ask(wt);
    };
    int st = 0;
    for(int jump = 65536;jump;jump/=2){
        if(st+jump>=N)continue;
        if(check(st+jump))st+=jump;
    }
    st = arr[st].second;
    bfs(st);
    vector<int> sus;
    for(int i=0;i<N;i++)if(depth[i]==basedep)sus.emplace_back(i);
    while(sus.size()>1){
        int mid = (sus.size())/2;
        vector<int> left,right;
        for(int i=0;i<mid;i++)left.emplace_back(sus[i]);
        for(int i=mid;i<sus.size();i++)right.emplace_back(sus[i]);
        vector<int> w = baseask;
        for(int&i:left)w[pedge[i]]=1;
        auto ans = ask(w);
        if(ans!=base)sus=left;
        else sus=right;
    }
    answer(st, sus[0]);
}

Compilation message

highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:13:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for(int i=0;i<U.size();i++){
      |                 ~^~~~~~~~~
highway.cpp:74:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |         for(int i=mid;i<sus.size();i++)right.emplace_back(sus[i]);
      |                       ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 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 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 10 ms 1524 KB Output is correct
3 Correct 106 ms 9984 KB Output is correct
4 Correct 90 ms 9964 KB Output is correct
5 Correct 92 ms 9972 KB Output is correct
6 Correct 85 ms 9960 KB Output is correct
7 Correct 88 ms 9940 KB Output is correct
8 Correct 101 ms 10208 KB Output is correct
9 Correct 81 ms 9940 KB Output is correct
10 Correct 95 ms 9940 KB Output is correct
11 Correct 88 ms 9176 KB Output is correct
12 Correct 88 ms 9196 KB Output is correct
13 Correct 86 ms 9176 KB Output is correct
14 Correct 88 ms 9164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1380 KB Output is correct
2 Correct 15 ms 2392 KB Output is correct
3 Correct 19 ms 3220 KB Output is correct
4 Correct 67 ms 9312 KB Output is correct
5 Correct 73 ms 9368 KB Output is correct
6 Correct 85 ms 9148 KB Output is correct
7 Correct 64 ms 9344 KB Output is correct
8 Correct 67 ms 9372 KB Output is correct
9 Correct 67 ms 9200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 10 ms 1568 KB Output is correct
3 Correct 76 ms 7768 KB Output is correct
4 Correct 85 ms 9944 KB Output is correct
5 Correct 92 ms 10156 KB Output is correct
6 Correct 86 ms 9940 KB Output is correct
7 Correct 75 ms 9980 KB Output is correct
8 Correct 101 ms 9940 KB Output is correct
9 Correct 90 ms 10200 KB Output is correct
10 Correct 96 ms 9988 KB Output is correct
11 Correct 90 ms 9192 KB Output is correct
12 Correct 82 ms 9212 KB Output is correct
13 Correct 92 ms 9176 KB Output is correct
14 Correct 87 ms 9176 KB Output is correct
15 Correct 76 ms 9932 KB Output is correct
16 Correct 88 ms 9972 KB Output is correct
17 Correct 104 ms 9168 KB Output is correct
18 Correct 85 ms 9200 KB Output is correct
19 Correct 80 ms 9944 KB Output is correct
20 Correct 76 ms 9172 KB Output is correct
21 Correct 90 ms 10784 KB Output is correct
22 Correct 83 ms 10856 KB Output is correct
23 Correct 83 ms 10352 KB Output is correct
24 Correct 83 ms 10332 KB Output is correct
25 Correct 88 ms 9264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 1368 KB Output is correct
2 Correct 12 ms 1620 KB Output is correct
3 Correct 95 ms 10328 KB Output is correct
4 Correct 142 ms 11224 KB Output is correct
5 Correct 124 ms 12744 KB Output is correct
6 Correct 127 ms 12504 KB Output is correct
7 Correct 131 ms 12676 KB Output is correct
8 Correct 138 ms 12524 KB Output is correct
9 Correct 95 ms 10208 KB Output is correct
10 Correct 100 ms 10664 KB Output is correct
11 Correct 113 ms 10688 KB Output is correct
12 Correct 139 ms 11388 KB Output is correct
13 Correct 139 ms 11792 KB Output is correct
14 Correct 136 ms 12520 KB Output is correct
15 Correct 130 ms 12556 KB Output is correct
16 Correct 111 ms 10572 KB Output is correct
17 Correct 104 ms 11080 KB Output is correct
18 Correct 82 ms 11052 KB Output is correct
19 Correct 101 ms 11000 KB Output is correct
20 Correct 88 ms 11088 KB Output is correct
21 Correct 127 ms 11832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 1368 KB Output is correct
2 Correct 11 ms 1544 KB Output is correct
3 Correct 101 ms 10872 KB Output is correct
4 Correct 110 ms 10932 KB Output is correct
5 Correct 106 ms 10888 KB Output is correct
6 Correct 134 ms 12028 KB Output is correct
7 Correct 108 ms 10416 KB Output is correct
8 Correct 98 ms 10648 KB Output is correct
9 Correct 103 ms 11180 KB Output is correct
10 Correct 132 ms 12528 KB Output is correct
11 Correct 134 ms 12536 KB Output is correct
12 Correct 128 ms 12168 KB Output is correct
13 Correct 101 ms 10692 KB Output is correct
14 Correct 99 ms 10636 KB Output is correct
15 Correct 103 ms 10740 KB Output is correct
16 Correct 90 ms 10796 KB Output is correct
17 Correct 111 ms 10860 KB Output is correct
18 Correct 112 ms 10812 KB Output is correct
19 Correct 126 ms 11632 KB Output is correct
20 Correct 128 ms 12108 KB Output is correct
21 Correct 128 ms 12004 KB Output is correct
22 Correct 134 ms 11976 KB Output is correct
23 Correct 136 ms 12428 KB Output is correct
24 Correct 153 ms 12456 KB Output is correct
25 Correct 142 ms 12100 KB Output is correct
26 Correct 151 ms 12196 KB Output is correct
27 Partially correct 81 ms 11032 KB Output is partially correct
28 Partially correct 88 ms 10908 KB Output is partially correct
29 Partially correct 104 ms 11184 KB Output is partially correct
30 Partially correct 92 ms 11044 KB Output is partially correct
31 Partially correct 91 ms 10984 KB Output is partially correct
32 Partially correct 85 ms 10956 KB Output is partially correct
33 Partially correct 94 ms 11356 KB Output is partially correct
34 Partially correct 89 ms 11272 KB Output is partially correct
35 Correct 85 ms 10984 KB Output is correct
36 Partially correct 86 ms 10952 KB Output is partially correct
37 Partially correct 86 ms 11116 KB Output is partially correct
38 Partially correct 90 ms 11416 KB Output is partially correct
39 Correct 143 ms 11536 KB Output is correct
40 Correct 128 ms 11656 KB Output is correct
41 Correct 137 ms 11580 KB Output is correct
42 Correct 120 ms 11836 KB Output is correct