Submission #729317

#TimeUsernameProblemLanguageResultExecution timeMemory
729317KarpinCountries (BOI06_countries)C++14
100 / 100
4 ms340 KiB
#include <bits/stdc++.h>

using namespace std;


#define ll long long
#define vt vector
#define ar array

struct city {
    int x;
    int y;
    double s;
};

struct resCondition{
    double threatenPower;
    int leaderCountry;
    bool isDemocracy;

};

int getDist (city first, city second){
    return (second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y);
}

double getStrength (city first, city enemy){
    return first.s / getDist(first, enemy);
}


void solve(){

    int n;

    cin >> n;

    vt<city> cities;

    for(int i = 0; i < n; i++){
        int a, b;
        double c;

        cin >> a >> b >> c;
        city my = {a, b, c};
        cities.push_back(my);
    }

    vt<resCondition> res;



    for(int i = 0; i < n; i++) {
        res.push_back({0, i, false});
    }



    for(int i = 0; i < n; i++){
        for(int j = 0; j < i; j++){

            if (getStrength(cities[i], cities[j]) > cities[j].s){
                if (getStrength(cities[i], cities[j]) > res[j].threatenPower){
                    res[j].threatenPower = getStrength(cities[i], cities[j]);
                    res[j].leaderCountry = i;
                    res[j].isDemocracy = false;
                }else if (getStrength(cities[i], cities[j]) == res[j].threatenPower){
                    res[j].isDemocracy = true;
                }
            }

            if (cities[i].s < getStrength(cities[j], cities[i])){
                if (res[i].threatenPower < getStrength(cities[j], cities[i])){
                    res[i].threatenPower = getStrength(cities[j], cities[i]);
                    res[i].leaderCountry = j;
                    res[i].isDemocracy = false;
                } else if (res[i].threatenPower == getStrength(cities[j], cities[i])){
                    res[i].isDemocracy = true;
                }
            }
        }
    }

    for(int i = 0; i < n; i++){
        if (res[i].isDemocracy) cout << 'D' << endl;
        else if (res[i].leaderCountry == i) cout << 'K' << endl;
        else{
            int pointer = i;
            while (res[pointer].leaderCountry != pointer) pointer = res[pointer].leaderCountry;
            cout << pointer + 1 << endl;
        }
    }


		

}

int main(){

	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int testcases = 1;

	// cin >> testcases;

	while(testcases--){
		solve();
	}

	return 0;

}
#Verdict Execution timeMemoryGrader output
Fetching results...