답안 #531149

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
531149 2022-02-27T20:45:22 Z OttoTheDino Countries (BOI06_countries) C++17
100 / 100
5 ms 340 KB
#include <bits/stdc++.h>
using namespace std;

#define rep(i,s,e)                  for (int i = s; i <= e; ++i)
#define rrep(i,s,e)                 for (int i = s; i >= e; --i)
#define pb                          push_back
#define pf                          push_front
#define fi                          first
#define se                          second
#define all(a)                      a.begin(), a.end()
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n; cin >> n;
    int x[n+1], y[n+1], s[n+1], cap[n+1] = {};

    rep (i,1,n) cin >> x[i] >> y[i] >> s[i];

    rep (i,1,n) {
        int rul = i, de = 0;
        rep (j,1,n) {
            if (i==j) continue;
            if (rul==i) {
                int d2 = (x[j]-x[i])*(x[j]-x[i])+(y[j]-y[i])*(y[j]-y[i]);
                if ((s[j]+d2-1)/d2>s[i]) rul = j;
            }
            else {
                int dr2 = (x[rul]-x[i])*(x[rul]-x[i])+(y[rul]-y[i])*(y[rul]-y[i]); 
                int d2 = (x[j]-x[i])*(x[j]-x[i])+(y[j]-y[i])*(y[j]-y[i]);
                if (s[j]*dr2>s[rul]*d2) {
                    rul = j;
                    de = 0;
                }
                else if (s[j]*dr2==s[rul]*d2) {
                    de = 1;
                }
            }
        }
        if (de) continue;
        cap[i] = rul;
    }

    rep (i,1,n) {
        int c = cap[i];
        while (c != cap[c]) c = cap[c];
        if (c==i) cout << "K\n";
        else if (!c) cout << "D\n";
        else cout << c << "\n";
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 2 ms 316 KB Output is correct
6 Correct 2 ms 328 KB Output is correct
7 Correct 3 ms 208 KB Output is correct
8 Correct 3 ms 208 KB Output is correct
9 Correct 4 ms 324 KB Output is correct
10 Correct 5 ms 320 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 2 ms 208 KB Output is correct
16 Correct 2 ms 208 KB Output is correct
17 Correct 3 ms 208 KB Output is correct
18 Correct 3 ms 208 KB Output is correct
19 Correct 4 ms 324 KB Output is correct
20 Correct 5 ms 340 KB Output is correct