답안 #4864

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
4864 2014-01-05T17:46:23 Z tncks0121 별들과 삼각형 (IZhO11_triangle) C++
100 / 100
216 ms 8120 KB
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 
#include <memory.h> 
#include <math.h> 
#include <assert.h> 
#include <stack> 
#include <queue> 
#include <map> 
#include <set> 
#include <algorithm> 
#include <string> 
#include <functional> 
#include <vector> 
#include <deque> 
#include <utility> 
#include <bitset> 
#include <limits.h>  
#include <time.h>

using namespace std; 
typedef long long ll; 
typedef unsigned long long llu; 
typedef double lf;
typedef unsigned int uint;
typedef long double llf;
typedef pair<int, int> pii;

const int N_ = 300005;

int N, X[N_], Y[N_];

int *P[N_];
bool cmpP (const int *a, const int *b) { return *a < *b; }

int CX[N_], CY[N_];
ll res;

int main() {
	int i, j, k;
	
	scanf("%d", &N);
	for(i = 1; i <= N; i++) scanf("%d%d", X+i, Y+i);

	for(i = 1; i <= N; i++) P[i] = &X[i];
	sort(P+1, P+N+1, cmpP);

	for(k = -1, j = 0, i = 1; i <= N; i++) {
		if(k != *P[i]) k = *P[i], ++j;
		*P[i] = j;
	}

	for(i = 1; i <= N; i++) P[i] = &Y[i];
	sort(P+1, P+N+1, cmpP);

	for(k = -1, j = 0, i = 1; i <= N; i++) {
		if(k != *P[i]) k = *P[i], ++j;
		*P[i] = j;
	}

	for(i = 1; i <= N; i++) ++CX[X[i]], ++CY[Y[i]];

	for(i = 1; i <= N; i++) {
		res += (ll) (CX[X[i]] - 1) * (CY[Y[i]] - 1);
	}

	printf("%lld\n", res);
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 8120 KB Output is correct
2 Correct 0 ms 8120 KB Output is correct
3 Correct 0 ms 8120 KB Output is correct
4 Correct 0 ms 8120 KB Output is correct
5 Correct 0 ms 8120 KB Output is correct
6 Correct 0 ms 8120 KB Output is correct
7 Correct 0 ms 8120 KB Output is correct
8 Correct 0 ms 8120 KB Output is correct
9 Correct 0 ms 8120 KB Output is correct
10 Correct 0 ms 8120 KB Output is correct
11 Correct 0 ms 8120 KB Output is correct
12 Correct 4 ms 8120 KB Output is correct
13 Correct 0 ms 8120 KB Output is correct
14 Correct 4 ms 8120 KB Output is correct
15 Correct 64 ms 8120 KB Output is correct
16 Correct 76 ms 8120 KB Output is correct
17 Correct 60 ms 8120 KB Output is correct
18 Correct 68 ms 8120 KB Output is correct
19 Correct 172 ms 8120 KB Output is correct
20 Correct 140 ms 8120 KB Output is correct
21 Correct 208 ms 8120 KB Output is correct
22 Correct 216 ms 8120 KB Output is correct