Submission #525129

#TimeUsernameProblemLanguageResultExecution timeMemory
525129ali22413836Countries (BOI06_countries)C++14
10 / 100
11 ms6092 KiB
#include <bits/stdc++.h> //#define endl "\n" using namespace std ; typedef long long ll; typedef long double ld ; const int N=2e7; const ll inf=1e18 ; const ll mod = 1e9 + 7 ; ll mypower(ll x, ll y){ if(y == 0) return 1 ; if(y == 1) return x ; ll ret = mypower(x , y / 2); ret = (ret * ret) % mod; if(y % 2) ret = ( ret * x ) % mod ; return ret ; } ll n , x[20000] , y[200009] , s[200009] , in[200009] , di[200009] ; bool vis[1009][1009] , from2[200009] ; vector < ll > v[200009] ; void dfs(ll node , ll root){ if(vis[node][root]) return ; vis[node][root] = 1 ; if(di[node] != -1){ from2[node] = 1 ; } else{ di[node] = root ; } for(auto p : v[node]){ if(vis[p][root] == 0){ ll q = (x[node] - x[p]) * (x[node] - x[p]) + (y[node] - y[p]) * (y[node] - y[p]) ; ll e = s[node]/ q ; if(e > s[p]) dfs(p , root) ; } } } int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n ; for(int i = 0 ; i < n ; i++){ cin >> x[i] >> y[i] >> s[i] ; di[i] = -1 ; } for(int i = 0 ; i < n ; i++){ for(int j = 0; j < n ; j++){ if(i == j) continue ; ll q = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]) ; ll e = s[j] / q ; if(e > s[i]){ v[j].push_back(i) ; in[i]++ ; } } } for(int i = 0 ; i < n ; i++){ if(in[i] == 0){ dfs(i , i) ; } } for(int i = 0 ; i < n ; i++){ if(di[i] == i){ cout << "K" << endl ; } else if(from2[i] == 1){ cout << "D" << endl ; } else{ cout << di[i] + 1 << endl; } } return 0 ; } /* 5 2 5 14 2 3 2 3 2 7 1 1 2 2 1 3 */
#Verdict Execution timeMemoryGrader output
Fetching results...