답안 #572458

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
572458 2022-06-04T12:22:13 Z valerikk Diversity (CEOI21_diversity) C++17
64 / 100
49 ms 6416 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.rbegin(), x.rend());

	int k = x.size();

	deque<int> q;
	for (int i = 0; i < k; ++i) {
		if (i & 1)
			q.push_front(x[i]);
		else
			q.push_back(x[i]);
	}
 
	x.clear();
	for (int i : q)
		x.push_back(i);
 
	long long ans = n * 1ll * (n + 1) / 2 * k;
	
	long long sum = 0;
	for (int i = 0; i < k; ++i) {
		ans -= sum * (sum + 1) / 2;
		sum += x[i];
	}
	sum = 0;
	for (int i = k - 1; i >= 0; --i) {
		ans -= sum * (sum + 1) / 2;
		sum += x[i];
	}
 
	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 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 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 1 ms 340 KB Output is correct
4 Correct 5 ms 724 KB Output is correct
5 Correct 11 ms 1124 KB Output is correct
6 Correct 19 ms 1516 KB Output is correct
7 Correct 15 ms 1516 KB Output is correct
8 Correct 19 ms 1520 KB Output is correct
9 Correct 15 ms 1520 KB Output is correct
10 Correct 16 ms 1516 KB Output is correct
11 Correct 16 ms 1512 KB Output is correct
12 Correct 16 ms 1508 KB Output is correct
13 Correct 16 ms 1512 KB Output is correct
14 Correct 15 ms 1516 KB Output is correct
15 Correct 17 ms 1512 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 1 ms 340 KB Output is correct
4 Correct 5 ms 724 KB Output is correct
5 Correct 11 ms 1124 KB Output is correct
6 Correct 19 ms 1516 KB Output is correct
7 Correct 15 ms 1516 KB Output is correct
8 Correct 19 ms 1520 KB Output is correct
9 Correct 15 ms 1520 KB Output is correct
10 Correct 16 ms 1516 KB Output is correct
11 Correct 16 ms 1512 KB Output is correct
12 Correct 16 ms 1508 KB Output is correct
13 Correct 16 ms 1512 KB Output is correct
14 Correct 15 ms 1516 KB Output is correct
15 Correct 17 ms 1512 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 6 ms 980 KB Output is correct
20 Correct 12 ms 1632 KB Output is correct
21 Correct 18 ms 2340 KB Output is correct
22 Correct 18 ms 2268 KB Output is correct
23 Correct 20 ms 2276 KB Output is correct
24 Correct 17 ms 2264 KB Output is correct
25 Correct 17 ms 2268 KB Output is correct
26 Correct 18 ms 2260 KB Output is correct
27 Correct 18 ms 2272 KB Output is correct
28 Correct 17 ms 2228 KB Output is correct
29 Correct 18 ms 2264 KB Output is correct
30 Correct 17 ms 2264 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 1 ms 340 KB Output is correct
4 Correct 5 ms 724 KB Output is correct
5 Correct 11 ms 1124 KB Output is correct
6 Correct 19 ms 1516 KB Output is correct
7 Correct 15 ms 1516 KB Output is correct
8 Correct 19 ms 1520 KB Output is correct
9 Correct 15 ms 1520 KB Output is correct
10 Correct 16 ms 1516 KB Output is correct
11 Correct 16 ms 1512 KB Output is correct
12 Correct 16 ms 1508 KB Output is correct
13 Correct 16 ms 1512 KB Output is correct
14 Correct 15 ms 1516 KB Output is correct
15 Correct 17 ms 1512 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 6 ms 980 KB Output is correct
20 Correct 12 ms 1632 KB Output is correct
21 Correct 18 ms 2340 KB Output is correct
22 Correct 18 ms 2268 KB Output is correct
23 Correct 20 ms 2276 KB Output is correct
24 Correct 17 ms 2264 KB Output is correct
25 Correct 17 ms 2268 KB Output is correct
26 Correct 18 ms 2260 KB Output is correct
27 Correct 18 ms 2272 KB Output is correct
28 Correct 17 ms 2228 KB Output is correct
29 Correct 18 ms 2264 KB Output is correct
30 Correct 17 ms 2264 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 2 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 4 ms 724 KB Output is correct
38 Correct 4 ms 656 KB Output is correct
39 Correct 7 ms 1112 KB Output is correct
40 Correct 14 ms 1876 KB Output is correct
41 Correct 19 ms 2648 KB Output is correct
42 Correct 21 ms 2640 KB Output is correct
43 Correct 20 ms 2644 KB Output is correct
44 Correct 19 ms 2640 KB Output is correct
45 Correct 20 ms 2648 KB Output is correct
46 Correct 21 ms 2644 KB Output is correct
47 Correct 19 ms 2652 KB Output is correct
48 Correct 20 ms 2644 KB Output is correct
49 Correct 20 ms 2644 KB Output is correct
50 Correct 20 ms 2652 KB Output is correct
51 Correct 21 ms 2656 KB Output is correct
52 Correct 18 ms 2652 KB Output is correct
53 Correct 19 ms 2668 KB Output is correct
54 Correct 19 ms 2644 KB Output is correct
55 Correct 22 ms 2648 KB Output is correct
56 Correct 20 ms 2636 KB Output is correct
57 Correct 22 ms 2656 KB Output is correct
58 Correct 19 ms 2648 KB Output is correct
59 Correct 18 ms 2644 KB Output is correct
60 Correct 19 ms 2648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 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 1 ms 340 KB Output is correct
14 Correct 5 ms 724 KB Output is correct
15 Correct 11 ms 1124 KB Output is correct
16 Correct 19 ms 1516 KB Output is correct
17 Correct 15 ms 1516 KB Output is correct
18 Correct 19 ms 1520 KB Output is correct
19 Correct 15 ms 1520 KB Output is correct
20 Correct 16 ms 1516 KB Output is correct
21 Correct 16 ms 1512 KB Output is correct
22 Correct 16 ms 1508 KB Output is correct
23 Correct 16 ms 1512 KB Output is correct
24 Correct 15 ms 1516 KB Output is correct
25 Correct 17 ms 1512 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 6 ms 980 KB Output is correct
30 Correct 12 ms 1632 KB Output is correct
31 Correct 18 ms 2340 KB Output is correct
32 Correct 18 ms 2268 KB Output is correct
33 Correct 20 ms 2276 KB Output is correct
34 Correct 17 ms 2264 KB Output is correct
35 Correct 17 ms 2268 KB Output is correct
36 Correct 18 ms 2260 KB Output is correct
37 Correct 18 ms 2272 KB Output is correct
38 Correct 17 ms 2228 KB Output is correct
39 Correct 18 ms 2264 KB Output is correct
40 Correct 17 ms 2264 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 2 ms 340 KB Output is correct
47 Correct 4 ms 724 KB Output is correct
48 Correct 4 ms 656 KB Output is correct
49 Correct 7 ms 1112 KB Output is correct
50 Correct 14 ms 1876 KB Output is correct
51 Correct 19 ms 2648 KB Output is correct
52 Correct 21 ms 2640 KB Output is correct
53 Correct 20 ms 2644 KB Output is correct
54 Correct 19 ms 2640 KB Output is correct
55 Correct 20 ms 2648 KB Output is correct
56 Correct 21 ms 2644 KB Output is correct
57 Correct 19 ms 2652 KB Output is correct
58 Correct 20 ms 2644 KB Output is correct
59 Correct 20 ms 2644 KB Output is correct
60 Correct 20 ms 2652 KB Output is correct
61 Correct 21 ms 2656 KB Output is correct
62 Correct 18 ms 2652 KB Output is correct
63 Correct 19 ms 2668 KB Output is correct
64 Correct 19 ms 2644 KB Output is correct
65 Correct 22 ms 2648 KB Output is correct
66 Correct 20 ms 2636 KB Output is correct
67 Correct 22 ms 2656 KB Output is correct
68 Correct 19 ms 2648 KB Output is correct
69 Correct 18 ms 2644 KB Output is correct
70 Correct 19 ms 2648 KB Output is correct
71 Correct 4 ms 724 KB Output is correct
72 Correct 7 ms 724 KB Output is correct
73 Correct 7 ms 756 KB Output is correct
74 Correct 5 ms 724 KB Output is correct
75 Correct 5 ms 724 KB Output is correct
76 Correct 8 ms 1224 KB Output is correct
77 Correct 8 ms 1200 KB Output is correct
78 Correct 9 ms 1228 KB Output is correct
79 Correct 8 ms 1232 KB Output is correct
80 Correct 12 ms 1232 KB Output is correct
81 Correct 15 ms 2136 KB Output is correct
82 Correct 15 ms 2132 KB Output is correct
83 Correct 15 ms 2140 KB Output is correct
84 Correct 15 ms 2132 KB Output is correct
85 Correct 15 ms 2136 KB Output is correct
86 Correct 16 ms 2444 KB Output is correct
87 Correct 17 ms 2508 KB Output is correct
88 Correct 16 ms 2396 KB Output is correct
89 Correct 17 ms 2376 KB Output is correct
90 Correct 16 ms 2388 KB Output is correct
91 Correct 26 ms 4316 KB Output is correct
92 Correct 26 ms 4308 KB Output is correct
93 Correct 26 ms 4432 KB Output is correct
94 Correct 28 ms 4312 KB Output is correct
95 Correct 29 ms 4436 KB Output is correct
96 Correct 34 ms 5700 KB Output is correct
97 Correct 38 ms 5716 KB Output is correct
98 Correct 32 ms 5708 KB Output is correct
99 Correct 34 ms 5684 KB Output is correct
100 Correct 33 ms 5792 KB Output is correct
101 Correct 31 ms 5712 KB Output is correct
102 Correct 32 ms 5692 KB Output is correct
103 Correct 33 ms 5716 KB Output is correct
104 Correct 32 ms 5720 KB Output is correct
105 Correct 32 ms 5704 KB Output is correct
106 Correct 32 ms 6324 KB Output is correct
107 Correct 31 ms 6340 KB Output is correct
108 Correct 33 ms 6372 KB Output is correct
109 Correct 48 ms 6340 KB Output is correct
110 Correct 32 ms 6340 KB Output is correct
111 Correct 36 ms 6356 KB Output is correct
112 Correct 32 ms 6344 KB Output is correct
113 Correct 32 ms 6340 KB Output is correct
114 Correct 33 ms 6416 KB Output is correct
115 Correct 49 ms 6344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 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 1 ms 340 KB Output is correct
14 Correct 5 ms 724 KB Output is correct
15 Correct 11 ms 1124 KB Output is correct
16 Correct 19 ms 1516 KB Output is correct
17 Correct 15 ms 1516 KB Output is correct
18 Correct 19 ms 1520 KB Output is correct
19 Correct 15 ms 1520 KB Output is correct
20 Correct 16 ms 1516 KB Output is correct
21 Correct 16 ms 1512 KB Output is correct
22 Correct 16 ms 1508 KB Output is correct
23 Correct 16 ms 1512 KB Output is correct
24 Correct 15 ms 1516 KB Output is correct
25 Correct 17 ms 1512 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 6 ms 980 KB Output is correct
30 Correct 12 ms 1632 KB Output is correct
31 Correct 18 ms 2340 KB Output is correct
32 Correct 18 ms 2268 KB Output is correct
33 Correct 20 ms 2276 KB Output is correct
34 Correct 17 ms 2264 KB Output is correct
35 Correct 17 ms 2268 KB Output is correct
36 Correct 18 ms 2260 KB Output is correct
37 Correct 18 ms 2272 KB Output is correct
38 Correct 17 ms 2228 KB Output is correct
39 Correct 18 ms 2264 KB Output is correct
40 Correct 17 ms 2264 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 2 ms 340 KB Output is correct
47 Correct 4 ms 724 KB Output is correct
48 Correct 4 ms 656 KB Output is correct
49 Correct 7 ms 1112 KB Output is correct
50 Correct 14 ms 1876 KB Output is correct
51 Correct 19 ms 2648 KB Output is correct
52 Correct 21 ms 2640 KB Output is correct
53 Correct 20 ms 2644 KB Output is correct
54 Correct 19 ms 2640 KB Output is correct
55 Correct 20 ms 2648 KB Output is correct
56 Correct 21 ms 2644 KB Output is correct
57 Correct 19 ms 2652 KB Output is correct
58 Correct 20 ms 2644 KB Output is correct
59 Correct 20 ms 2644 KB Output is correct
60 Correct 20 ms 2652 KB Output is correct
61 Correct 21 ms 2656 KB Output is correct
62 Correct 18 ms 2652 KB Output is correct
63 Correct 19 ms 2668 KB Output is correct
64 Correct 19 ms 2644 KB Output is correct
65 Correct 22 ms 2648 KB Output is correct
66 Correct 20 ms 2636 KB Output is correct
67 Correct 22 ms 2656 KB Output is correct
68 Correct 19 ms 2648 KB Output is correct
69 Correct 18 ms 2644 KB Output is correct
70 Correct 19 ms 2648 KB Output is correct
71 Correct 4 ms 724 KB Output is correct
72 Correct 7 ms 724 KB Output is correct
73 Correct 7 ms 756 KB Output is correct
74 Correct 5 ms 724 KB Output is correct
75 Correct 5 ms 724 KB Output is correct
76 Correct 8 ms 1224 KB Output is correct
77 Correct 8 ms 1200 KB Output is correct
78 Correct 9 ms 1228 KB Output is correct
79 Correct 8 ms 1232 KB Output is correct
80 Correct 12 ms 1232 KB Output is correct
81 Correct 15 ms 2136 KB Output is correct
82 Correct 15 ms 2132 KB Output is correct
83 Correct 15 ms 2140 KB Output is correct
84 Correct 15 ms 2132 KB Output is correct
85 Correct 15 ms 2136 KB Output is correct
86 Correct 16 ms 2444 KB Output is correct
87 Correct 17 ms 2508 KB Output is correct
88 Correct 16 ms 2396 KB Output is correct
89 Correct 17 ms 2376 KB Output is correct
90 Correct 16 ms 2388 KB Output is correct
91 Correct 26 ms 4316 KB Output is correct
92 Correct 26 ms 4308 KB Output is correct
93 Correct 26 ms 4432 KB Output is correct
94 Correct 28 ms 4312 KB Output is correct
95 Correct 29 ms 4436 KB Output is correct
96 Correct 34 ms 5700 KB Output is correct
97 Correct 38 ms 5716 KB Output is correct
98 Correct 32 ms 5708 KB Output is correct
99 Correct 34 ms 5684 KB Output is correct
100 Correct 33 ms 5792 KB Output is correct
101 Correct 31 ms 5712 KB Output is correct
102 Correct 32 ms 5692 KB Output is correct
103 Correct 33 ms 5716 KB Output is correct
104 Correct 32 ms 5720 KB Output is correct
105 Correct 32 ms 5704 KB Output is correct
106 Correct 32 ms 6324 KB Output is correct
107 Correct 31 ms 6340 KB Output is correct
108 Correct 33 ms 6372 KB Output is correct
109 Correct 48 ms 6340 KB Output is correct
110 Correct 32 ms 6340 KB Output is correct
111 Correct 36 ms 6356 KB Output is correct
112 Correct 32 ms 6344 KB Output is correct
113 Correct 32 ms 6340 KB Output is correct
114 Correct 33 ms 6416 KB Output is correct
115 Correct 49 ms 6344 KB Output is correct
116 Incorrect 2 ms 480 KB Output isn't correct
117 Halted 0 ms 0 KB -