Submission #462609

# Submission time Handle Problem Language Result Execution time Memory
462609 2021-08-11T00:07:25 Z JovanB Countries (BOI06_countries) C++17
100 / 100
5 ms 384 KB
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
int par[100005];
int x[100005];
int y[100005];
int s[100005];
 
struct broj{
    int p, q;
    bool operator <(const broj & a) const{
        return p * a.q < a.p * q;
    }
    bool operator ==(const broj & a) const{
        return p * a.q == a.p * q;
    }
};
 
int dist(int j, int i){
    return (x[j]-x[i])*(x[j]-x[i]) + (y[j]-y[i])*(y[j]-y[i]);
}
 
broj infl(int j, int i){
    return {s[j], dist(j, i)};
}
 
int root(int a){
    if(par[a] == a) return a;
    return root(par[a]);
}
 
int main(){
    ios_base::sync_with_stdio(false);
    cout.precision(10);
    cout<<fixed;
 
    int n;
    cin >> n;
    for(int i=1; i<=n; i++){
        cin >> x[i] >> y[i] >> s[i];
    }
    for(int i=1; i<=n; i++){
        broj mx;
        mx.q = 0;
        for(int j=1; j<=n; j++){
            if(i == j) continue;
            if(mx.q == 0) mx = infl(j, i);
            else if(mx < infl(j, i)) mx = infl(j, i);
        }
        if(mx.p <= s[i]*mx.q){
            par[i] = i;
            continue;
        }
        for(int j=1; j<=n; j++){
            if(j == i) continue;
            if(mx == infl(j, i)){
                if(!par[i]) par[i] = j;
                else par[i] = -1;
            }
        }
    }
    for(int i=1; i<=n; i++){
        if(par[i] == i) cout << "K\n";
        else if(par[i] == -1) cout << "D\n";
        else cout << root(i) << "\n";
    }
    return 0;
}

Compilation message

countries.cpp: In function 'int main()':
countries.cpp:18:18: warning: 'mx.broj::p' may be used uninitialized in this function [-Wmaybe-uninitialized]
   18 |         return p * a.q == a.p * q;
      |                ~~^~~~~
countries.cpp:46:14: note: 'mx.broj::p' was declared here
   46 |         broj mx;
      |              ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 2 ms 324 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 4 ms 332 KB Output is correct
9 Correct 4 ms 332 KB Output is correct
10 Correct 5 ms 332 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 2 ms 352 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 3 ms 332 KB Output is correct
18 Correct 3 ms 332 KB Output is correct
19 Correct 4 ms 332 KB Output is correct
20 Correct 4 ms 332 KB Output is correct