Submission #1029652

# Submission time Handle Problem Language Result Execution time Memory
1029652 2024-07-21T07:05:50 Z kunzaZa183 Towns (IOI15_towns) C++17
25 / 100
13 ms 1060 KB
#include "towns.h"

#include <bits/stdc++.h>
using namespace std;
const int maxn = 110;
int dist[maxn][maxn];

int hubDistance(int N, int sub) {
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++) dist[i][j] = -1;
  for (int i = 1; i < N; i++) {
    int x = getDistance(0, i);
    dist[i][0] = x, dist[0][i] = x;
  }
  int r1 = 1, r2;
  for (int i = 1; i < N; i++)
    if (dist[0][r1] < dist[0][i]) r1 = i;
  for (int i = 0; i < N; i++) {
    int x = getDistance(r1, i);
    dist[r1][i] = x, dist[i][r1] = x;
  }
  r2 = r1;
  for (int i = 0; i < N; i++)
    if (dist[r1][r2] < dist[r1][i]) {
      // cout << dist[r1][r2] << " " << dist[r1][i] << " " << i << "\n";
      r2 = i;
    }
  for (int i = 0; i < N; i++) {
    int x = getDistance(i, r2);
    dist[i][r2] = x, dist[r2][i] = x;
  }
  // cerr << r1 << " " << r2 << "\n";
  map<int, int> mii;
  for (int i = 0; i < N; i++)
    if (i != r1 && i != r2) {
      int sumall = (dist[i][r1] + dist[r1][r2] + dist[i][r2]) / 2;
      int tor1 = sumall - dist[i][r2], toi = sumall - dist[r1][r2],
          tor2 = sumall - dist[i][r1];
      mii[tor1] = max({mii[tor1], tor1, tor2, toi});
    }
  int maxi = INT_MAX;
  for (auto a : mii) maxi = min(maxi, a.second);
  return maxi;
}

Compilation message

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:8:28: warning: unused parameter 'sub' [-Wunused-parameter]
    8 | int hubDistance(int N, int sub) {
      |                        ~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 860 KB Output is correct
2 Correct 8 ms 772 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 13 ms 1060 KB Output is correct
5 Correct 12 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 580 KB Output is correct
2 Correct 7 ms 968 KB Output is correct
3 Correct 10 ms 844 KB Output is correct
4 Correct 10 ms 892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 860 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -