Submission #704136

# Submission time Handle Problem Language Result Execution time Memory
704136 2023-03-01T16:49:20 Z pakhomovee Countries (BOI06_countries) C++17
100 / 100
3 ms 340 KB
#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 time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 2 ms 212 KB Output is correct
18 Correct 3 ms 340 KB Output is correct
19 Correct 2 ms 328 KB Output is correct
20 Correct 3 ms 340 KB Output is correct