# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
137906 | onjo0127 | Countries (BOI06_countries) | C++11 | 5 ms | 380 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int N, x[1009], y[1009], s[1009], p[1009];
char ans[1009];
int root(int x) {
if(p[x] == x) return x;
return p[x] = root(p[x]);
}
void merg(int u, int v) {
u = root(u); v = root(v);
p[u] = v;
}
int dst(int i, int j) {
return (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
}
int main() {
scanf("%d",&N);
for(int i=1; i<=N; i++) {
scanf("%d%d%d", &x[i], &y[i], &s[i]);
p[i] = i;
}
for(int i=1; i<=N; i++) {
int mxi = -1, c = 0;
for(int j=1; j<=N; j++) {
if(i == j) continue;
if(s[j] > s[i] * dst(i, j)) {
if(mxi == -1) mxi = j, c = 1;
else if(s[j] * dst(i, mxi) > s[mxi] * dst(i, j)) mxi = j, c = 1;
else if(s[j] * dst(i, mxi) == s[mxi] * dst(i, j)) ++c;
}
}
if(mxi == -1) ans[i] = 'K';
else if(c > 1) ans[i] = 'D';
else {
ans[i] = 'O';
merg(i, mxi);
}
}
for(int i=1; i<=N; i++) {
if(ans[i] == 'O') printf("%d\n", root(i));
else printf("%c\n", ans[i]);
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |