Submission #704136

#TimeUsernameProblemLanguageResultExecution timeMemory
704136pakhomoveeCountries (BOI06_countries)C++17
100 / 100
3 ms340 KiB
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <set> #include <stdlib.h> #include <map> #include <random> #include <cstring> #include <functional> #include <iomanip> #include <cassert> #include <queue> #include <unordered_map> #include <array> using namespace std; void solve() { int n; cin >> n; vector<pair<pair<int, int>, int>> a(n); for (int i = 0; i < n; ++i) { cin >> a[i].first.first >> a[i].first.second >> a[i].second; } auto d = [&] (pair<int, int> a, pair<int, int> b) { int dx = a.first - b.first; int dy = a.second - b.second; return dx * dx + dy * dy; }; vector<bool> kingdom(n, false); vector<bool> democracy(n, false); vector<int> dependence(n, -1); vector<int> par(n, -1); for (int i = 0; i < n; ++i) { pair<double, double> mx = { 0, 0 }; int bst = -1; for (int j = 0; j < n; ++j) { if (i != j) { double curr = a[j].second * 1.0 / d(a[j].first, a[i].first); if (curr > mx.first) { mx.second = mx.first; mx.first = curr; bst = j; } else if (curr > mx.second) { mx.second = curr; } } } if (mx.first > a[i].second) { if (mx.first == mx.second) { democracy[i] = true; } else { par[i] = bst; } } else { kingdom[i] = true; } } for (int j = 0; j < n; ++j) { int x = j; while (par[x] != -1) x = par[x]; dependence[j] = x; } for (int i = 0; i < n; ++i) { if (kingdom[i]) cout << 'K' << '\n'; else if (democracy[i]) cout << 'D' << '\n'; else cout << dependence[i] + 1 << '\n'; } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; t = 1; while (t--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...