Submission #139475

#TimeUsernameProblemLanguageResultExecution timeMemory
139475CaroLindaHighway Tolls (IOI18_highway)C++14
12 / 100
210 ms8948 KiB
#include "highway.h" #include <bits/stdc++.h> #define debug printf #define lp(i,a,b) for(int i=a;i<b;i++) #define pii pair<int,int> #define ll long long #define ff first #define ss second #define pb push_back #define mk make_pair const int MAXN = 9e4+ 10 ; const int MAXM = 13e4+10 ; using namespace std ; struct Edge { int j , id ; Edge(int j = 0 , int id = 0) : j(j) , id(id) {} } ; int n , m , S , T ; vector<int> toAsk , possible ; ll oldVal , newVal , rad ; bool marc[MAXN] ; vector<Edge> adj[MAXN] ; int edgePai[MAXN] ; // -------------------------------- void dfs(int x , ll depth ) { if( depth == rad ) possible.pb(x) ; marc[x] = true ; for(Edge e : adj[x]) if( !marc[e.j] ) { edgePai[e.j] = e.id ; dfs(e.j,depth+1) ; } } void find_pair(int N, vector<int> U, vector<int> V, int A, int B) { m = U.size(); n = N ; lp(i,0,m) { int a = U[i] , b = V[i] ; adj[a].pb(Edge(b,i)) ; adj[b].pb(Edge(a,i)) ; toAsk.pb(0) ; } oldVal = ask(toAsk) ; rad = oldVal/A ; edgePai[0] = -1 ; dfs(0,0) ; int l = 0 , r = possible.size() - 1 , mid , best = 0 ; while(l<=r) { mid = (l+r)/2 ; lp( i, l , mid+1 ) toAsk[ edgePai[possible[i]] ] = 1 ; newVal = ask(toAsk) ; lp(i,l,mid+1) toAsk[ edgePai[possible[i]] ] = 0 ; if( A < B ? newVal > oldVal : newVal < oldVal ) { r = mid - 1; best = mid ; } else l = mid+1 ; } T = possible[best] ; answer(S,T) ; }
#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...