Submission #1055124

#TimeUsernameProblemLanguageResultExecution timeMemory
1055124Ahmed57Highway Tolls (IOI18_highway)C++17
Compilation error
0 ms0 KiB
#include "bits/stdc++.h" #include "highway.h" using namespace std; #define int long long pair<int,int> p[100001]; int dep[100001]; vector<pair<int,int>> adj[100001]; void dfs(int i,int pr,int id){ dep[i] = dep[pr]+1; p[i] = {pr,id}; for(auto j:adj[i]){ if(j.first==pr)continue; dfs(j.first,i,j.second); } } void find_pair(int32_t N, vector<int32_t> U, vector<int32_t> V, int32_t A, int32_t B){ int m = U.size(); vector<int> as(m,0); vector<int> as2(m,1); int len = ask(as); int len2 = ask(as2); for(int i = 0;i<U.size();i++){ adj[U[i]].push_back({V[i],i}); adj[V[i]].push_back({U[i],i}); } dfs(0,0,-1); vector<pair<int,int>> v; for(int i = 0;i<N;i++){ v.push_back({dep[i],i}); } sort(v.begin(),v.end()); reverse(v.begin(),v.end()); int l = 0 , r = v.size()-2 , ans = 0; while(l<=r){ int mid = (l+r)/2; vector<int> as(m,0); for(int i = 0;i<=mid;i++){ as[p[v[i].second].second] = 1; } if(ask(as)!=len){ ans = mid; r = mid-1; }else l = mid+1; } int a = v[ans].second; if(len/A==len2/B){ int x = len/A; int b = a; while(x--){ b = p[b].first; } answer(a,b); return ; } l = 2 , r = dep[a] ;int ans2 = 0; while(l<=r){ int mid = (l+r)/2; vector<int> as(m,0); for(int i = 0;i<N;i++){ if(dep[i]>=mid){ as[p[i].second] =1 ; } } int na = ask(as); if(na!=(dep[a]-mid+1)*B){ ans2 = mid; l = mid+1; }else r = mid-1; } vector<int> lol; l = -1; for(int i = 0;i<v.size();i++){ if(v[i].first==ans2&&l==-1)l = i; if(v[i].first==ans2)r = i; } int ans3 = 0; while(l<=r){ int mid = (l+r)/2; vector<int> as(m,0); for(int i = 0;i<=mid;i++){ as[p[v[i].second].second] = 1; } if(ask(as)==(dep[a]-ans2+1)*B+B){ ans3 = mid; r = mid-1; }else l = mid+1; } int b = v[ans3].second; answer(a,b); }

Compilation message (stderr)

highway.cpp: In function 'void find_pair(int32_t, std::vector<int>, std::vector<int>, int32_t, int32_t)':
highway.cpp:21:19: error: invalid initialization of reference of type 'const std::vector<int>&' from expression of type 'std::vector<long long int>'
   21 |     int len = ask(as);
      |                   ^~
In file included from highway.cpp:2:
highway.h:7:39: note: in passing argument 1 of 'long long int ask(const std::vector<int>&)'
    7 | long long ask(const std::vector<int> &w);
      |               ~~~~~~~~~~~~~~~~~~~~~~~~^
highway.cpp:22:20: error: invalid initialization of reference of type 'const std::vector<int>&' from expression of type 'std::vector<long long int>'
   22 |     int len2 = ask(as2);
      |                    ^~~
In file included from highway.cpp:2:
highway.h:7:39: note: in passing argument 1 of 'long long int ask(const std::vector<int>&)'
    7 | long long ask(const std::vector<int> &w);
      |               ~~~~~~~~~~~~~~~~~~~~~~~~^
highway.cpp:23:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for(int i = 0;i<U.size();i++){
      |                   ~^~~~~~~~~
highway.cpp:41:16: error: invalid initialization of reference of type 'const std::vector<int>&' from expression of type 'std::vector<long long int>'
   41 |         if(ask(as)!=len){
      |                ^~
In file included from highway.cpp:2:
highway.h:7:39: note: in passing argument 1 of 'long long int ask(const std::vector<int>&)'
    7 | long long ask(const std::vector<int> &w);
      |               ~~~~~~~~~~~~~~~~~~~~~~~~^
highway.cpp:65:22: error: invalid initialization of reference of type 'const std::vector<int>&' from expression of type 'std::vector<long long int>'
   65 |         int na = ask(as);
      |                      ^~
In file included from highway.cpp:2:
highway.h:7:39: note: in passing argument 1 of 'long long int ask(const std::vector<int>&)'
    7 | long long ask(const std::vector<int> &w);
      |               ~~~~~~~~~~~~~~~~~~~~~~~~^
highway.cpp:73:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |     for(int i = 0;i<v.size();i++){
      |                   ~^~~~~~~~~
highway.cpp:84:16: error: invalid initialization of reference of type 'const std::vector<int>&' from expression of type 'std::vector<long long int>'
   84 |         if(ask(as)==(dep[a]-ans2+1)*B+B){
      |                ^~
In file included from highway.cpp:2:
highway.h:7:39: note: in passing argument 1 of 'long long int ask(const std::vector<int>&)'
    7 | long long ask(const std::vector<int> &w);
      |               ~~~~~~~~~~~~~~~~~~~~~~~~^