Submission #715318

#TimeUsernameProblemLanguageResultExecution timeMemory
715318lamHighway Tolls (IOI18_highway)C++14
51 / 100
771 ms15360 KiB
#include "highway.h" #include <bits/stdc++.h> #define ll long long using namespace std; const int maxn = 2e5 + 10; typedef pair<int,int> ii; #define ff first #define ss second int n,m; ll dist,w1,w2,dist2; vector <ii> adj[maxn]; ii e[maxn]; int d[maxn]; ii par[maxn]; int side[maxn]; int dnc(int lx, int rx, vector<int32_t> &dau) { if (lx==rx) return lx; int mid=(lx+rx)/2; for (int i=lx; i<=mid; i++) dau[i] = 0; ll temp = ask(dau); // for (int i:dau) cerr<<i<<' '; cerr<<" = "<<temp<<'\n'; bool check = temp < dist2; for (int i=lx; i<=mid; i++) dau[i] = 1; if (check) return dnc(lx,mid,dau); else return dnc(mid+1,rx,dau); } int trace(int lx, int rx, vector <int>&nodes, vector <int32_t> &dau) { if (lx==rx) return nodes[lx]; int mid=(lx+rx)/2; for (int i=lx; i<=mid; i++) dau[par[nodes[i]].ss] = 1; bool check = (ask(dau) > dist); for (int i=lx; i<=mid; i++) dau[par[nodes[i]].ss] = 0; if (check) return trace(lx,mid,nodes,dau); else return trace(mid+1,rx,nodes,dau); } void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) { m=U.size(); n=N; w1=A; w2=B; fill_n(side,n,0); for (int i=0; i<n; i++) par[i]={-1,-1}; // cerr<<":>"<<endl; for (int i=0; i<n; i++) adj[i].clear(); for (int i=0; i<m; i++) e[i].ff=U[i], e[i].ss = V[i], adj[e[i].ff].push_back({e[i].ss,i}), adj[e[i].ss].push_back({e[i].ff,i}); vector <int32_t> dau(m,0); dist=ask(dau); for (int i=0; i<m; i++) dau[i]=1; dist2=ask(dau); cerr<<dist<<endl; int idx = dnc(0,m-1,dau); for (int i=0; i<m; i++) dau[i]=0; cerr<<idx<<endl; fill_n(d,n,-1); int u=e[idx].ff; int v=e[idx].ss; d[u]=d[v]=0; par[u] = par[v] = {-1,-1}; dau[idx] = -1; queue<int> q; q.push(u); q.push(v); side[u] = 1; side[v] = 2; while (!q.empty()) { int u=q.front(); q.pop(); for (ii i:adj[u]) { int v=i.ff; int id = i.ss; if (d[v]==-1) { par[v] = {u,id}; side[v] = side[u]; d[v] = d[u]+1; cerr<<u<<" - "<<v<<endl; dau[id] = side[v]; q.push(v); } } } vector <int32_t> tmp(m,0); for (int i=0; i<m; i++) if (dau[i]==0) tmp[i]=1; for (int i=0; i<m; i++) if (dau[i]==1) tmp[i]=1; for (int i:tmp) cerr<<i<<' '; cerr<<endl;cerr<<" = "<<ask(tmp)<<' '<<dist<<endl; ll du = 1LL*(ask(tmp)-dist)/(w2-w1); for (int i=0; i<m; i++) if (dau[i]==1) tmp[i]=0; for (int i=0; i<m; i++) if (dau[i]==2) tmp[i]=1; ll dv = 1LL*(ask(tmp)-dist)/(w2-w1); for (int i=0; i<m; i++) if (dau[i]==2) tmp[i]=0; cerr<<u<<' '<<du<<" & "<<v<<' '<<dv<<endl; vector <int> nodes; for (int i=0; i<n; i++) if (side[i]==1&&d[i]==du) nodes.push_back(i); // for (int i=0; i<n; i++) cerr<<d[i]<<','<<side[i]<<' '; cerr<<endl; int s,t; // cerr<<nodes.size()<<endl; if (du==0) s=u; else s=trace(0,nodes.size()-1,nodes,tmp); nodes.clear(); for (int i=0; i<n; i++) if (side[i]==2&&d[i]==dv) nodes.push_back(i); if (dv==0) t=v; else t=trace(0,nodes.size()-1,nodes,tmp); answer(s,t); }

Compilation message (stderr)

highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:80:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   80 |   for (int i:tmp) cerr<<i<<' '; cerr<<endl;cerr<<" = "<<ask(tmp)<<' '<<dist<<endl;
      |   ^~~
highway.cpp:80:33: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   80 |   for (int i:tmp) cerr<<i<<' '; cerr<<endl;cerr<<" = "<<ask(tmp)<<' '<<dist<<endl;
      |                                 ^~~~
#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...