# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
697609 | finn__ | Countries (BOI06_countries) | C++17 | 191 ms | 368 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
struct DSU
{
vector<int64_t> y;
DSU(size_t n) { y = vector<int64_t>(n, -1); }
int64_t representative(int64_t u)
{
return y[u] < 0 ? u : (y[u] = representative(y[u]));
}
void unite(int64_t u, int64_t v)
{
u = representative(u), v = representative(v);
if (u != v)
y[v] = u;
}
};
typedef pair<int, int> fraction;
fraction reduce_fraction(fraction const f)
{
int g = __gcd(f.first, f.second);
return {f.first / g, f.second / g};
}
long double val(fraction const &f)
{
return (long double)f.first / (long double)f.second;
}
bool compare_influence(pair<int, fraction> const &f, pair<int, fraction> const &g)
{
return ((long double)f.second.first / (long double)f.second.second) <
((long double)g.second.first / (long double)g.second.second);
}
int main()
{
size_t n;
cin >> n;
vector<complex<int>> cities(n);
vector<int> s(n);
for (size_t i = 0; i < n; i++)
{
int x, y;
cin >> x >> y >> s[i];
cities[i] = {x, y};
}
DSU dsu(n);
vector<string> ans(n);
for (size_t i = 0; i < n; i++)
{
vector<pair<unsigned, fraction>> influence;
for (size_t j = 0; j < n; j++)
if (i != j)
influence.emplace_back(j, reduce_fraction({s[j], norm(cities[j] - cities[i])}));
sort(influence.begin(), influence.end(), compare_influence);
if (s[i] * influence.back().second.second >= influence.back().second.first)
ans[i] = "K\n";
else if (influence.size() >= 2 && influence.back().second == influence[influence.size() - 2].second)
ans[i] = "D\n";
else
dsu.unite(influence.back().first, i);
}
for (size_t i = 0; i < n; i++)
if (dsu.representative(i) != i)
ans[i] = to_string(dsu.representative(i) + 1) + "\n";
for (string const &x : ans)
cout << x;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |