Submission #966135

# Submission time Handle Problem Language Result Execution time Memory
966135 2024-04-19T12:17:46 Z AdamGS Towns (IOI15_towns) C++17
35 / 100
12 ms 956 KB
#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

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 time Memory Grader output
1 Correct 10 ms 856 KB Output is correct
2 Correct 8 ms 860 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 12 ms 860 KB Output is correct
5 Correct 12 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 860 KB Output is correct
2 Correct 9 ms 860 KB Output is correct
3 Correct 12 ms 860 KB Output is correct
4 Correct 12 ms 956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 856 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 860 KB Output isn't correct
2 Halted 0 ms 0 KB -