답안 #149107

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
149107 2019-09-01T05:45:31 Z etyu(#3586, kimjihoon) 함수컵 박물관 (FXCUP4_museum) C++17
100 / 100
156 ms 7528 KB
#include "museum.h"
#include <algorithm>

struct ts
{
	int a, b, c;
	bool operator<(const ts &r) {
		if (a != r.a) return a < r.a;
		if (b != r.b) return b < r.b;
		return c < r.c;
	}
};

ts p[200009];

long long CountSimilarPairs(std::vector<int> B, std::vector<int> T, std::vector<int> G) {
	int N = B.size();
	for (int i = 0; i < N; i++) {
		p[i].a = B[i]; p[i].b = T[i]; p[i].c = G[i];
	}
	long long ans = 0;
	std::sort(p, p + N);
	int c1 = 0, c2 = 0, c3 = 0;
	for (int i = 0; i < N; i++) {
		c1++; c2++; c3++;
		if (i == N - 1 || p[i].a != p[i + 1].a) {
			ans += 1LL * c1 * (c1 - 1) / 2LL;
			c1 = 0;
		}
		if (i == N - 1 || p[i].a != p[i + 1].a || p[i].b != p[i + 1].b) {
			ans -= 1LL * c2 * (c2 - 1) / 2LL;
			c2 = 0;
		}
		if (i == N - 1 || p[i].a != p[i + 1].a || p[i].b != p[i + 1].b || p[i].c != p[i + 1].c) {
			ans += 1LL * c3 * (c3 - 1) / 2LL;
			c3 = 0;
		}
		std::swap(p[i].b, p[i].c); std::swap(p[i].c, p[i].a);
	}
	for (int ti = 0; ti < 2; ti++) {
		std::sort(p, p + N);
		c1 = c2 = 0;
		for (int i = 0; i < N; i++) {
			c1++; c2++;
			if (i == N - 1 || p[i].a != p[i + 1].a) {
				ans += 1LL * c1 * (c1 - 1) / 2LL;
				c1 = 0;
			}
			if (i == N - 1 || p[i].a != p[i + 1].a || p[i].b != p[i + 1].b) {
				ans -= 1LL * c2 * (c2 - 1) / 2LL;
				c2 = 0;
			}
			std::swap(p[i].b, p[i].c); std::swap(p[i].c, p[i].a);
		}
	}
	return ans;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 5 ms 408 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 8 ms 384 KB Output is correct
8 Correct 7 ms 512 KB Output is correct
9 Correct 6 ms 512 KB Output is correct
10 Correct 9 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 5 ms 408 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 8 ms 384 KB Output is correct
8 Correct 7 ms 512 KB Output is correct
9 Correct 6 ms 512 KB Output is correct
10 Correct 9 ms 384 KB Output is correct
11 Correct 10 ms 640 KB Output is correct
12 Correct 21 ms 1424 KB Output is correct
13 Correct 46 ms 2420 KB Output is correct
14 Correct 72 ms 3312 KB Output is correct
15 Correct 97 ms 4848 KB Output is correct
16 Correct 92 ms 7524 KB Output is correct
17 Correct 110 ms 7528 KB Output is correct
18 Correct 152 ms 7528 KB Output is correct
19 Correct 156 ms 7528 KB Output is correct
20 Correct 155 ms 7404 KB Output is correct