#include <bits/stdc++.h>
using namespace std;
struct country {
int x, y, s, ind;
bool operator<(country a) {
return s > a.s;
}
} a[1007];
int dist(int i, int j) {
return (a[i].x - a[j].x) * (a[i].x - a[j].x) +
(a[i].y - a[j].y) * (a[i].y - a[j].y);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n; cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i].x >> a[i].y >> a[i].s;
a[i].ind = i;
}
sort(a, a + n);
vector<int> r(n);
for (int i = 0; i < n; i++) {
vector<int> v;
for (int j = 0; j < i; j++) {
if (a[j].s > a[i].s * dist(i, j)) {
v.push_back(j);
}
}
if (v.empty()) {
r[a[i].ind] = 0; continue;
}
int h = v[0], c = 1;
for (int j = 1; j < v.size(); j++) {
int d1 = a[h].s * dist(v[j], i);
int d2 = a[v[j]].s * dist(h, i);
if (d1 == d2) {
c++; continue;
}
if (d1 < d2) {
h = v[j]; c = 1;
}
}
if (c > 1) {
r[a[i].ind] = -1; continue;
}
r[a[i].ind] = (r[a[h].ind] ? r[a[h].ind] : a[h].ind + 1);
}
for (int i = 0; i < n; i++) {
if (r[i] > 0) {
cout << r[i] << endl; continue;
}
cout << (r[i] ? "D" : "K") << endl;
}
}
Compilation message
countries.cpp: In function 'int main()':
countries.cpp:37:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for (int j = 1; j < v.size(); j++) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
3 ms |
332 KB |
Output is correct |
9 |
Correct |
3 ms |
332 KB |
Output is correct |
10 |
Correct |
4 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
332 KB |
Output is correct |
18 |
Correct |
3 ms |
332 KB |
Output is correct |
19 |
Correct |
4 ms |
340 KB |
Output is correct |
20 |
Correct |
3 ms |
332 KB |
Output is correct |