제출 #1223452

#제출 시각아이디문제언어결과실행 시간메모리
1223452HappyCapybara도시들 (IOI15_towns)C++20
26 / 100
63 ms584 KiB
#include "towns.h" #include<bits/stdc++.h> using namespace std; int f1, f2; map<pair<int,int>,int> res; int getDist(int a, int b){ if (a == b) return 0; if (a > b) swap(a, b); if (res.find({a, b}) == res.end()) res[{a, b}] = getDistance(a, b); return res[{a, b}]; } int eq(int a, int b){ return getDist(f1, a)+getDist(f1, b)-getDist(a, b); } int hubDistance(int N, int sub){ res.clear(); int bsf = 0; for (int i=1; i<N; i++){ int d = getDist(0, i); if (d > bsf){ bsf = d; f1 = i; } } bsf = 0; for (int i=0; i<N; i++){ if (i == f1) continue; int d = getDist(f1, i); if (d > bsf){ bsf = d; f2 = i; } } int diam = getDist(f1, f2); map<int,vector<int>> m; int R = pow(10, 9); for (int i=0; i<N; i++){ int jp = (getDist(f1, 0)+getDist(f1, i)-getDist(0, i))/2; m[jp].push_back(i); R = min(R, max(jp, diam-jp)); } int xl = 0, xm, xr = N; bool bal = false; for (auto [jp, v] : m){ xr -= v.size(); xm = v.size(); if ((jp == R || diam-jp == R) && xl <= N/2 && xr <= N/2){ if (xm <= N/2) bal = true; else { int bc = 0; for (int x : v){ int cur = 0; for (int y : v){ if (eq(x, y) != 2*jp) cur++; } bc = max(bc, cur); } if (bc <= N/2) bal = true; /*vector<pair<int,int>> w, d; for (int x : v) w.push_back({x, 1}); while (w.size() > 1){ vector<pair<int,int>> nw; if (w.size() % 2){ nw.push_back(w.back()); w.pop_back(); } for (int i=0; i<(int)w.size(); i+=2){ if (eq(w[i].first, w[i+1].first) == 2*jp){ d.push_back(w[i]); d.push_back(w[i+1]); } else nw.push_back({w[i].first, w[i].second+w[i+1].second}); } w = nw; } if (w.size()){ int bc = w[0].second; for (pair<int,int> dead : d){ if (eq(w[0].first, dead.first) != 2*jp) bc += dead.second; } if (bc <= N/2) bal = true; } else bal = true;*/ } } xl += v.size(); } if (bal) return R; else return -R; }
#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...