답안 #569485

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
569485 2022-05-27T12:25:16 Z aryan12 Diversity (CEOI21_diversity) C++17
64 / 100
60 ms 14432 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
 
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
 
const int N = 3e5 + 5;
vector<int> cnt(N, 0);
 
void Solve() 
{
	int n, q;
	cin >> n >> q;
	vector<int> a(n);
	vector<int> cnt(N, 0);
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		cnt[a[i]]++;
	}
	vector<int> idx(N, 0);
	for(int i = 0; i < N; i++)
	{
		idx[i] = i;
	}
	sort(idx.begin(), idx.end(), [&](int i, int j)
	{
		return cnt[i] < cnt[j];
	});
	vector<int> ans(N);
	int l = 1, r = n;
	for(int i = 0; i < N; i++)
	{
		for(int j = 0; j < cnt[idx[i]]; j++)
		{
			if(i % 2 == 1) ans[l++] = idx[i];
			else ans[r--] = idx[i];
		}
	}
	vector<int> sum(n + 1, 0);
	sum[0] = 0;
	for(int i = 1; i <= n; i++)
	{
		sum[i] = sum[i - 1] + 1;
		if(i == 1 || ans[i] != ans[i - 1])
		{
			sum[i] += (i - 1);
		}
	}
	int res = 0;
	for(int i = 1; i <= n; i++)
	{
		res += sum[i];
	}
	cout << res << "\n";
}
 
int32_t main() 
{
	auto begin = std::chrono::high_resolution_clock::now();
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
	// cin >> t;
	for(int i = 1; i <= t; i++) 
	{
		//cout << "Case #" << i << ": ";
		Solve();
	}
	auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 9684 KB Output is correct
2 Correct 10 ms 9684 KB Output is correct
3 Correct 10 ms 9684 KB Output is correct
4 Correct 8 ms 9676 KB Output is correct
5 Correct 10 ms 9684 KB Output is correct
6 Correct 9 ms 9684 KB Output is correct
7 Correct 9 ms 9684 KB Output is correct
8 Correct 9 ms 9684 KB Output is correct
9 Correct 10 ms 9680 KB Output is correct
10 Correct 9 ms 9684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 9680 KB Output is correct
2 Correct 10 ms 9692 KB Output is correct
3 Correct 11 ms 9768 KB Output is correct
4 Correct 19 ms 11232 KB Output is correct
5 Correct 23 ms 12756 KB Output is correct
6 Correct 30 ms 14284 KB Output is correct
7 Correct 24 ms 14284 KB Output is correct
8 Correct 29 ms 14328 KB Output is correct
9 Correct 29 ms 14424 KB Output is correct
10 Correct 26 ms 14420 KB Output is correct
11 Correct 29 ms 14308 KB Output is correct
12 Correct 26 ms 14420 KB Output is correct
13 Correct 25 ms 14284 KB Output is correct
14 Correct 27 ms 14284 KB Output is correct
15 Correct 27 ms 14408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 9680 KB Output is correct
2 Correct 10 ms 9692 KB Output is correct
3 Correct 11 ms 9768 KB Output is correct
4 Correct 19 ms 11232 KB Output is correct
5 Correct 23 ms 12756 KB Output is correct
6 Correct 30 ms 14284 KB Output is correct
7 Correct 24 ms 14284 KB Output is correct
8 Correct 29 ms 14328 KB Output is correct
9 Correct 29 ms 14424 KB Output is correct
10 Correct 26 ms 14420 KB Output is correct
11 Correct 29 ms 14308 KB Output is correct
12 Correct 26 ms 14420 KB Output is correct
13 Correct 25 ms 14284 KB Output is correct
14 Correct 27 ms 14284 KB Output is correct
15 Correct 27 ms 14408 KB Output is correct
16 Correct 10 ms 9684 KB Output is correct
17 Correct 10 ms 9684 KB Output is correct
18 Correct 9 ms 9812 KB Output is correct
19 Correct 14 ms 11280 KB Output is correct
20 Correct 24 ms 12748 KB Output is correct
21 Correct 29 ms 14432 KB Output is correct
22 Correct 27 ms 14416 KB Output is correct
23 Correct 28 ms 14420 KB Output is correct
24 Correct 34 ms 14284 KB Output is correct
25 Correct 32 ms 14288 KB Output is correct
26 Correct 32 ms 14288 KB Output is correct
27 Correct 40 ms 14284 KB Output is correct
28 Correct 28 ms 14280 KB Output is correct
29 Correct 29 ms 14288 KB Output is correct
30 Correct 27 ms 14324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 9680 KB Output is correct
2 Correct 10 ms 9692 KB Output is correct
3 Correct 11 ms 9768 KB Output is correct
4 Correct 19 ms 11232 KB Output is correct
5 Correct 23 ms 12756 KB Output is correct
6 Correct 30 ms 14284 KB Output is correct
7 Correct 24 ms 14284 KB Output is correct
8 Correct 29 ms 14328 KB Output is correct
9 Correct 29 ms 14424 KB Output is correct
10 Correct 26 ms 14420 KB Output is correct
11 Correct 29 ms 14308 KB Output is correct
12 Correct 26 ms 14420 KB Output is correct
13 Correct 25 ms 14284 KB Output is correct
14 Correct 27 ms 14284 KB Output is correct
15 Correct 27 ms 14408 KB Output is correct
16 Correct 10 ms 9684 KB Output is correct
17 Correct 10 ms 9684 KB Output is correct
18 Correct 9 ms 9812 KB Output is correct
19 Correct 14 ms 11280 KB Output is correct
20 Correct 24 ms 12748 KB Output is correct
21 Correct 29 ms 14432 KB Output is correct
22 Correct 27 ms 14416 KB Output is correct
23 Correct 28 ms 14420 KB Output is correct
24 Correct 34 ms 14284 KB Output is correct
25 Correct 32 ms 14288 KB Output is correct
26 Correct 32 ms 14288 KB Output is correct
27 Correct 40 ms 14284 KB Output is correct
28 Correct 28 ms 14280 KB Output is correct
29 Correct 29 ms 14288 KB Output is correct
30 Correct 27 ms 14324 KB Output is correct
31 Correct 9 ms 9684 KB Output is correct
32 Correct 9 ms 9692 KB Output is correct
33 Correct 10 ms 9696 KB Output is correct
34 Correct 9 ms 9812 KB Output is correct
35 Correct 9 ms 9812 KB Output is correct
36 Correct 11 ms 9840 KB Output is correct
37 Correct 14 ms 10420 KB Output is correct
38 Correct 12 ms 10452 KB Output is correct
39 Correct 18 ms 11220 KB Output is correct
40 Correct 24 ms 12756 KB Output is correct
41 Correct 35 ms 14404 KB Output is correct
42 Correct 34 ms 14280 KB Output is correct
43 Correct 29 ms 14416 KB Output is correct
44 Correct 29 ms 14284 KB Output is correct
45 Correct 29 ms 14284 KB Output is correct
46 Correct 29 ms 14336 KB Output is correct
47 Correct 29 ms 14288 KB Output is correct
48 Correct 28 ms 14424 KB Output is correct
49 Correct 33 ms 14420 KB Output is correct
50 Correct 41 ms 14288 KB Output is correct
51 Correct 33 ms 14280 KB Output is correct
52 Correct 29 ms 14420 KB Output is correct
53 Correct 29 ms 14316 KB Output is correct
54 Correct 29 ms 14344 KB Output is correct
55 Correct 29 ms 14332 KB Output is correct
56 Correct 29 ms 14284 KB Output is correct
57 Correct 29 ms 14288 KB Output is correct
58 Correct 31 ms 14288 KB Output is correct
59 Correct 32 ms 14312 KB Output is correct
60 Correct 41 ms 14308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 9684 KB Output is correct
2 Correct 10 ms 9684 KB Output is correct
3 Correct 10 ms 9684 KB Output is correct
4 Correct 8 ms 9676 KB Output is correct
5 Correct 10 ms 9684 KB Output is correct
6 Correct 9 ms 9684 KB Output is correct
7 Correct 9 ms 9684 KB Output is correct
8 Correct 9 ms 9684 KB Output is correct
9 Correct 10 ms 9680 KB Output is correct
10 Correct 9 ms 9684 KB Output is correct
11 Correct 9 ms 9680 KB Output is correct
12 Correct 10 ms 9692 KB Output is correct
13 Correct 11 ms 9768 KB Output is correct
14 Correct 19 ms 11232 KB Output is correct
15 Correct 23 ms 12756 KB Output is correct
16 Correct 30 ms 14284 KB Output is correct
17 Correct 24 ms 14284 KB Output is correct
18 Correct 29 ms 14328 KB Output is correct
19 Correct 29 ms 14424 KB Output is correct
20 Correct 26 ms 14420 KB Output is correct
21 Correct 29 ms 14308 KB Output is correct
22 Correct 26 ms 14420 KB Output is correct
23 Correct 25 ms 14284 KB Output is correct
24 Correct 27 ms 14284 KB Output is correct
25 Correct 27 ms 14408 KB Output is correct
26 Correct 10 ms 9684 KB Output is correct
27 Correct 10 ms 9684 KB Output is correct
28 Correct 9 ms 9812 KB Output is correct
29 Correct 14 ms 11280 KB Output is correct
30 Correct 24 ms 12748 KB Output is correct
31 Correct 29 ms 14432 KB Output is correct
32 Correct 27 ms 14416 KB Output is correct
33 Correct 28 ms 14420 KB Output is correct
34 Correct 34 ms 14284 KB Output is correct
35 Correct 32 ms 14288 KB Output is correct
36 Correct 32 ms 14288 KB Output is correct
37 Correct 40 ms 14284 KB Output is correct
38 Correct 28 ms 14280 KB Output is correct
39 Correct 29 ms 14288 KB Output is correct
40 Correct 27 ms 14324 KB Output is correct
41 Correct 9 ms 9684 KB Output is correct
42 Correct 9 ms 9692 KB Output is correct
43 Correct 10 ms 9696 KB Output is correct
44 Correct 9 ms 9812 KB Output is correct
45 Correct 9 ms 9812 KB Output is correct
46 Correct 11 ms 9840 KB Output is correct
47 Correct 14 ms 10420 KB Output is correct
48 Correct 12 ms 10452 KB Output is correct
49 Correct 18 ms 11220 KB Output is correct
50 Correct 24 ms 12756 KB Output is correct
51 Correct 35 ms 14404 KB Output is correct
52 Correct 34 ms 14280 KB Output is correct
53 Correct 29 ms 14416 KB Output is correct
54 Correct 29 ms 14284 KB Output is correct
55 Correct 29 ms 14284 KB Output is correct
56 Correct 29 ms 14336 KB Output is correct
57 Correct 29 ms 14288 KB Output is correct
58 Correct 28 ms 14424 KB Output is correct
59 Correct 33 ms 14420 KB Output is correct
60 Correct 41 ms 14288 KB Output is correct
61 Correct 33 ms 14280 KB Output is correct
62 Correct 29 ms 14420 KB Output is correct
63 Correct 29 ms 14316 KB Output is correct
64 Correct 29 ms 14344 KB Output is correct
65 Correct 29 ms 14332 KB Output is correct
66 Correct 29 ms 14284 KB Output is correct
67 Correct 29 ms 14288 KB Output is correct
68 Correct 31 ms 14288 KB Output is correct
69 Correct 32 ms 14312 KB Output is correct
70 Correct 41 ms 14308 KB Output is correct
71 Correct 14 ms 10452 KB Output is correct
72 Correct 14 ms 10460 KB Output is correct
73 Correct 13 ms 10456 KB Output is correct
74 Correct 13 ms 10416 KB Output is correct
75 Correct 13 ms 10468 KB Output is correct
76 Correct 20 ms 11220 KB Output is correct
77 Correct 16 ms 11196 KB Output is correct
78 Correct 17 ms 11280 KB Output is correct
79 Correct 16 ms 11220 KB Output is correct
80 Correct 16 ms 11220 KB Output is correct
81 Correct 37 ms 12748 KB Output is correct
82 Correct 27 ms 12756 KB Output is correct
83 Correct 26 ms 12736 KB Output is correct
84 Correct 26 ms 12756 KB Output is correct
85 Correct 24 ms 12756 KB Output is correct
86 Correct 26 ms 12736 KB Output is correct
87 Correct 25 ms 12788 KB Output is correct
88 Correct 25 ms 12756 KB Output is correct
89 Correct 26 ms 12740 KB Output is correct
90 Correct 25 ms 12744 KB Output is correct
91 Correct 37 ms 14420 KB Output is correct
92 Correct 41 ms 14412 KB Output is correct
93 Correct 45 ms 14416 KB Output is correct
94 Correct 54 ms 14280 KB Output is correct
95 Correct 35 ms 14280 KB Output is correct
96 Correct 37 ms 14284 KB Output is correct
97 Correct 38 ms 14288 KB Output is correct
98 Correct 40 ms 14376 KB Output is correct
99 Correct 37 ms 14428 KB Output is correct
100 Correct 47 ms 14284 KB Output is correct
101 Correct 50 ms 14284 KB Output is correct
102 Correct 42 ms 14368 KB Output is correct
103 Correct 38 ms 14332 KB Output is correct
104 Correct 37 ms 14420 KB Output is correct
105 Correct 38 ms 14284 KB Output is correct
106 Correct 49 ms 14400 KB Output is correct
107 Correct 37 ms 14404 KB Output is correct
108 Correct 60 ms 14284 KB Output is correct
109 Correct 49 ms 14336 KB Output is correct
110 Correct 39 ms 14404 KB Output is correct
111 Correct 38 ms 14324 KB Output is correct
112 Correct 38 ms 14404 KB Output is correct
113 Correct 38 ms 14312 KB Output is correct
114 Correct 43 ms 14280 KB Output is correct
115 Correct 38 ms 14284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 9684 KB Output is correct
2 Correct 10 ms 9684 KB Output is correct
3 Correct 10 ms 9684 KB Output is correct
4 Correct 8 ms 9676 KB Output is correct
5 Correct 10 ms 9684 KB Output is correct
6 Correct 9 ms 9684 KB Output is correct
7 Correct 9 ms 9684 KB Output is correct
8 Correct 9 ms 9684 KB Output is correct
9 Correct 10 ms 9680 KB Output is correct
10 Correct 9 ms 9684 KB Output is correct
11 Correct 9 ms 9680 KB Output is correct
12 Correct 10 ms 9692 KB Output is correct
13 Correct 11 ms 9768 KB Output is correct
14 Correct 19 ms 11232 KB Output is correct
15 Correct 23 ms 12756 KB Output is correct
16 Correct 30 ms 14284 KB Output is correct
17 Correct 24 ms 14284 KB Output is correct
18 Correct 29 ms 14328 KB Output is correct
19 Correct 29 ms 14424 KB Output is correct
20 Correct 26 ms 14420 KB Output is correct
21 Correct 29 ms 14308 KB Output is correct
22 Correct 26 ms 14420 KB Output is correct
23 Correct 25 ms 14284 KB Output is correct
24 Correct 27 ms 14284 KB Output is correct
25 Correct 27 ms 14408 KB Output is correct
26 Correct 10 ms 9684 KB Output is correct
27 Correct 10 ms 9684 KB Output is correct
28 Correct 9 ms 9812 KB Output is correct
29 Correct 14 ms 11280 KB Output is correct
30 Correct 24 ms 12748 KB Output is correct
31 Correct 29 ms 14432 KB Output is correct
32 Correct 27 ms 14416 KB Output is correct
33 Correct 28 ms 14420 KB Output is correct
34 Correct 34 ms 14284 KB Output is correct
35 Correct 32 ms 14288 KB Output is correct
36 Correct 32 ms 14288 KB Output is correct
37 Correct 40 ms 14284 KB Output is correct
38 Correct 28 ms 14280 KB Output is correct
39 Correct 29 ms 14288 KB Output is correct
40 Correct 27 ms 14324 KB Output is correct
41 Correct 9 ms 9684 KB Output is correct
42 Correct 9 ms 9692 KB Output is correct
43 Correct 10 ms 9696 KB Output is correct
44 Correct 9 ms 9812 KB Output is correct
45 Correct 9 ms 9812 KB Output is correct
46 Correct 11 ms 9840 KB Output is correct
47 Correct 14 ms 10420 KB Output is correct
48 Correct 12 ms 10452 KB Output is correct
49 Correct 18 ms 11220 KB Output is correct
50 Correct 24 ms 12756 KB Output is correct
51 Correct 35 ms 14404 KB Output is correct
52 Correct 34 ms 14280 KB Output is correct
53 Correct 29 ms 14416 KB Output is correct
54 Correct 29 ms 14284 KB Output is correct
55 Correct 29 ms 14284 KB Output is correct
56 Correct 29 ms 14336 KB Output is correct
57 Correct 29 ms 14288 KB Output is correct
58 Correct 28 ms 14424 KB Output is correct
59 Correct 33 ms 14420 KB Output is correct
60 Correct 41 ms 14288 KB Output is correct
61 Correct 33 ms 14280 KB Output is correct
62 Correct 29 ms 14420 KB Output is correct
63 Correct 29 ms 14316 KB Output is correct
64 Correct 29 ms 14344 KB Output is correct
65 Correct 29 ms 14332 KB Output is correct
66 Correct 29 ms 14284 KB Output is correct
67 Correct 29 ms 14288 KB Output is correct
68 Correct 31 ms 14288 KB Output is correct
69 Correct 32 ms 14312 KB Output is correct
70 Correct 41 ms 14308 KB Output is correct
71 Correct 14 ms 10452 KB Output is correct
72 Correct 14 ms 10460 KB Output is correct
73 Correct 13 ms 10456 KB Output is correct
74 Correct 13 ms 10416 KB Output is correct
75 Correct 13 ms 10468 KB Output is correct
76 Correct 20 ms 11220 KB Output is correct
77 Correct 16 ms 11196 KB Output is correct
78 Correct 17 ms 11280 KB Output is correct
79 Correct 16 ms 11220 KB Output is correct
80 Correct 16 ms 11220 KB Output is correct
81 Correct 37 ms 12748 KB Output is correct
82 Correct 27 ms 12756 KB Output is correct
83 Correct 26 ms 12736 KB Output is correct
84 Correct 26 ms 12756 KB Output is correct
85 Correct 24 ms 12756 KB Output is correct
86 Correct 26 ms 12736 KB Output is correct
87 Correct 25 ms 12788 KB Output is correct
88 Correct 25 ms 12756 KB Output is correct
89 Correct 26 ms 12740 KB Output is correct
90 Correct 25 ms 12744 KB Output is correct
91 Correct 37 ms 14420 KB Output is correct
92 Correct 41 ms 14412 KB Output is correct
93 Correct 45 ms 14416 KB Output is correct
94 Correct 54 ms 14280 KB Output is correct
95 Correct 35 ms 14280 KB Output is correct
96 Correct 37 ms 14284 KB Output is correct
97 Correct 38 ms 14288 KB Output is correct
98 Correct 40 ms 14376 KB Output is correct
99 Correct 37 ms 14428 KB Output is correct
100 Correct 47 ms 14284 KB Output is correct
101 Correct 50 ms 14284 KB Output is correct
102 Correct 42 ms 14368 KB Output is correct
103 Correct 38 ms 14332 KB Output is correct
104 Correct 37 ms 14420 KB Output is correct
105 Correct 38 ms 14284 KB Output is correct
106 Correct 49 ms 14400 KB Output is correct
107 Correct 37 ms 14404 KB Output is correct
108 Correct 60 ms 14284 KB Output is correct
109 Correct 49 ms 14336 KB Output is correct
110 Correct 39 ms 14404 KB Output is correct
111 Correct 38 ms 14324 KB Output is correct
112 Correct 38 ms 14404 KB Output is correct
113 Correct 38 ms 14312 KB Output is correct
114 Correct 43 ms 14280 KB Output is correct
115 Correct 38 ms 14284 KB Output is correct
116 Incorrect 15 ms 9812 KB Output isn't correct
117 Halted 0 ms 0 KB -