답안 #21882

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
21882 2017-04-26T16:01:23 Z ulna 별들과 삼각형 (IZhO11_triangle) C++11
0 / 100
0 ms 4376 KB
#include <bits/stdc++.h>
using namespace std;

// why am I so weak

int n;
int x[300055], y[300055];

int main() {
	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		scanf("%d %d", &x[i], &y[i]);
	}

	long long res = 0ll;

	vector<int> vec(n);

	for (int i = 0; i < n; i++) {
		vec[i] = i;
	}

	{
		// find bottom left
		sort(vec.begin(), vec.end(), [&] (int u, int v) {
			if (y[u] != y[v]) return y[u] > y[v];
			return x[u] > x[v];
		});

		map<int, int> c;

		int ac = 0;
		int last = -INT_MAX;

		for (auto u : vec) {
			if (y[u] != last) {
				ac = 0;
			}

			res += 1ll * ac * c[x[u]];

			c[x[u]]++;
			
			ac++;
			last = y[u];
		}
	}

	{
		// find bottom right
		sort(vec.begin(), vec.end(), [&] (int u, int v) {
			if (y[u] != y[v]) return y[u] > y[v];
			return x[u] < x[v];
		});

		map<int, int> c;

		int ac = 0;
		int last = -INT_MAX;

		for (auto u : vec) {
			if (y[u] != last) {
				ac = 0;
			}

			res += 1ll * ac * c[x[u]];

			c[x[u]]++;
			
			ac++;
			last = y[u];
		}
	}

	{
		// find top left
		sort(vec.begin(), vec.end(), [&] (int u, int v) {
			if (y[u] != y[v]) return y[u] > y[v];
			return x[u] < x[v];
		});

		map<int, int> c;

		int ac = 0;
		int last = -INT_MAX;

		for (auto u : vec) {
			if (y[u] != last) {
				ac = 0;
			}

			res += 1ll * ac * c[x[u]];

			c[x[u]]++;
			
			ac++;
			last = y[u];
		}
	}

	{
		// find top right
		sort(vec.begin(), vec.end(), [&] (int u, int v) {
			if (y[u] != y[v]) return y[u] < y[v];
			return x[u] < x[v];
		});

		map<int, int> c;

		int ac = 0;
		int last = -INT_MAX;

		for (auto u : vec) {
			if (y[u] != last) {
				ac = 0;
			}

			res += 1ll * ac * c[x[u]];

			c[x[u]]++;

			ac++;
			last = y[u];
		}
	}

	printf("%lld\n", res);

	return 0;
}

Compilation message

triangle.cpp: In function 'int main()':
triangle.cpp:10:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
triangle.cpp:13:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &x[i], &y[i]);
                               ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4376 KB Output is correct
2 Correct 0 ms 4376 KB Output is correct
3 Correct 0 ms 4376 KB Output is correct
4 Incorrect 0 ms 4376 KB Output isn't correct
5 Halted 0 ms 0 KB -