답안 #142852

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
142852 2019-08-11T14:09:23 Z gs14004 Countries (BOI06_countries) C++17
100 / 100
8 ms 504 KB
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = pair<int, int>;
#define sz(v) ((int)((v).size()))
const int MAXN = 1005;

int n, x[MAXN], y[MAXN], s[MAXN];
string ans[MAXN];
int par[MAXN];

bool cmp(pi a, pi b){
	return 1ll * a.first * b.second < 1ll * b.first * a.second;
}

int main(){
	cin >> n;
	for(int i=0; i<n; i++) cin >> x[i] >> y[i] >> s[i];
	for(int i=0; i<n; i++){
		pi rt(s[i], 1);
		int cnt = 0;
		int pos = -1;
		for(int j=0; j<n; j++){
			if(i == j) continue;
			int dist = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
			pi rat = pi(s[j], dist);
			if(cmp(rt, rat)){
				rt = rat;
				cnt = 0;
			}
			if(!cmp(rt, rat) && !cmp(rat, rt)){
				cnt++;
				pos = j;
			}
		}
		if(!cmp(pi(s[i], 1), rt)){
			ans[i] = "K";
		}
		else{
			if(cnt == 1){
				ans[i] = "?";
				par[i] = pos;
			}
			else{
				ans[i] = "D";
			}
		}
	}
	for(int i=0; i<n; i++){
		if(ans[i] != "?") cout << ans[i] << endl;
		else{
			int pos = i;
			while(ans[pos] == "?") pos = par[pos];
			cout << pos + 1 << endl;
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 4 ms 376 KB Output is correct
5 Correct 4 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 6 ms 380 KB Output is correct
8 Correct 7 ms 376 KB Output is correct
9 Correct 8 ms 376 KB Output is correct
10 Correct 8 ms 376 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 4 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 372 KB Output is correct
17 Correct 6 ms 376 KB Output is correct
18 Correct 7 ms 376 KB Output is correct
19 Correct 7 ms 376 KB Output is correct
20 Correct 8 ms 376 KB Output is correct