답안 #74160

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
74160 2018-08-30T10:30:28 Z funcsr 도시들 (IOI15_towns) C++17
25 / 100
24 ms 3744 KB
#include "towns.h"
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i, N) for (int i=0; i<(N); i++)
#define pb push_back
#define _1 first
#define _2 second
#define all(x) x.begin(), x.end()
#define uniq(x) x.erase(unique(all(x)), x.end())
#define INF 1145141919
using namespace std;
typedef pair<int, int> P;

int N;
int memo[111][111];
int Rank[111];
int dist(int a, int b) {
  if (memo[a][b] != -1) return memo[a][b];
  return memo[a][b] = getDistance(a, b);
}
int saien(int x) {
  P mp = P(-1, -1);
  rep(t, N) mp = max(mp, P(dist(x, t), t));
  return mp._2;
}

int hubDistance(int NN, int sub) {
  N=NN;
  rep(i, N) rep(j, N) memo[i][j] = -1;
  rep(i, N) memo[i][i] = 0;

  int u = saien(0);
  int v = saien(u);
  vector<int> pos;
  int L = dist(u, v);
  pos.pb(0);
  pos.pb(L);
  rep(x, N) if (x != u && x != v) {
    Rank[x] = (dist(u, x)+dist(v, x)-L)/2;
    pos.pb(dist(u, x)-Rank[x]);
  }
  sort(all(pos)); uniq(pos);
  P mp = P(INF, -1);
  //cout<<"L="<<L<<"\n";
  //for (int x : pos)cout<<x<<",";cout<<"\n";
  for (int x : pos) mp = min(mp, P(max(x, L-x), x));
  int R = mp._1;
  return R;
}

Compilation message

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:28:29: warning: unused parameter 'sub' [-Wunused-parameter]
 int hubDistance(int NN, int sub) {
                             ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 376 KB Output is correct
2 Correct 17 ms 892 KB Output is correct
3 Correct 2 ms 912 KB Output is correct
4 Correct 24 ms 1740 KB Output is correct
5 Correct 24 ms 2040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 2068 KB Output is correct
2 Correct 17 ms 2580 KB Output is correct
3 Correct 22 ms 3164 KB Output is correct
4 Correct 24 ms 3732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 3732 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 23 ms 3732 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 3732 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 3744 KB Output isn't correct
2 Halted 0 ms 0 KB -