답안 #659700

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
659700 2022-11-19T05:33:56 Z Sohsoh84 Diversity (CEOI21_diversity) C++17
64 / 100
881 ms 5728 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

#define all(x)			(x).begin(),(x).end()
#define X			first
#define Y			second
#define sep			' '
#define endl			'\n'
#define debug(x)		cerr << #x << ": " <<  x << endl;

const ll MAXN = 1e6 + 10;
const ll INF = 4e18;

int n, q, cnt[MAXN], A[MAXN];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> q;
	for (int i = 1; i <= n; i++) {
		int A[i];
		cin >> A[i];
		cnt[A[i]]++;
	}

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

	int m = vec.size() - 1;
	sort(all(vec));

	ll s = 0, ans = 0, j = 0;
	for (int i = 1; i <= m; i++) {	
		if (j < s - j) {
			j += vec[i];
			ans += j * (n - j);
		} else ans += (s - j) * (n - s + j);

		s += vec[i];
	}

	cout << ans + 1ll * n * (n + 1) / 2 << 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 2 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 2 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 2 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 81 ms 692 KB Output is correct
5 Correct 349 ms 1064 KB Output is correct
6 Correct 872 ms 1532 KB Output is correct
7 Correct 811 ms 1388 KB Output is correct
8 Correct 827 ms 1412 KB Output is correct
9 Correct 841 ms 1580 KB Output is correct
10 Correct 826 ms 1604 KB Output is correct
11 Correct 790 ms 1472 KB Output is correct
12 Correct 828 ms 1512 KB Output is correct
13 Correct 808 ms 1424 KB Output is correct
14 Correct 773 ms 1556 KB Output is correct
15 Correct 837 ms 1412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 81 ms 692 KB Output is correct
5 Correct 349 ms 1064 KB Output is correct
6 Correct 872 ms 1532 KB Output is correct
7 Correct 811 ms 1388 KB Output is correct
8 Correct 827 ms 1412 KB Output is correct
9 Correct 841 ms 1580 KB Output is correct
10 Correct 826 ms 1604 KB Output is correct
11 Correct 790 ms 1472 KB Output is correct
12 Correct 828 ms 1512 KB Output is correct
13 Correct 808 ms 1424 KB Output is correct
14 Correct 773 ms 1556 KB Output is correct
15 Correct 837 ms 1412 KB Output is correct
16 Correct 2 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 81 ms 632 KB Output is correct
20 Correct 354 ms 1092 KB Output is correct
21 Correct 820 ms 1428 KB Output is correct
22 Correct 833 ms 1492 KB Output is correct
23 Correct 784 ms 1612 KB Output is correct
24 Correct 819 ms 1528 KB Output is correct
25 Correct 815 ms 1576 KB Output is correct
26 Correct 827 ms 1556 KB Output is correct
27 Correct 816 ms 1604 KB Output is correct
28 Correct 803 ms 1448 KB Output is correct
29 Correct 845 ms 1460 KB Output is correct
30 Correct 784 ms 1608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 3 ms 340 KB Output is correct
4 Correct 81 ms 692 KB Output is correct
5 Correct 349 ms 1064 KB Output is correct
6 Correct 872 ms 1532 KB Output is correct
7 Correct 811 ms 1388 KB Output is correct
8 Correct 827 ms 1412 KB Output is correct
9 Correct 841 ms 1580 KB Output is correct
10 Correct 826 ms 1604 KB Output is correct
11 Correct 790 ms 1472 KB Output is correct
12 Correct 828 ms 1512 KB Output is correct
13 Correct 808 ms 1424 KB Output is correct
14 Correct 773 ms 1556 KB Output is correct
15 Correct 837 ms 1412 KB Output is correct
16 Correct 2 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 81 ms 632 KB Output is correct
20 Correct 354 ms 1092 KB Output is correct
21 Correct 820 ms 1428 KB Output is correct
22 Correct 833 ms 1492 KB Output is correct
23 Correct 784 ms 1612 KB Output is correct
24 Correct 819 ms 1528 KB Output is correct
25 Correct 815 ms 1576 KB Output is correct
26 Correct 827 ms 1556 KB Output is correct
27 Correct 816 ms 1604 KB Output is correct
28 Correct 803 ms 1448 KB Output is correct
29 Correct 845 ms 1460 KB Output is correct
30 Correct 784 ms 1608 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 340 KB Output is correct
34 Correct 2 ms 340 KB Output is correct
35 Correct 3 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 21 ms 592 KB Output is correct
38 Correct 18 ms 468 KB Output is correct
39 Correct 78 ms 672 KB Output is correct
40 Correct 353 ms 1108 KB Output is correct
41 Correct 822 ms 1532 KB Output is correct
42 Correct 813 ms 1504 KB Output is correct
43 Correct 824 ms 1488 KB Output is correct
44 Correct 849 ms 1484 KB Output is correct
45 Correct 816 ms 1520 KB Output is correct
46 Correct 812 ms 1576 KB Output is correct
47 Correct 831 ms 1444 KB Output is correct
48 Correct 804 ms 1464 KB Output is correct
49 Correct 825 ms 1560 KB Output is correct
50 Correct 835 ms 1416 KB Output is correct
51 Correct 825 ms 1516 KB Output is correct
52 Correct 804 ms 1712 KB Output is correct
53 Correct 806 ms 1568 KB Output is correct
54 Correct 864 ms 1496 KB Output is correct
55 Correct 799 ms 1444 KB Output is correct
56 Correct 802 ms 1564 KB Output is correct
57 Correct 859 ms 1472 KB Output is correct
58 Correct 832 ms 1492 KB Output is correct
59 Correct 822 ms 1492 KB Output is correct
60 Correct 785 ms 1416 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 2 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 2 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 2 ms 212 KB Output is correct
12 Correct 2 ms 212 KB Output is correct
13 Correct 3 ms 340 KB Output is correct
14 Correct 81 ms 692 KB Output is correct
15 Correct 349 ms 1064 KB Output is correct
16 Correct 872 ms 1532 KB Output is correct
17 Correct 811 ms 1388 KB Output is correct
18 Correct 827 ms 1412 KB Output is correct
19 Correct 841 ms 1580 KB Output is correct
20 Correct 826 ms 1604 KB Output is correct
21 Correct 790 ms 1472 KB Output is correct
22 Correct 828 ms 1512 KB Output is correct
23 Correct 808 ms 1424 KB Output is correct
24 Correct 773 ms 1556 KB Output is correct
25 Correct 837 ms 1412 KB Output is correct
26 Correct 2 ms 212 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 81 ms 632 KB Output is correct
30 Correct 354 ms 1092 KB Output is correct
31 Correct 820 ms 1428 KB Output is correct
32 Correct 833 ms 1492 KB Output is correct
33 Correct 784 ms 1612 KB Output is correct
34 Correct 819 ms 1528 KB Output is correct
35 Correct 815 ms 1576 KB Output is correct
36 Correct 827 ms 1556 KB Output is correct
37 Correct 816 ms 1604 KB Output is correct
38 Correct 803 ms 1448 KB Output is correct
39 Correct 845 ms 1460 KB Output is correct
40 Correct 784 ms 1608 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 340 KB Output is correct
44 Correct 2 ms 340 KB Output is correct
45 Correct 3 ms 340 KB Output is correct
46 Correct 2 ms 340 KB Output is correct
47 Correct 21 ms 592 KB Output is correct
48 Correct 18 ms 468 KB Output is correct
49 Correct 78 ms 672 KB Output is correct
50 Correct 353 ms 1108 KB Output is correct
51 Correct 822 ms 1532 KB Output is correct
52 Correct 813 ms 1504 KB Output is correct
53 Correct 824 ms 1488 KB Output is correct
54 Correct 849 ms 1484 KB Output is correct
55 Correct 816 ms 1520 KB Output is correct
56 Correct 812 ms 1576 KB Output is correct
57 Correct 831 ms 1444 KB Output is correct
58 Correct 804 ms 1464 KB Output is correct
59 Correct 825 ms 1560 KB Output is correct
60 Correct 835 ms 1416 KB Output is correct
61 Correct 825 ms 1516 KB Output is correct
62 Correct 804 ms 1712 KB Output is correct
63 Correct 806 ms 1568 KB Output is correct
64 Correct 864 ms 1496 KB Output is correct
65 Correct 799 ms 1444 KB Output is correct
66 Correct 802 ms 1564 KB Output is correct
67 Correct 859 ms 1472 KB Output is correct
68 Correct 832 ms 1492 KB Output is correct
69 Correct 822 ms 1492 KB Output is correct
70 Correct 785 ms 1416 KB Output is correct
71 Correct 19 ms 520 KB Output is correct
72 Correct 18 ms 440 KB Output is correct
73 Correct 18 ms 520 KB Output is correct
74 Correct 18 ms 472 KB Output is correct
75 Correct 17 ms 448 KB Output is correct
76 Correct 79 ms 864 KB Output is correct
77 Correct 85 ms 672 KB Output is correct
78 Correct 87 ms 720 KB Output is correct
79 Correct 83 ms 736 KB Output is correct
80 Correct 82 ms 716 KB Output is correct
81 Correct 353 ms 1140 KB Output is correct
82 Correct 370 ms 1164 KB Output is correct
83 Correct 344 ms 1360 KB Output is correct
84 Correct 371 ms 1128 KB Output is correct
85 Correct 329 ms 1192 KB Output is correct
86 Correct 350 ms 1420 KB Output is correct
87 Correct 347 ms 1296 KB Output is correct
88 Correct 369 ms 1356 KB Output is correct
89 Correct 372 ms 1304 KB Output is correct
90 Correct 317 ms 1356 KB Output is correct
91 Correct 865 ms 2672 KB Output is correct
92 Correct 849 ms 4212 KB Output is correct
93 Correct 822 ms 4344 KB Output is correct
94 Correct 840 ms 4264 KB Output is correct
95 Correct 836 ms 4380 KB Output is correct
96 Correct 806 ms 5312 KB Output is correct
97 Correct 835 ms 5404 KB Output is correct
98 Correct 829 ms 5420 KB Output is correct
99 Correct 842 ms 5428 KB Output is correct
100 Correct 847 ms 5320 KB Output is correct
101 Correct 797 ms 5396 KB Output is correct
102 Correct 856 ms 5416 KB Output is correct
103 Correct 850 ms 5440 KB Output is correct
104 Correct 868 ms 5348 KB Output is correct
105 Correct 843 ms 5244 KB Output is correct
106 Correct 811 ms 5600 KB Output is correct
107 Correct 857 ms 5516 KB Output is correct
108 Correct 881 ms 5528 KB Output is correct
109 Correct 794 ms 5496 KB Output is correct
110 Correct 807 ms 5524 KB Output is correct
111 Correct 826 ms 5632 KB Output is correct
112 Correct 877 ms 5564 KB Output is correct
113 Correct 865 ms 5728 KB Output is correct
114 Correct 838 ms 5676 KB Output is correct
115 Correct 851 ms 5564 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 2 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 2 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 2 ms 212 KB Output is correct
12 Correct 2 ms 212 KB Output is correct
13 Correct 3 ms 340 KB Output is correct
14 Correct 81 ms 692 KB Output is correct
15 Correct 349 ms 1064 KB Output is correct
16 Correct 872 ms 1532 KB Output is correct
17 Correct 811 ms 1388 KB Output is correct
18 Correct 827 ms 1412 KB Output is correct
19 Correct 841 ms 1580 KB Output is correct
20 Correct 826 ms 1604 KB Output is correct
21 Correct 790 ms 1472 KB Output is correct
22 Correct 828 ms 1512 KB Output is correct
23 Correct 808 ms 1424 KB Output is correct
24 Correct 773 ms 1556 KB Output is correct
25 Correct 837 ms 1412 KB Output is correct
26 Correct 2 ms 212 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 81 ms 632 KB Output is correct
30 Correct 354 ms 1092 KB Output is correct
31 Correct 820 ms 1428 KB Output is correct
32 Correct 833 ms 1492 KB Output is correct
33 Correct 784 ms 1612 KB Output is correct
34 Correct 819 ms 1528 KB Output is correct
35 Correct 815 ms 1576 KB Output is correct
36 Correct 827 ms 1556 KB Output is correct
37 Correct 816 ms 1604 KB Output is correct
38 Correct 803 ms 1448 KB Output is correct
39 Correct 845 ms 1460 KB Output is correct
40 Correct 784 ms 1608 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 340 KB Output is correct
44 Correct 2 ms 340 KB Output is correct
45 Correct 3 ms 340 KB Output is correct
46 Correct 2 ms 340 KB Output is correct
47 Correct 21 ms 592 KB Output is correct
48 Correct 18 ms 468 KB Output is correct
49 Correct 78 ms 672 KB Output is correct
50 Correct 353 ms 1108 KB Output is correct
51 Correct 822 ms 1532 KB Output is correct
52 Correct 813 ms 1504 KB Output is correct
53 Correct 824 ms 1488 KB Output is correct
54 Correct 849 ms 1484 KB Output is correct
55 Correct 816 ms 1520 KB Output is correct
56 Correct 812 ms 1576 KB Output is correct
57 Correct 831 ms 1444 KB Output is correct
58 Correct 804 ms 1464 KB Output is correct
59 Correct 825 ms 1560 KB Output is correct
60 Correct 835 ms 1416 KB Output is correct
61 Correct 825 ms 1516 KB Output is correct
62 Correct 804 ms 1712 KB Output is correct
63 Correct 806 ms 1568 KB Output is correct
64 Correct 864 ms 1496 KB Output is correct
65 Correct 799 ms 1444 KB Output is correct
66 Correct 802 ms 1564 KB Output is correct
67 Correct 859 ms 1472 KB Output is correct
68 Correct 832 ms 1492 KB Output is correct
69 Correct 822 ms 1492 KB Output is correct
70 Correct 785 ms 1416 KB Output is correct
71 Correct 19 ms 520 KB Output is correct
72 Correct 18 ms 440 KB Output is correct
73 Correct 18 ms 520 KB Output is correct
74 Correct 18 ms 472 KB Output is correct
75 Correct 17 ms 448 KB Output is correct
76 Correct 79 ms 864 KB Output is correct
77 Correct 85 ms 672 KB Output is correct
78 Correct 87 ms 720 KB Output is correct
79 Correct 83 ms 736 KB Output is correct
80 Correct 82 ms 716 KB Output is correct
81 Correct 353 ms 1140 KB Output is correct
82 Correct 370 ms 1164 KB Output is correct
83 Correct 344 ms 1360 KB Output is correct
84 Correct 371 ms 1128 KB Output is correct
85 Correct 329 ms 1192 KB Output is correct
86 Correct 350 ms 1420 KB Output is correct
87 Correct 347 ms 1296 KB Output is correct
88 Correct 369 ms 1356 KB Output is correct
89 Correct 372 ms 1304 KB Output is correct
90 Correct 317 ms 1356 KB Output is correct
91 Correct 865 ms 2672 KB Output is correct
92 Correct 849 ms 4212 KB Output is correct
93 Correct 822 ms 4344 KB Output is correct
94 Correct 840 ms 4264 KB Output is correct
95 Correct 836 ms 4380 KB Output is correct
96 Correct 806 ms 5312 KB Output is correct
97 Correct 835 ms 5404 KB Output is correct
98 Correct 829 ms 5420 KB Output is correct
99 Correct 842 ms 5428 KB Output is correct
100 Correct 847 ms 5320 KB Output is correct
101 Correct 797 ms 5396 KB Output is correct
102 Correct 856 ms 5416 KB Output is correct
103 Correct 850 ms 5440 KB Output is correct
104 Correct 868 ms 5348 KB Output is correct
105 Correct 843 ms 5244 KB Output is correct
106 Correct 811 ms 5600 KB Output is correct
107 Correct 857 ms 5516 KB Output is correct
108 Correct 881 ms 5528 KB Output is correct
109 Correct 794 ms 5496 KB Output is correct
110 Correct 807 ms 5524 KB Output is correct
111 Correct 826 ms 5632 KB Output is correct
112 Correct 877 ms 5564 KB Output is correct
113 Correct 865 ms 5728 KB Output is correct
114 Correct 838 ms 5676 KB Output is correct
115 Correct 851 ms 5564 KB Output is correct
116 Incorrect 2 ms 468 KB Output isn't correct
117 Halted 0 ms 0 KB -