\(N\)의 범위가 최대 50이기 때문에, 겁 먹지 말고 브루트 포스로 \(O(n^2)\)에 해결하자.

문제에서 원하는 대로 구현만 해주면 쉽게 해결 가능하다.

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int INF = 2147483647;
const int MAX = 10e+8;

ll gcd(ll a, ll b) { for (; b; a %= b, swap(a, b)); return a; }

int cnt[51] = { 0, }; // 나보다 덩치가 큰 사람의 명수를 담는 배열
pair<int, int> spec[51]; // 나의 키, 몸무게 저장

int main() {
	ios::ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	
	int n;
	cin >> n;
	
	for (int i = 0; i < n; i++) cin >> spec[i].first >> spec[i].second;
	
	for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) {
    	 // i가 j보다 덩치가 큰 경우
		if (spec[i].first > spec[j].first && spec[i].second > spec[j].second) cnt[j]++;
         // i보다 j가 덩치가 큰 경우
		else if (spec[i].first < spec[j].first && spec[i].second < spec[j].second) cnt[i]++;
	}

	for (int i = 0; i < n; i++) cout << cnt[i] + 1 << ' ';

	return 0;
}

+ Recent posts