Submission #99351

#TimeUsernameProblemLanguageResultExecution timeMemory
99351TadijaSebezHighway Tolls (IOI18_highway)C++11
100 / 100
503 ms16496 KiB
#include "highway.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mp make_pair const int N=100050; ll dist; vector<pair<int,int>> E[N]; vector<int> I[N]; int d[N],f[N]; void AddEdge(int u, int v, int id){ E[u].pb(mp(v,id));E[v].pb(mp(u,id));} void find_pair(int n, vector<int> U, vector<int> V, int A, int B) { int m=U.size(); int top=m-1,bot=0,mid,ans; vector<int> use(m,0); dist=ask(use); while(top>=bot) { mid=top+bot>>1; use.clear();use.resize(m); for(int i=0;i<=mid;i++) use[i]=1; if(ask(use)==dist) bot=mid+1; else ans=mid,top=mid-1; } for(int i=ans+1;i<m;i++) AddEdge(U[i],V[i],i); queue<int> q;q.push(U[ans]);q.push(V[ans]); d[U[ans]]=d[V[ans]]=1; f[U[ans]]=1;f[V[ans]]=2; vector<int> L,R; while(q.size()) { int x=q.front();q.pop(); if(f[x]&1) L.pb(x); if(f[x]&2) R.pb(x); for(auto e:E[x]) { int y=e.first; int id=e.second; if(!d[y]) d[y]=d[x]+1,f[y]=f[x],q.push(y); if(d[y]==d[x]+1) { if(f[y]==f[x]) I[y].pb(id); else f[y]|=f[x]; } } } int bad=-1; auto Solve=[&](vector<int> vs) { top=(int)vs.size()-1;bot=0; int ret=vs[0]; vector<int> use; while(top>=bot) { mid=top+bot>>1; use.clear();use.resize(m); for(int i=0;i<ans;i++) use[i]=1; for(int i=mid;i<vs.size();i++) if(vs[i]!=bad) for(int id:I[vs[i]]) use[id]=1; if(ask(use)==dist) top=mid-1; else ret=vs[mid],bot=mid+1; } bad=ret; return ret; }; return answer(Solve(L),Solve(R)); }

Compilation message (stderr)

highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:21:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   mid=top+bot>>1;
       ~~~^~~~
highway.cpp: In lambda function:
highway.cpp:57:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    mid=top+bot>>1;
        ~~~^~~~
highway.cpp:60:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int i=mid;i<vs.size();i++) if(vs[i]!=bad) for(int id:I[vs[i]]) use[id]=1;
                  ~^~~~~~~~~~
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:28:27: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
  queue<int> q;q.push(U[ans]);q.push(V[ans]);
                           ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...