Submission #729696

# Submission time Handle Problem Language Result Execution time Memory
729696 2023-04-24T11:19:32 Z thimote75 Countries (BOI06_countries) C++14
100 / 100
4 ms 368 KB
#include <bits/stdc++.h>

using namespace std;

#define num long long

struct Influence {
    num dx, dy, sj, from;

    Influence () {
        dx = 0;
        dy = 0;
        sj = 0;
        from = -2;
    }
    Influence (num dx, num dy, num sj, num from) : dx(dx), dy(dy), sj(sj), from(from) {}

    bool valid (num si) {
        return sj > si * dist();
    }
    num dist () {
        return dx * dx + dy * dy;
    }
    void merge (num si, Influence &other) {
        if (!other.valid(si)) return ;

        num idel = dist() * other.sj - sj * other.dist();

        if (from == -2) {
            dx   = other.dx;
            dy   = other.dy;
            sj   = other.sj;
            from = other.from;
        } else if (idel == 0) {
            from = -1;
        } else if (idel > 0) {
            dx   = other.dx;
            dy   = other.dy;
            sj   = other.sj;
            from = other.from;
        }
    }

    void show () {
        if (from == -2) cout << "K";
        else if (from == -1) cout << "D";
        else cout << from + 1;

        cout << " ";
    }
};

vector<int> x;
vector<int> y;
vector<int> s;
vector<Influence> i;

int main () {
    int N;
    cin >> N;

    x.resize(N);
    y.resize(N);
    s.resize(N);
    i.resize(N);

    priority_queue<pair<int, int>> p;
    for (int j = 0; j < N; j ++) {
        cin >> x[j] >> y[j] >> s[j];
        p.push({ s[j], j });
    }
    
    for (int iu = 0; iu < N; iu ++) {
        auto mu = p.top(); p.pop();
        int u = mu.second;

        for (int v = 0; v < N; v ++) {
            if (u == v) continue ;

            Influence i_uv (x[v] - x[u], y[v] - y[u], s[u], i[u].from < 0 ? u : i[u].from);

            i[v].merge(s[v], i_uv);
        }
    }

    for (Influence i_u : i) i_u.show();
    cout << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 316 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 3 ms 300 KB Output is correct
9 Correct 4 ms 308 KB Output is correct
10 Correct 4 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 2 ms 296 KB Output is correct
16 Correct 2 ms 304 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 4 ms 340 KB Output is correct
19 Correct 4 ms 368 KB Output is correct
20 Correct 4 ms 364 KB Output is correct