#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> s(n);
vector<pair<int, int>> cities(n);
for (int i = 0; i < n; i++) {
cin >> cities[i].first >> cities[i].second >> s[i];
}
vector<int> ans(n);
for (int i = 0; i < n; i++) {
map<double, pair<int, int>> cnt;
for (int j = 0; j < n; j++) {
if (j == i) continue;
int x1 = cities[i].first, x2 = cities[j].first;
int y1 = cities[i].second, y2 = cities[j].second;
double dist = abs(x1-x2)*abs(x1-x2) + abs(y1-y2)*abs(y1-y2);
cnt[s[j]/dist].first++;
cnt[s[j]/dist].second = j;
}
auto it = cnt.rbegin();
if (it->first > s[i]) {
if (it->second.first > 1) ans[i] = -2;
else ans[i] = it->second.second;
}
else ans[i] = -1;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
ans[j] = (ans[j] < 0 || ans[ans[j]] < 0 ? ans[j] : ans[ans[j]]);
}
}
for (int i = 0; i < n; i++) {
if (ans[i] == -1) cout << "K\n";
else if (ans[i] == -2) cout << "D\n";
else cout << ans[i]+1 << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
344 KB |
Output is correct |
2 |
Correct |
5 ms |
348 KB |
Output is correct |
3 |
Correct |
12 ms |
344 KB |
Output is correct |
4 |
Correct |
23 ms |
348 KB |
Output is correct |
5 |
Correct |
40 ms |
460 KB |
Output is correct |
6 |
Correct |
55 ms |
348 KB |
Output is correct |
7 |
Correct |
83 ms |
468 KB |
Output is correct |
8 |
Correct |
110 ms |
480 KB |
Output is correct |
9 |
Correct |
141 ms |
348 KB |
Output is correct |
10 |
Correct |
190 ms |
344 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
348 KB |
Output is correct |
13 |
Correct |
13 ms |
456 KB |
Output is correct |
14 |
Correct |
23 ms |
436 KB |
Output is correct |
15 |
Correct |
42 ms |
348 KB |
Output is correct |
16 |
Correct |
59 ms |
464 KB |
Output is correct |
17 |
Correct |
83 ms |
348 KB |
Output is correct |
18 |
Correct |
94 ms |
464 KB |
Output is correct |
19 |
Correct |
72 ms |
348 KB |
Output is correct |
20 |
Correct |
185 ms |
348 KB |
Output is correct |