Submission #966223

#TimeUsernameProblemLanguageResultExecution timeMemory
966223AdamGSTowns (IOI15_towns)C++17
100 / 100
20 ms1100 KiB
#include "towns.h" #include<bits/stdc++.h> using namespace std; #define rep(a, b) for(int a = 0; a < (b); ++a) #define st first #define nd second #define pb push_back #define all(a) a.begin(), a.end() int hubDistance(int n, int sub) { vector<int>A(n), B(n), C(n); pair<int,int>ma={0, 0}; for(int i=1; i<n; ++i) { A[i]=getDistance(0, i); ma=max(ma, {A[i], i}); } int x=ma.nd; B[0]=ma.st; for(int i=1; i<n; ++i) if(i!=x) B[i]=getDistance(x, i); rep(i, n) C[i]=B[i]-(A[i]+B[i]-B[0])/2; ma={0, 0}; rep(i, n) ma=max(ma, {B[i], i}); int y=ma.nd; int ans=max(C[y], B[y]-C[y]); rep(i, n) if(C[i]<=C[y]) ans=min(ans, max(C[i], C[y]-C[i]+B[y]-C[y])); bool czy=false; map<int,int>mp; rep(i, n) if(C[i]<=C[y] && max(C[i], C[y]-C[i]+B[y]-C[y])==ans && !mp[C[i]]) { mp[C[i]]=1; vector<int>P; int a=0, b=0; rep(j, n) { if(C[j]<C[i]) ++a; else if(C[j]==C[i]) P.pb(j); else ++b; } if(a>n/2 || b>n/2) continue; vector<vector<int>>X, Y; vector<int>tX, tY; for(auto j : P) { if(tX.size()==0) { tX.pb(j); continue; } if(getDistance(tX[0], j)==B[tX[0]]+B[j]-2*C[i]) tY.pb(j); else tX.pb(j); if(tX.size()==tY.size()) { X.pb(tX); Y.pb(tY); tX.clear(); tY.clear(); } } if(tX.size()==0) { czy=true; continue; } rep(j, X.size()) { if(getDistance(tX[0], X[j][0])!=B[tX[0]]+B[X[j][0]]-2*C[i]) { for(auto l : X[j]) tX.pb(l); } else { for(auto l : Y[j]) if(getDistance(tX[0], l)!=B[tX[0]]+B[l]-2*C[i]) tX.pb(l); } } if(tX.size()<=n/2) czy=true; } if(!czy) ans=-ans; return ans; }

Compilation message (stderr)

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:4:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define rep(a, b) for(int a = 0; a < (b); ++a)
      |                                    ^
towns.cpp:56:5: note: in expansion of macro 'rep'
   56 |     rep(j, X.size()) {
      |     ^~~
towns.cpp:63:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   63 |     if(tX.size()<=n/2) czy=true;
      |        ~~~~~~~~~^~~~~
towns.cpp:9:28: warning: unused parameter 'sub' [-Wunused-parameter]
    9 | 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...