답안 #572457

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
572457 2022-06-04T12:21:29 Z valerikk Diversity (CEOI21_diversity) C++17
14 / 100
7000 ms 2172 KB
#include <bits/stdc++.h>

using namespace std;

int cnt[300001];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n, Q;
	cin >> n >> Q;

	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}

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

	vector<int> x;
	for (int i = 1; i <= 300000; ++i) {
		if (cnt[i] > 0) 
			x.push_back(cnt[i]);
	}

	sort(x.begin(), x.end());

	int k = x.size();

	long long ans = 1e18;
	do {
		long long cur = n * 1ll * (n + 1) / 2 * k;
		long long sum = 0;
		for (int i = 0; i < k; ++i) {
			cur -= sum * (sum + 1) / 2;
			sum += x[i];
		}
		sum = 0;
		for (int i = k - 1; i >= 0; --i) {
			cur -= sum * (sum + 1) / 2;
			sum += x[i];
		}
		ans = min(ans, cur);
	} while (next_permutation(x.begin(), x.end()));

	cout << ans << endl;

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 15 ms 832 KB Output is correct
5 Correct 131 ms 1508 KB Output is correct
6 Correct 1374 ms 2172 KB Output is correct
7 Correct 1358 ms 2104 KB Output is correct
8 Correct 1355 ms 2132 KB Output is correct
9 Correct 1340 ms 2132 KB Output is correct
10 Correct 1407 ms 2156 KB Output is correct
11 Correct 1348 ms 2140 KB Output is correct
12 Correct 1338 ms 2168 KB Output is correct
13 Correct 1332 ms 2140 KB Output is correct
14 Correct 1338 ms 2144 KB Output is correct
15 Correct 1345 ms 2132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 15 ms 832 KB Output is correct
5 Correct 131 ms 1508 KB Output is correct
6 Correct 1374 ms 2172 KB Output is correct
7 Correct 1358 ms 2104 KB Output is correct
8 Correct 1355 ms 2132 KB Output is correct
9 Correct 1340 ms 2132 KB Output is correct
10 Correct 1407 ms 2156 KB Output is correct
11 Correct 1348 ms 2140 KB Output is correct
12 Correct 1338 ms 2168 KB Output is correct
13 Correct 1332 ms 2140 KB Output is correct
14 Correct 1338 ms 2144 KB Output is correct
15 Correct 1345 ms 2132 KB Output is correct
16 Correct 2192 ms 308 KB Output is correct
17 Execution timed out 7054 ms 340 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 15 ms 832 KB Output is correct
5 Correct 131 ms 1508 KB Output is correct
6 Correct 1374 ms 2172 KB Output is correct
7 Correct 1358 ms 2104 KB Output is correct
8 Correct 1355 ms 2132 KB Output is correct
9 Correct 1340 ms 2132 KB Output is correct
10 Correct 1407 ms 2156 KB Output is correct
11 Correct 1348 ms 2140 KB Output is correct
12 Correct 1338 ms 2168 KB Output is correct
13 Correct 1332 ms 2140 KB Output is correct
14 Correct 1338 ms 2144 KB Output is correct
15 Correct 1345 ms 2132 KB Output is correct
16 Correct 2192 ms 308 KB Output is correct
17 Execution timed out 7054 ms 340 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 3 ms 340 KB Output is correct
14 Correct 15 ms 832 KB Output is correct
15 Correct 131 ms 1508 KB Output is correct
16 Correct 1374 ms 2172 KB Output is correct
17 Correct 1358 ms 2104 KB Output is correct
18 Correct 1355 ms 2132 KB Output is correct
19 Correct 1340 ms 2132 KB Output is correct
20 Correct 1407 ms 2156 KB Output is correct
21 Correct 1348 ms 2140 KB Output is correct
22 Correct 1338 ms 2168 KB Output is correct
23 Correct 1332 ms 2140 KB Output is correct
24 Correct 1338 ms 2144 KB Output is correct
25 Correct 1345 ms 2132 KB Output is correct
26 Correct 2192 ms 308 KB Output is correct
27 Execution timed out 7054 ms 340 KB Time limit exceeded
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 3 ms 340 KB Output is correct
14 Correct 15 ms 832 KB Output is correct
15 Correct 131 ms 1508 KB Output is correct
16 Correct 1374 ms 2172 KB Output is correct
17 Correct 1358 ms 2104 KB Output is correct
18 Correct 1355 ms 2132 KB Output is correct
19 Correct 1340 ms 2132 KB Output is correct
20 Correct 1407 ms 2156 KB Output is correct
21 Correct 1348 ms 2140 KB Output is correct
22 Correct 1338 ms 2168 KB Output is correct
23 Correct 1332 ms 2140 KB Output is correct
24 Correct 1338 ms 2144 KB Output is correct
25 Correct 1345 ms 2132 KB Output is correct
26 Correct 2192 ms 308 KB Output is correct
27 Execution timed out 7054 ms 340 KB Time limit exceeded
28 Halted 0 ms 0 KB -