Submission #1335536

#TimeUsernameProblemLanguageResultExecution timeMemory
1335536nguyengiabach1201Countries (BOI06_countries)C++20
35 / 100
8 ms7748 KiB
// https://oj.uz/problem/view/BOI06_countries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define el '\n'
#define FNAME "countries"
#define ll long long
#define int long long
#define ld long double

const int MOD = 1e9 + 7;
const ll INF = 1e18 + 7;
const double EPS = 1e-6;

void setup()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    if (fopen(FNAME ".in", "r"))
    {
        freopen(FNAME ".in", "r", stdin);
        freopen(FNAME ".out", "w", stdout);
    }

    return;
}

const int N = 1e3 + 5;
int n, x[N], y[N], s[N], ans[N];
vector<pair<ld, int>> influBy[N];
bool isK[N], isD[N];
vector<int> adj[N];

void dfs(int u)
{
    for (int v : adj[u])
    {
        ans[v] = ans[u], dfs(v);
    }
}

void solve()
{
    cin >> n;

    for (int i = 1; i <= n; ++i)
        cin >> x[i] >> y[i] >> s[i];

    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j)
        {
            if (i == j)
                continue;

            int deltaX = x[i] - x[j], deltaY = y[i] - y[j];

            // cerr << i << " " << j << " " << s[i] << " " << s[j] << " " << (deltaX * deltaX + deltaY * deltaY) << el;

            if (s[i] > s[j] * (deltaX * deltaX + deltaY * deltaY))
                influBy[j].push_back({1l * s[i] / (deltaX * deltaX + deltaY * deltaY), i});
        }

    for (int i = 1; i <= n; ++i)
    {
        int par;
        pair<ld, int> mx = {-1, 0};

        for (auto [influ, idx] : influBy[i])
            if (abs(influ - mx.first) < EPS)
                ++mx.second;
            else if (influ - mx.first > EPS)
                mx = {influ, 1}, par = idx;

        if (influBy[i].size() == 0)
            isK[i] = true, ans[i] = i;
        else if (mx.second >= 2)
            isD[i] = true, ans[i] = i;
        else
            adj[par].push_back(i);
    }

    for (int i = 1; i <= n; ++i)
        if (isK[i] || isD[i])
            dfs(i);

    for (int i = 1; i <= n; ++i)
        if (isK[i])
            cout << "K" << el;
        else if (isD[i])
            cout << "D" << el;
        else
            cout << ans[i] << el;

    return;
}

signed main()
{
    setup();

    int t = 1;
    bool multiTest = false;

    if (multiTest)
        cin >> t;

    while (t--)
        solve();

    return 0;
}

Compilation message (stderr)

countries.cpp: In function 'void setup()':
countries.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen(FNAME ".in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
countries.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen(FNAME ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...