#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll gcd(ll a, ll b){return __gcd(a, b);}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ull mask){return __builtin_popcountll(mask);}
int ctz(ull mask){return __builtin_ctzll(mask);}
int logOf(ull mask){return 63 - __builtin_clzll(mask);}
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
double rngesus_d(double l, double r){
double wow = (double) ((ull) rng()) / ((ull)(0-1));
return wow * (r - l) + l;
}
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b) {a = b; return true;}
return false;
}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b) {a = b; return true;}
return false;
}
template <class T>
void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){
for(auto item: container) out << item << separator;
out << finish;
}
template <class T>
void remove_dup(vector<T> &a){
sort(ALL(a));
a.resize(unique(ALL(a)) - a.begin());
}
ll sqr(ll x){return x * x;}
ll dis(ll x, ll y, ll u, ll v){
return sqr(x - u) + sqr(y - v);
}
void solve(){
int n; cin >> n;
vector<array<int, 3>> a(n+1);
for(int i = 1; i <= n; ++i)
cin >> a[i][0] >> a[i][1] >> a[i][2];
vector<int> parent(n+1, -1);
vector<int> influenced(n+1);
for(int i = 1; i <= n; ++i){
pair<ll, ll> cur = make_pair(-1, 1);
int idx = -1, cnt = 0;
for(int j = 1; j <= n; ++j) if (i != j){
ll dih = dis(a[i][0], a[i][1], a[j][0], a[j][1]);
if (a[i][2] * dih < a[j][2]){
influenced[i] = true;
pair<ll, ll> frac = make_pair(a[j][2], dih);
if (cur.first * frac.second < frac.first * cur.second){
idx = j;
cnt = 1;
cur = frac;
}
else if (cur.first * frac.second == frac.first * cur.second){
cnt++;
}
}
}
if (cnt == 1){
parent[i] = idx;
}
}
for(int i = 1; i <= n; ++i){
if (parent[i] == -1){
if (influenced[i]) cout << "D\n";
else cout << "K\n";
}
else {
int u = i;
while(parent[u] != -1) u = parent[u];
cout << u << "\n";
}
}
}
int main(void){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
clock_t cock = clock();
solve();
cerr << "Time elapsed: " << clock() - cock << "ms!\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |