답안 #758242

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
758242 2023-06-14T10:12:03 Z nguyen31hoang08minh2003 Countries (BOI06_countries) C++14
10 / 100
292 ms 524288 KB
#include <bits/stdc++.h>
using namespace std;

constexpr int MAX_N = 1005, INF = 0X3F3F3F3F, NINF = 0XC0C0C0C0;

class UnsignedFraction {
private:

    long long numerator, denominator;

public:

    UnsignedFraction(const long long numerator, const long long denominator): numerator(numerator), denominator(denominator) {};

    UnsignedFraction(const long long numerator): numerator(numerator), denominator(1) {};

    UnsignedFraction(): numerator(0), denominator(1) {};

    friend bool operator == (const UnsignedFraction &a, const UnsignedFraction &b) {
        return a.numerator * b.denominator == b.numerator * a.denominator;
    }

    friend bool operator > (const UnsignedFraction &a, const UnsignedFraction &b) {
        return a.numerator * b.denominator == b.numerator * a.denominator;
    }

    friend bool operator < (const UnsignedFraction &a, const UnsignedFraction &b) {
        return a.numerator * b.denominator == b.numerator * a.denominator;
    }

    short compare(const UnsignedFraction &other) const {
        const long long first = numerator * other.denominator, second = other.numerator * denominator;
        if (first < second)
            return -1;
        if (first > second)
            return 1;
        return 0;
    }

    UnsignedFraction getReducedFraction() const {
        const long long g = __gcd(this -> numerator, this -> denominator);
        return UnsignedFraction((this -> numerator) / g, (this -> denominator) / g);
    }

    friend ostream& operator << (ostream &outputStream, const UnsignedFraction &fraction) {
        return outputStream << fraction.numerator << '/' << fraction.denominator;
    }

};

signed capital[MAX_N];
UnsignedFraction maximum[MAX_N];
int n, x[MAX_N], y[MAX_N], s[MAX_N];

/**

    0 <= x[i], y[i], s[i] <= 1000

    s[j] / sqrt(square(x[i] - x[j]) + square(y[i] - y[j])) > s[i]
    => s[j] > s[i] * sqrt(square(x[i] - x[j]) + square(y[i] - y[j]))
    => square(s[j]) > square(s[i]) * (square(x[i] - x[j]) + square(y[i] - y[j]))

**/

long long findSquare(const long long x) {
    return x * x;
}

signed findCapital(const signed c) {
    if (capital[c] == c)
        return c;
    return capital[c] = findCapital(capital[c]);
}

signed main() {

    UnsignedFraction fraction;

    #ifdef LOCAL
        freopen("input.INP", "r", stdin);
//        freopen("output.out", "w", stdout);
    #endif
    cin.tie(0) -> sync_with_stdio(0);
    cout.tie(0);

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

    for (int j = 1, i, flag; j <= n; ++j)
        for (i = 1; i <= n; ++i) {
            if (i == j)
                continue;
            fraction = UnsignedFraction(s[j], findSquare(x[i] - x[j]) + findSquare(y[i] - y[j]));
            flag = maximum[i].compare(fraction);
            if (flag > 0)
                continue;
            if (flag < 0) {
                maximum[i] = fraction;
                capital[i] = j;
            } else
                capital[i] = 0;
        }

    for (int i = 1; i <= n; ++i) {
//        #ifdef LOCAL
//        cerr << i << ' ' << maximum[i] << '\n';
//        #endif // LOCAL
        if (maximum[i].compare(s[i]) <= 0) {
            capital[i] = i;
            cout << "K\n";
            continue;
        }
        if (capital[i])
            cout << findCapital(i) << '\n';
        else
            cout << "D\n";
    }


    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 267 ms 524288 KB Execution killed with signal 9
2 Runtime error 283 ms 524288 KB Execution killed with signal 9
3 Runtime error 260 ms 524288 KB Execution killed with signal 9
4 Runtime error 272 ms 524288 KB Execution killed with signal 9
5 Runtime error 256 ms 524288 KB Execution killed with signal 9
6 Runtime error 281 ms 524288 KB Execution killed with signal 9
7 Runtime error 264 ms 524288 KB Execution killed with signal 9
8 Runtime error 266 ms 524288 KB Execution killed with signal 9
9 Runtime error 284 ms 524288 KB Execution killed with signal 9
10 Runtime error 259 ms 524288 KB Execution killed with signal 9
11 Correct 1 ms 344 KB Output is correct
12 Runtime error 274 ms 524288 KB Execution killed with signal 9
13 Correct 1 ms 344 KB Output is correct
14 Runtime error 280 ms 524288 KB Execution killed with signal 9
15 Incorrect 1 ms 340 KB Output isn't correct
16 Runtime error 280 ms 524288 KB Execution killed with signal 9
17 Runtime error 276 ms 524288 KB Execution killed with signal 9
18 Runtime error 283 ms 524288 KB Execution killed with signal 9
19 Runtime error 262 ms 524288 KB Execution killed with signal 9
20 Runtime error 292 ms 524288 KB Execution killed with signal 9