#include <iostream>
#include <cmath>
#include <unordered_map>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <string>
#include <iomanip>
#include <algorithm>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
typedef long long ll;
ll linf = 1e15+1;
inline void scoobydoobydoo(){
ios::sync_with_stdio(false);
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
}
const int MAXN = 1001;
int parent[MAXN];
bool isDemo[MAXN];
int rootOf(int x){
return (x == parent[x] ? x : rootOf(parent[x]));
}
void merge(int a, int b){
//a -> b
parent[a] = rootOf(b);
}
/*
5
2 5 14
2 3 2
3 2 7
1 1 2
2 1 3
*/
set<pair<long double, int> > s[MAXN];
long double soldiers[MAXN];
vector<pair<ll, ll> > v;
long double dist(int i, int j){
long double di = pow(abs(v[i].first-v[j].first), 2) + pow(abs(v[i].second-v[j].second), 2);
return soldiers[j]/di;
}
int main(){
scoobydoobydoo();
int n; cin >> n;
for (int i = 0; i < n; i++){
parent[i] = i;
v.push_back({});
}
for (int i = 0; i < n; i++){
ll x, y, w; cin >> x >> y >> w;
v[i] = {x, y};
soldiers[i] = w;
}
int counter = 0;
for (auto p : v){
int cntr = -1;
for (auto e : v){
cntr++;
if (p == e)continue;
s[counter].insert({dist(counter, cntr), cntr});
}
counter++;
}
for (int i = 0; i < n; i++){
auto it = s[i].rbegin();
pair<long double, int> firs = *it;
it--;
pair<long double, int> secon = *it;
if (firs.first == secon.first){
isDemo[i] = true;
} else if (firs.first > soldiers[i]){
merge(i, firs.second);
}
}
for (int i = 0; i < n; i++){
if (isDemo[i]){
cout << "D" << endl;
} else if (parent[i] != i){
cout << rootOf(i)+1 << endl;
} else {
cout << "K" << endl;
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1116 KB |
Output is correct |
2 |
Incorrect |
7 ms |
3468 KB |
Output isn't correct |
3 |
Incorrect |
16 ms |
7516 KB |
Output isn't correct |
4 |
Incorrect |
29 ms |
12892 KB |
Output isn't correct |
5 |
Incorrect |
47 ms |
19796 KB |
Output isn't correct |
6 |
Incorrect |
70 ms |
28492 KB |
Output isn't correct |
7 |
Correct |
95 ms |
38616 KB |
Output is correct |
8 |
Correct |
126 ms |
50316 KB |
Output is correct |
9 |
Incorrect |
169 ms |
63756 KB |
Output isn't correct |
10 |
Correct |
206 ms |
78568 KB |
Output is correct |
11 |
Correct |
2 ms |
1112 KB |
Output is correct |
12 |
Correct |
7 ms |
3420 KB |
Output is correct |
13 |
Correct |
15 ms |
7516 KB |
Output is correct |
14 |
Incorrect |
29 ms |
12892 KB |
Output isn't correct |
15 |
Correct |
47 ms |
19796 KB |
Output is correct |
16 |
Correct |
68 ms |
28496 KB |
Output is correct |
17 |
Correct |
105 ms |
38736 KB |
Output is correct |
18 |
Correct |
125 ms |
50484 KB |
Output is correct |
19 |
Incorrect |
157 ms |
63828 KB |
Output isn't correct |
20 |
Correct |
203 ms |
78536 KB |
Output is correct |