답안 #832080

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
832080 2023-08-20T22:04:16 Z QwertyPi Diversity (CEOI21_diversity) C++14
64 / 100
205 ms 22560 KB
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define int long long
using namespace std;

const int MAXN = 3e5 + 11;
int a[MAXN];
int32_t main(){
    int n, q; cin >> n >> q;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }

    map<int, int> c;
    for(int i = 1; i <= n; i++){
        c[a[i]]++;
    }

    vector<int> cnt;
    for(auto [x, y] : c){
        cnt.push_back(y);
    }

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

    int ans = 0;
    for(auto x : cnt){
        ans += x * (x + 1) / 2;
    }

    int s1 = 0, s2 = 0;
    for(auto x : cnt){
        s1 += x; s2 += x * x;
    }

    ans += (s1 * s1 - s2) / 2;

    int l = 0, r = 0;
    for(auto x : cnt){
        if(l > r) swap(l, r);
        ans += l * (n - l); l += x;
    }
    ans += l * (n - l);
    cout << ans << endl;
}

Compilation message

diversity.cpp: In function 'int32_t main()':
diversity.cpp:20:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   20 |     for(auto [x, y] : c){
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 308 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 12 ms 1280 KB Output is correct
5 Correct 24 ms 2288 KB Output is correct
6 Correct 39 ms 3292 KB Output is correct
7 Correct 35 ms 3148 KB Output is correct
8 Correct 37 ms 3216 KB Output is correct
9 Correct 37 ms 3252 KB Output is correct
10 Correct 39 ms 3276 KB Output is correct
11 Correct 38 ms 3272 KB Output is correct
12 Correct 39 ms 3264 KB Output is correct
13 Correct 38 ms 3196 KB Output is correct
14 Correct 37 ms 3192 KB Output is correct
15 Correct 37 ms 3152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 12 ms 1280 KB Output is correct
5 Correct 24 ms 2288 KB Output is correct
6 Correct 39 ms 3292 KB Output is correct
7 Correct 35 ms 3148 KB Output is correct
8 Correct 37 ms 3216 KB Output is correct
9 Correct 37 ms 3252 KB Output is correct
10 Correct 39 ms 3276 KB Output is correct
11 Correct 38 ms 3272 KB Output is correct
12 Correct 39 ms 3264 KB Output is correct
13 Correct 38 ms 3196 KB Output is correct
14 Correct 37 ms 3192 KB Output is correct
15 Correct 37 ms 3152 KB Output is correct
16 Correct 0 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 17 ms 1340 KB Output is correct
20 Correct 34 ms 2372 KB Output is correct
21 Correct 44 ms 3428 KB Output is correct
22 Correct 43 ms 3336 KB Output is correct
23 Correct 43 ms 3428 KB Output is correct
24 Correct 44 ms 3304 KB Output is correct
25 Correct 43 ms 3404 KB Output is correct
26 Correct 43 ms 3380 KB Output is correct
27 Correct 42 ms 3380 KB Output is correct
28 Correct 41 ms 3340 KB Output is correct
29 Correct 42 ms 3276 KB Output is correct
30 Correct 43 ms 3436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 12 ms 1280 KB Output is correct
5 Correct 24 ms 2288 KB Output is correct
6 Correct 39 ms 3292 KB Output is correct
7 Correct 35 ms 3148 KB Output is correct
8 Correct 37 ms 3216 KB Output is correct
9 Correct 37 ms 3252 KB Output is correct
10 Correct 39 ms 3276 KB Output is correct
11 Correct 38 ms 3272 KB Output is correct
12 Correct 39 ms 3264 KB Output is correct
13 Correct 38 ms 3196 KB Output is correct
14 Correct 37 ms 3192 KB Output is correct
15 Correct 37 ms 3152 KB Output is correct
16 Correct 0 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 17 ms 1340 KB Output is correct
20 Correct 34 ms 2372 KB Output is correct
21 Correct 44 ms 3428 KB Output is correct
22 Correct 43 ms 3336 KB Output is correct
23 Correct 43 ms 3428 KB Output is correct
24 Correct 44 ms 3304 KB Output is correct
25 Correct 43 ms 3404 KB Output is correct
26 Correct 43 ms 3380 KB Output is correct
27 Correct 42 ms 3380 KB Output is correct
28 Correct 41 ms 3340 KB Output is correct
29 Correct 42 ms 3276 KB Output is correct
30 Correct 43 ms 3436 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 2 ms 340 KB Output is correct
35 Correct 2 ms 320 KB Output is correct
36 Correct 3 ms 468 KB Output is correct
37 Correct 10 ms 860 KB Output is correct
38 Correct 10 ms 956 KB Output is correct
39 Correct 20 ms 1444 KB Output is correct
40 Correct 40 ms 2716 KB Output is correct
41 Correct 60 ms 3788 KB Output is correct
42 Correct 59 ms 3784 KB Output is correct
43 Correct 60 ms 3844 KB Output is correct
44 Correct 62 ms 3824 KB Output is correct
45 Correct 59 ms 3796 KB Output is correct
46 Correct 64 ms 3792 KB Output is correct
47 Correct 66 ms 3744 KB Output is correct
48 Correct 58 ms 3824 KB Output is correct
49 Correct 60 ms 3788 KB Output is correct
50 Correct 73 ms 3816 KB Output is correct
51 Correct 60 ms 3788 KB Output is correct
52 Correct 58 ms 3728 KB Output is correct
53 Correct 59 ms 3764 KB Output is correct
54 Correct 64 ms 3760 KB Output is correct
55 Correct 59 ms 3844 KB Output is correct
56 Correct 60 ms 3788 KB Output is correct
57 Correct 59 ms 3760 KB Output is correct
58 Correct 59 ms 3836 KB Output is correct
59 Correct 60 ms 3812 KB Output is correct
60 Correct 59 ms 3836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 308 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 12 ms 1280 KB Output is correct
15 Correct 24 ms 2288 KB Output is correct
16 Correct 39 ms 3292 KB Output is correct
17 Correct 35 ms 3148 KB Output is correct
18 Correct 37 ms 3216 KB Output is correct
19 Correct 37 ms 3252 KB Output is correct
20 Correct 39 ms 3276 KB Output is correct
21 Correct 38 ms 3272 KB Output is correct
22 Correct 39 ms 3264 KB Output is correct
23 Correct 38 ms 3196 KB Output is correct
24 Correct 37 ms 3192 KB Output is correct
25 Correct 37 ms 3152 KB Output is correct
26 Correct 0 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 17 ms 1340 KB Output is correct
30 Correct 34 ms 2372 KB Output is correct
31 Correct 44 ms 3428 KB Output is correct
32 Correct 43 ms 3336 KB Output is correct
33 Correct 43 ms 3428 KB Output is correct
34 Correct 44 ms 3304 KB Output is correct
35 Correct 43 ms 3404 KB Output is correct
36 Correct 43 ms 3380 KB Output is correct
37 Correct 42 ms 3380 KB Output is correct
38 Correct 41 ms 3340 KB Output is correct
39 Correct 42 ms 3276 KB Output is correct
40 Correct 43 ms 3436 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 2 ms 340 KB Output is correct
45 Correct 2 ms 320 KB Output is correct
46 Correct 3 ms 468 KB Output is correct
47 Correct 10 ms 860 KB Output is correct
48 Correct 10 ms 956 KB Output is correct
49 Correct 20 ms 1444 KB Output is correct
50 Correct 40 ms 2716 KB Output is correct
51 Correct 60 ms 3788 KB Output is correct
52 Correct 59 ms 3784 KB Output is correct
53 Correct 60 ms 3844 KB Output is correct
54 Correct 62 ms 3824 KB Output is correct
55 Correct 59 ms 3796 KB Output is correct
56 Correct 64 ms 3792 KB Output is correct
57 Correct 66 ms 3744 KB Output is correct
58 Correct 58 ms 3824 KB Output is correct
59 Correct 60 ms 3788 KB Output is correct
60 Correct 73 ms 3816 KB Output is correct
61 Correct 60 ms 3788 KB Output is correct
62 Correct 58 ms 3728 KB Output is correct
63 Correct 59 ms 3764 KB Output is correct
64 Correct 64 ms 3760 KB Output is correct
65 Correct 59 ms 3844 KB Output is correct
66 Correct 60 ms 3788 KB Output is correct
67 Correct 59 ms 3760 KB Output is correct
68 Correct 59 ms 3836 KB Output is correct
69 Correct 60 ms 3812 KB Output is correct
70 Correct 59 ms 3836 KB Output is correct
71 Correct 12 ms 980 KB Output is correct
72 Correct 12 ms 964 KB Output is correct
73 Correct 11 ms 980 KB Output is correct
74 Correct 12 ms 960 KB Output is correct
75 Correct 12 ms 1036 KB Output is correct
76 Correct 26 ms 1876 KB Output is correct
77 Correct 26 ms 1848 KB Output is correct
78 Correct 25 ms 1956 KB Output is correct
79 Correct 26 ms 1896 KB Output is correct
80 Correct 25 ms 1852 KB Output is correct
81 Correct 54 ms 3604 KB Output is correct
82 Correct 54 ms 3628 KB Output is correct
83 Correct 56 ms 3652 KB Output is correct
84 Correct 54 ms 3532 KB Output is correct
85 Correct 53 ms 3532 KB Output is correct
86 Correct 63 ms 4540 KB Output is correct
87 Correct 61 ms 4488 KB Output is correct
88 Correct 63 ms 4460 KB Output is correct
89 Correct 62 ms 4488 KB Output is correct
90 Correct 67 ms 4452 KB Output is correct
91 Correct 121 ms 11780 KB Output is correct
92 Correct 120 ms 11752 KB Output is correct
93 Correct 121 ms 11716 KB Output is correct
94 Correct 128 ms 11748 KB Output is correct
95 Correct 118 ms 11756 KB Output is correct
96 Correct 158 ms 19208 KB Output is correct
97 Correct 155 ms 19228 KB Output is correct
98 Correct 164 ms 19136 KB Output is correct
99 Correct 157 ms 19144 KB Output is correct
100 Correct 158 ms 19148 KB Output is correct
101 Correct 158 ms 19228 KB Output is correct
102 Correct 205 ms 19156 KB Output is correct
103 Correct 164 ms 19136 KB Output is correct
104 Correct 158 ms 19248 KB Output is correct
105 Correct 177 ms 19160 KB Output is correct
106 Correct 185 ms 22560 KB Output is correct
107 Correct 190 ms 22316 KB Output is correct
108 Correct 183 ms 22316 KB Output is correct
109 Correct 175 ms 22404 KB Output is correct
110 Correct 180 ms 22292 KB Output is correct
111 Correct 181 ms 22376 KB Output is correct
112 Correct 183 ms 22408 KB Output is correct
113 Correct 192 ms 22380 KB Output is correct
114 Correct 183 ms 22332 KB Output is correct
115 Correct 186 ms 22324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 308 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 12 ms 1280 KB Output is correct
15 Correct 24 ms 2288 KB Output is correct
16 Correct 39 ms 3292 KB Output is correct
17 Correct 35 ms 3148 KB Output is correct
18 Correct 37 ms 3216 KB Output is correct
19 Correct 37 ms 3252 KB Output is correct
20 Correct 39 ms 3276 KB Output is correct
21 Correct 38 ms 3272 KB Output is correct
22 Correct 39 ms 3264 KB Output is correct
23 Correct 38 ms 3196 KB Output is correct
24 Correct 37 ms 3192 KB Output is correct
25 Correct 37 ms 3152 KB Output is correct
26 Correct 0 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 17 ms 1340 KB Output is correct
30 Correct 34 ms 2372 KB Output is correct
31 Correct 44 ms 3428 KB Output is correct
32 Correct 43 ms 3336 KB Output is correct
33 Correct 43 ms 3428 KB Output is correct
34 Correct 44 ms 3304 KB Output is correct
35 Correct 43 ms 3404 KB Output is correct
36 Correct 43 ms 3380 KB Output is correct
37 Correct 42 ms 3380 KB Output is correct
38 Correct 41 ms 3340 KB Output is correct
39 Correct 42 ms 3276 KB Output is correct
40 Correct 43 ms 3436 KB Output is correct
41 Correct 1 ms 212 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 2 ms 340 KB Output is correct
45 Correct 2 ms 320 KB Output is correct
46 Correct 3 ms 468 KB Output is correct
47 Correct 10 ms 860 KB Output is correct
48 Correct 10 ms 956 KB Output is correct
49 Correct 20 ms 1444 KB Output is correct
50 Correct 40 ms 2716 KB Output is correct
51 Correct 60 ms 3788 KB Output is correct
52 Correct 59 ms 3784 KB Output is correct
53 Correct 60 ms 3844 KB Output is correct
54 Correct 62 ms 3824 KB Output is correct
55 Correct 59 ms 3796 KB Output is correct
56 Correct 64 ms 3792 KB Output is correct
57 Correct 66 ms 3744 KB Output is correct
58 Correct 58 ms 3824 KB Output is correct
59 Correct 60 ms 3788 KB Output is correct
60 Correct 73 ms 3816 KB Output is correct
61 Correct 60 ms 3788 KB Output is correct
62 Correct 58 ms 3728 KB Output is correct
63 Correct 59 ms 3764 KB Output is correct
64 Correct 64 ms 3760 KB Output is correct
65 Correct 59 ms 3844 KB Output is correct
66 Correct 60 ms 3788 KB Output is correct
67 Correct 59 ms 3760 KB Output is correct
68 Correct 59 ms 3836 KB Output is correct
69 Correct 60 ms 3812 KB Output is correct
70 Correct 59 ms 3836 KB Output is correct
71 Correct 12 ms 980 KB Output is correct
72 Correct 12 ms 964 KB Output is correct
73 Correct 11 ms 980 KB Output is correct
74 Correct 12 ms 960 KB Output is correct
75 Correct 12 ms 1036 KB Output is correct
76 Correct 26 ms 1876 KB Output is correct
77 Correct 26 ms 1848 KB Output is correct
78 Correct 25 ms 1956 KB Output is correct
79 Correct 26 ms 1896 KB Output is correct
80 Correct 25 ms 1852 KB Output is correct
81 Correct 54 ms 3604 KB Output is correct
82 Correct 54 ms 3628 KB Output is correct
83 Correct 56 ms 3652 KB Output is correct
84 Correct 54 ms 3532 KB Output is correct
85 Correct 53 ms 3532 KB Output is correct
86 Correct 63 ms 4540 KB Output is correct
87 Correct 61 ms 4488 KB Output is correct
88 Correct 63 ms 4460 KB Output is correct
89 Correct 62 ms 4488 KB Output is correct
90 Correct 67 ms 4452 KB Output is correct
91 Correct 121 ms 11780 KB Output is correct
92 Correct 120 ms 11752 KB Output is correct
93 Correct 121 ms 11716 KB Output is correct
94 Correct 128 ms 11748 KB Output is correct
95 Correct 118 ms 11756 KB Output is correct
96 Correct 158 ms 19208 KB Output is correct
97 Correct 155 ms 19228 KB Output is correct
98 Correct 164 ms 19136 KB Output is correct
99 Correct 157 ms 19144 KB Output is correct
100 Correct 158 ms 19148 KB Output is correct
101 Correct 158 ms 19228 KB Output is correct
102 Correct 205 ms 19156 KB Output is correct
103 Correct 164 ms 19136 KB Output is correct
104 Correct 158 ms 19248 KB Output is correct
105 Correct 177 ms 19160 KB Output is correct
106 Correct 185 ms 22560 KB Output is correct
107 Correct 190 ms 22316 KB Output is correct
108 Correct 183 ms 22316 KB Output is correct
109 Correct 175 ms 22404 KB Output is correct
110 Correct 180 ms 22292 KB Output is correct
111 Correct 181 ms 22376 KB Output is correct
112 Correct 183 ms 22408 KB Output is correct
113 Correct 192 ms 22380 KB Output is correct
114 Correct 183 ms 22332 KB Output is correct
115 Correct 186 ms 22324 KB Output is correct
116 Incorrect 2 ms 468 KB Output isn't correct
117 Halted 0 ms 0 KB -