Submission #207296

#TimeUsernameProblemLanguageResultExecution timeMemory
207296AQTTowns (IOI15_towns)C++14
35 / 100
27 ms504 KiB
#include <towns.h> #include <bits/stdc++.h> using namespace std; int dist[2][200]; int par[200], sz[200]; bool midset[200]; /* int getDistance(int i, int j){ cout << "? " << i << " " << j << endl; int k; cin >> k; return k; } */ int hubDistance(int N, int sub){ int d1 = 0, d2 = 0; for(int i = 1; i<N; i++){ dist[0][i] = getDistance(0, i); if(dist[0][i] > dist[0][d1]){ d1 = i; } } for(int i = 0; i<N; i++){ dist[1][i] = getDistance(d1, i); if(dist[1][i] > dist[1][d2]){ d2 = i; } } int dia = dist[1][d2]; //cout << "diameter endpoints: " << d1 << " " << d2 << endl; int ans = dia; for(int i = 0; i<N; i++){ int k = (dist[0][d1] + dist[1][i] - dist[0][i])/2; //cout << "which set?: " << i << " " << k << endl; if(abs(ans-dia/2) > abs(k-dia/2)){ ans = k; } midset[i] = 0; } ans = max(ans, dia-ans); int lft = 0, rht = 0; for(int i = 0; i<N; i++){ int k = (dist[0][d1] + dist[1][i] - dist[0][i])/2; //cout << "which set again?: " << i << " " << k << endl; //cout << dist[0][d1] << " " << dist[1][i] << " " << dist[0][i] << endl; if(dia-k > ans){ //cout << "lft: " << i << endl; midset[i] = 1; lft++; } else if(k > ans){ //cout << "rht: " << i << endl; midset[i] = 1; rht++; } } if(max(lft, rht) > N/2){ ans = -ans; return ans; } vector<int> v, w; for(int i =0 ; i<N; i++){ if(midset[i]){ par[i] = -1; continue; } par[i] = i; v.push_back(i); sz[i] = 1; } int g = -1; while(v.size()){ //cout << "next iteration: " << k << endl; while(v.size() >= 2){ int n = v.back(); v.pop_back(); int m = v.back(); v.pop_back(); if(dist[1][n] + dist[1][m] - getDistance(n, m) > 2*ans){ par[n] = -1; sz[m] += sz[n]; w.push_back(m); } } if(v.size() == 1 && w.empty()){ g = v[0]; break; } swap(v, w); w.clear(); } if(g != -1){ int cnt = 0; for(int i = 0; i<N; i++){ if(par[i] == i && !midset[i]){ if(dist[1][i] + dist[1][g] - getDistance(i, g) > 2*ans){ cnt += sz[i]; //cout << "sz: " << i << " " << sz[i] << endl; } } } //cout << cnt << endl; if(cnt > N/2){ ans = -ans; } } else{ ans = -ans; } return ans; } /* int main(){ cout << hubDistance(11, 0) << endl; } */

Compilation message (stderr)

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:18:28: warning: unused parameter 'sub' [-Wunused-parameter]
 int hubDistance(int N, int sub){
                            ^~~
#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...