Submission #729317

# Submission time Handle Problem Language Result Execution time Memory
729317 2023-04-23T19:17:26 Z Karpin Countries (BOI06_countries) C++14
100 / 100
4 ms 340 KB
#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 time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 4 ms 324 KB Output is correct
9 Correct 3 ms 340 KB Output is correct
10 Correct 4 ms 332 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 324 KB Output is correct
15 Correct 2 ms 324 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 3 ms 340 KB Output is correct
18 Correct 4 ms 340 KB Output is correct
19 Correct 4 ms 340 KB Output is correct
20 Correct 4 ms 340 KB Output is correct