Submission #1088403

#TimeUsernameProblemLanguageResultExecution timeMemory
1088403PacybwoahTowns (IOI15_towns)C++17
25 / 100
11 ms1004 KiB
#include "towns.h" #include<vector> #include<algorithm> #include<utility> #include<map> using namespace std; int hubDistance(int N, int sub) { int a = -1, b = -1; int maxi = 0, n = N; for(int i = 1; i < n; i++){ int len = getDistance(0, i); if(len > maxi){ maxi = len; a = i; } } vector<int> dista(n), distb(n); maxi = 0; for(int i = 0; i < n; i++){ dista[i] = getDistance(a, i); if(dista[i] > maxi){ maxi = dista[i]; b = i; } } for(int i = 0; i < n; i++){ distb[i] = getDistance(b, i); } int d = dista[b]; int ans = 1e9; for(int i = 0; i < n; i++){ int da = (d + dista[i] + distb[i]) / 2 - distb[i], db = (d + dista[i] + distb[i]) / 2 - dista[i]; ans = min(ans, max(da, db)); } if(sub == 4){ map<int, int> m; for(int i = 0; i < n; i++){ m[dista[i]]++; } int sum = 0; bool flag = 0; for(auto &[len, val]: m){ if(max(len, d - len) == ans){ if(max(val, max(sum, n - sum - val)) <= n / 2) flag = 1; } sum += val; } if(flag) return ans; else return -ans; } return ans; } // g++ -std=c++17 -Wall -Wextra -fsanitize=undefined -fsanitize=address -Wshadow -o run towns.cpp grader.cpp
#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...