Submission #883749

# Submission time Handle Problem Language Result Execution time Memory
883749 2023-12-05T23:36:02 Z MilosMilutinovic Towns (IOI15_towns) C++14
0 / 100
11 ms 604 KB
#include "towns.h"
#include <bits/stdc++.h>
 
using namespace std;
 
int hubDistance(int n, int sub) {
  map<pair<int, int>, int> mp;
  auto Ask = [&](int l, int r) {
    if (l > r) {
      swap(l, r);
    }
    if (l == r) {
      return 0;
    }
    if (mp.count({l, r})) {
      return mp[{l, r}];
    }
    mp[{l, r}] = getDistance(l, r);
    return mp[{l, r}];
  };
  int x = 0, y = 0;
  for (int i = 1; i < n; i++) {
    if (Ask(0, i) > Ask(0, x)) {
      x = i;
    }
  }
  for (int i = 0; i < n; i++) {
    if (Ask(x, i) > Ask(x, y)) {
      y = i;
    }
  }
  vector<int> d;
  vector<int> my(n);
  for (int i = 0; i < n; i++) {
    my[i] = (Ask(i, x) - Ask(i, 0) + Ask(0, x)) / 2;
    d.push_back(my[i]); 
  }
  sort(d.begin(), d.end());
  d.erase(unique(d.begin(), d.end()));
  int sz = (int) d.size();
  vector<int> r(sz);
  for (int i = 0; i < sz; i++) {
    r[i] = max(d[i], Ask(x, y) - d[i]);
  }
  int mn = *min_element(r.begin(), r.end());
  vector<int> cnt(sz);
  for (int i = 0; i < n; i++) {
    int idx = (int) (lower_bound(d.begin(), d.end(), my[i]) - d.begin());
    cnt[idx] += 1;
  }
  vector<int> pref(sz);
  for (int i = 0; i < sz; i++) {
    if (i > 0) {
      pref[i] = pref[i - 1];
    }
    pref[i] += cnt[i];
  }
  vector<int> cands;
  for (int i = 1; i + 1 < sz; i++) {
    if (r[i] == mn && max((i == 0 ? 0 : pref[i - 1]), pref[sz - 1] - pref[i]) <= n / 2) {
      cands.push_back(i);
    }
  }
  assert(cands.size() <= 2);
  return mn;
}

Compilation message

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:6:28: warning: unused parameter 'sub' [-Wunused-parameter]
    6 | int hubDistance(int n, int sub) {
      |                        ~~~~^~~
# Verdict Execution time Memory Grader output
1 Runtime error 11 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 11 ms 600 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 600 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 600 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -