제출 #764995

#제출 시각아이디문제언어결과실행 시간메모리
764995SanguineChameleon도시들 (IOI15_towns)C++17
13 / 100
16 ms408 KiB
#include "towns.h" #include <bits/stdc++.h> using namespace std; const int maxN = 1e2 + 20; int memo[maxN][maxN]; int depth[maxN]; bool flag[maxN]; int dist(int u, int v) { if (memo[u][v] != -1) { return memo[u][v]; } else { return memo[u][v] = memo[v][u] = getDistance(u, v); } } bool equal(int u, int v) { return depth[u] + depth[v] == dist(u, v); } bool check(vector<int> comp) { vector<int> bucket; vector<int> list; for (auto u: comp) { if (list.empty() || !equal(list.back(), u)) { list.push_back(u); if (!bucket.empty()) { list.push_back(bucket.back()); bucket.pop_back(); } } else { bucket.push_back(u); } } int u = list.back(); while (!list.empty()) { int v = list.back(); list.pop_back(); if (equal(u, v)) { if (!list.empty()) { list.pop_back(); } else { bucket.push_back(v); } } else { if (bucket.empty()) { return true; } bucket.pop_back(); } } return bucket.empty(); } int hubDistance(int N, int sub) { for (int i = 0; i < N; i++) { flag[i] = false; } for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { memo[i][j] = (i == j ? 0 : -1); } } int X = 0; for (int i = 0; i < N; i++) { if (dist(0, i) > dist(0, X)) { X = i; } } int Y = 0; for (int i = 0; i < N; i++) { if (dist(X, i) > dist(X, Y)) { Y = i; } } int R = dist(X, Y); map<int, vector<int>> comps; for (int i = 0; i < N; i++) { depth[i] = (dist(X, i) + dist(Y, i) - dist(X, Y)) / 2; int left = dist(X, i) - depth[i]; int right = dist(Y, i) - depth[i]; comps[left].push_back(i); R = min(R, max(left, right)); } int pref = 0; int suf = N; for (auto p: comps) { suf -= (int)p.second.size(); if (max(p.first, dist(X, Y) - p.first) == R && pref <= N / 2 && suf <= N / 2) { if ((int)p.second.size() <= N / 2 || check(p.second)) { return R; } } pref += (int)p.second.size(); } return -R; }

컴파일 시 표준 에러 (stderr) 메시지

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:60:28: warning: unused parameter 'sub' [-Wunused-parameter]
   60 | 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...