Submission #752602

# Submission time Handle Problem Language Result Execution time Memory
752602 2023-06-03T09:38:56 Z 이동현(#9968) Diversity (CEOI21_diversity) C++17
38 / 100
7000 ms 5476 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define int long long
#define mi(x, y) (x = min(x, y))
#define ma(x, y) (x = max(x, y))
using namespace std;

signed main(){
    ios_base::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];
    }

    sort(a.begin(), a.end());
    vector<int> b;
    for(int i = 0; i < n; ++i){
        int j = i;
        while(j + 1 < n && a[i] == a[j + 1]){
            ++j;
        }
        b.push_back(j - i + 1);
        i = j;
    }

    sort(b.begin(), b.end());
    reverse(b.begin(), b.end());
    int ans = (int)b.size() * n * (n + 1) / 2;
    for(int i = 0; i < (int)b.size(); ++i){
        ans -= ((int)b.size() - 1) * b[i] * (b[i] + 1) / 2;
        for(int j = i + 1; j < (int)b.size(); ++j){
            if(i % 2 == j % 2){
                ans -= ((int)b.size() - abs(i - j) / 2 - 1) * b[i] * b[j];
            }
            else{
                ans -= ((int)b.size() - i / 2 - j / 2 - 2) * b[i] * b[j];
            }
        }
    }

    cout << ans << '\n';
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 0 ms 324 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 332 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 13 ms 1228 KB Output is correct
5 Correct 16 ms 2268 KB Output is correct
6 Correct 23 ms 3276 KB Output is correct
7 Correct 21 ms 3284 KB Output is correct
8 Correct 22 ms 3184 KB Output is correct
9 Correct 24 ms 3308 KB Output is correct
10 Correct 35 ms 3308 KB Output is correct
11 Correct 28 ms 3276 KB Output is correct
12 Correct 30 ms 3284 KB Output is correct
13 Correct 25 ms 3308 KB Output is correct
14 Correct 26 ms 3308 KB Output is correct
15 Correct 25 ms 3308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 13 ms 1228 KB Output is correct
5 Correct 16 ms 2268 KB Output is correct
6 Correct 23 ms 3276 KB Output is correct
7 Correct 21 ms 3284 KB Output is correct
8 Correct 22 ms 3184 KB Output is correct
9 Correct 24 ms 3308 KB Output is correct
10 Correct 35 ms 3308 KB Output is correct
11 Correct 28 ms 3276 KB Output is correct
12 Correct 30 ms 3284 KB Output is correct
13 Correct 25 ms 3308 KB Output is correct
14 Correct 26 ms 3308 KB Output is correct
15 Correct 25 ms 3308 KB Output is correct
16 Correct 1 ms 288 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 9 ms 1364 KB Output is correct
20 Correct 27 ms 2384 KB Output is correct
21 Correct 34 ms 3428 KB Output is correct
22 Correct 30 ms 3424 KB Output is correct
23 Correct 27 ms 3440 KB Output is correct
24 Correct 28 ms 3412 KB Output is correct
25 Correct 27 ms 3412 KB Output is correct
26 Correct 32 ms 3412 KB Output is correct
27 Correct 26 ms 3408 KB Output is correct
28 Correct 25 ms 3304 KB Output is correct
29 Correct 25 ms 3308 KB Output is correct
30 Correct 30 ms 3436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 13 ms 1228 KB Output is correct
5 Correct 16 ms 2268 KB Output is correct
6 Correct 23 ms 3276 KB Output is correct
7 Correct 21 ms 3284 KB Output is correct
8 Correct 22 ms 3184 KB Output is correct
9 Correct 24 ms 3308 KB Output is correct
10 Correct 35 ms 3308 KB Output is correct
11 Correct 28 ms 3276 KB Output is correct
12 Correct 30 ms 3284 KB Output is correct
13 Correct 25 ms 3308 KB Output is correct
14 Correct 26 ms 3308 KB Output is correct
15 Correct 25 ms 3308 KB Output is correct
16 Correct 1 ms 288 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 9 ms 1364 KB Output is correct
20 Correct 27 ms 2384 KB Output is correct
21 Correct 34 ms 3428 KB Output is correct
22 Correct 30 ms 3424 KB Output is correct
23 Correct 27 ms 3440 KB Output is correct
24 Correct 28 ms 3412 KB Output is correct
25 Correct 27 ms 3412 KB Output is correct
26 Correct 32 ms 3412 KB Output is correct
27 Correct 26 ms 3408 KB Output is correct
28 Correct 25 ms 3304 KB Output is correct
29 Correct 25 ms 3308 KB Output is correct
30 Correct 30 ms 3436 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 256 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 436 KB Output is correct
35 Correct 2 ms 340 KB Output is correct
36 Correct 3 ms 340 KB Output is correct
37 Correct 9 ms 840 KB Output is correct
38 Correct 8 ms 912 KB Output is correct
39 Correct 15 ms 1504 KB Output is correct
40 Correct 29 ms 2644 KB Output is correct
41 Correct 37 ms 3788 KB Output is correct
42 Correct 41 ms 3812 KB Output is correct
43 Correct 44 ms 3804 KB Output is correct
44 Correct 51 ms 3820 KB Output is correct
45 Correct 35 ms 3792 KB Output is correct
46 Correct 34 ms 3812 KB Output is correct
47 Correct 34 ms 3812 KB Output is correct
48 Correct 48 ms 3816 KB Output is correct
49 Correct 36 ms 3820 KB Output is correct
50 Correct 40 ms 3812 KB Output is correct
51 Correct 51 ms 3832 KB Output is correct
52 Correct 34 ms 3820 KB Output is correct
53 Correct 33 ms 3796 KB Output is correct
54 Correct 36 ms 3788 KB Output is correct
55 Correct 43 ms 3804 KB Output is correct
56 Correct 37 ms 3824 KB Output is correct
57 Correct 35 ms 3820 KB Output is correct
58 Correct 32 ms 3820 KB Output is correct
59 Correct 39 ms 3816 KB Output is correct
60 Correct 34 ms 3804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 0 ms 324 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 332 KB Output is correct
8 Correct 1 ms 324 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 324 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 13 ms 1228 KB Output is correct
15 Correct 16 ms 2268 KB Output is correct
16 Correct 23 ms 3276 KB Output is correct
17 Correct 21 ms 3284 KB Output is correct
18 Correct 22 ms 3184 KB Output is correct
19 Correct 24 ms 3308 KB Output is correct
20 Correct 35 ms 3308 KB Output is correct
21 Correct 28 ms 3276 KB Output is correct
22 Correct 30 ms 3284 KB Output is correct
23 Correct 25 ms 3308 KB Output is correct
24 Correct 26 ms 3308 KB Output is correct
25 Correct 25 ms 3308 KB Output is correct
26 Correct 1 ms 288 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 9 ms 1364 KB Output is correct
30 Correct 27 ms 2384 KB Output is correct
31 Correct 34 ms 3428 KB Output is correct
32 Correct 30 ms 3424 KB Output is correct
33 Correct 27 ms 3440 KB Output is correct
34 Correct 28 ms 3412 KB Output is correct
35 Correct 27 ms 3412 KB Output is correct
36 Correct 32 ms 3412 KB Output is correct
37 Correct 26 ms 3408 KB Output is correct
38 Correct 25 ms 3304 KB Output is correct
39 Correct 25 ms 3308 KB Output is correct
40 Correct 30 ms 3436 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 256 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 436 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 3 ms 340 KB Output is correct
47 Correct 9 ms 840 KB Output is correct
48 Correct 8 ms 912 KB Output is correct
49 Correct 15 ms 1504 KB Output is correct
50 Correct 29 ms 2644 KB Output is correct
51 Correct 37 ms 3788 KB Output is correct
52 Correct 41 ms 3812 KB Output is correct
53 Correct 44 ms 3804 KB Output is correct
54 Correct 51 ms 3820 KB Output is correct
55 Correct 35 ms 3792 KB Output is correct
56 Correct 34 ms 3812 KB Output is correct
57 Correct 34 ms 3812 KB Output is correct
58 Correct 48 ms 3816 KB Output is correct
59 Correct 36 ms 3820 KB Output is correct
60 Correct 40 ms 3812 KB Output is correct
61 Correct 51 ms 3832 KB Output is correct
62 Correct 34 ms 3820 KB Output is correct
63 Correct 33 ms 3796 KB Output is correct
64 Correct 36 ms 3788 KB Output is correct
65 Correct 43 ms 3804 KB Output is correct
66 Correct 37 ms 3824 KB Output is correct
67 Correct 35 ms 3820 KB Output is correct
68 Correct 32 ms 3820 KB Output is correct
69 Correct 39 ms 3816 KB Output is correct
70 Correct 34 ms 3804 KB Output is correct
71 Correct 9 ms 980 KB Output is correct
72 Correct 11 ms 968 KB Output is correct
73 Correct 9 ms 968 KB Output is correct
74 Correct 13 ms 852 KB Output is correct
75 Correct 11 ms 976 KB Output is correct
76 Correct 32 ms 1620 KB Output is correct
77 Correct 36 ms 1620 KB Output is correct
78 Correct 38 ms 1584 KB Output is correct
79 Correct 32 ms 1596 KB Output is correct
80 Correct 32 ms 1620 KB Output is correct
81 Correct 111 ms 3052 KB Output is correct
82 Correct 125 ms 3056 KB Output is correct
83 Correct 101 ms 3032 KB Output is correct
84 Correct 126 ms 3056 KB Output is correct
85 Correct 123 ms 3060 KB Output is correct
86 Correct 365 ms 3288 KB Output is correct
87 Correct 374 ms 3344 KB Output is correct
88 Correct 421 ms 3300 KB Output is correct
89 Correct 347 ms 3276 KB Output is correct
90 Correct 400 ms 3236 KB Output is correct
91 Execution timed out 7092 ms 5476 KB Time limit exceeded
92 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 0 ms 324 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 332 KB Output is correct
8 Correct 1 ms 324 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 324 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 13 ms 1228 KB Output is correct
15 Correct 16 ms 2268 KB Output is correct
16 Correct 23 ms 3276 KB Output is correct
17 Correct 21 ms 3284 KB Output is correct
18 Correct 22 ms 3184 KB Output is correct
19 Correct 24 ms 3308 KB Output is correct
20 Correct 35 ms 3308 KB Output is correct
21 Correct 28 ms 3276 KB Output is correct
22 Correct 30 ms 3284 KB Output is correct
23 Correct 25 ms 3308 KB Output is correct
24 Correct 26 ms 3308 KB Output is correct
25 Correct 25 ms 3308 KB Output is correct
26 Correct 1 ms 288 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 9 ms 1364 KB Output is correct
30 Correct 27 ms 2384 KB Output is correct
31 Correct 34 ms 3428 KB Output is correct
32 Correct 30 ms 3424 KB Output is correct
33 Correct 27 ms 3440 KB Output is correct
34 Correct 28 ms 3412 KB Output is correct
35 Correct 27 ms 3412 KB Output is correct
36 Correct 32 ms 3412 KB Output is correct
37 Correct 26 ms 3408 KB Output is correct
38 Correct 25 ms 3304 KB Output is correct
39 Correct 25 ms 3308 KB Output is correct
40 Correct 30 ms 3436 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 256 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 436 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 3 ms 340 KB Output is correct
47 Correct 9 ms 840 KB Output is correct
48 Correct 8 ms 912 KB Output is correct
49 Correct 15 ms 1504 KB Output is correct
50 Correct 29 ms 2644 KB Output is correct
51 Correct 37 ms 3788 KB Output is correct
52 Correct 41 ms 3812 KB Output is correct
53 Correct 44 ms 3804 KB Output is correct
54 Correct 51 ms 3820 KB Output is correct
55 Correct 35 ms 3792 KB Output is correct
56 Correct 34 ms 3812 KB Output is correct
57 Correct 34 ms 3812 KB Output is correct
58 Correct 48 ms 3816 KB Output is correct
59 Correct 36 ms 3820 KB Output is correct
60 Correct 40 ms 3812 KB Output is correct
61 Correct 51 ms 3832 KB Output is correct
62 Correct 34 ms 3820 KB Output is correct
63 Correct 33 ms 3796 KB Output is correct
64 Correct 36 ms 3788 KB Output is correct
65 Correct 43 ms 3804 KB Output is correct
66 Correct 37 ms 3824 KB Output is correct
67 Correct 35 ms 3820 KB Output is correct
68 Correct 32 ms 3820 KB Output is correct
69 Correct 39 ms 3816 KB Output is correct
70 Correct 34 ms 3804 KB Output is correct
71 Correct 9 ms 980 KB Output is correct
72 Correct 11 ms 968 KB Output is correct
73 Correct 9 ms 968 KB Output is correct
74 Correct 13 ms 852 KB Output is correct
75 Correct 11 ms 976 KB Output is correct
76 Correct 32 ms 1620 KB Output is correct
77 Correct 36 ms 1620 KB Output is correct
78 Correct 38 ms 1584 KB Output is correct
79 Correct 32 ms 1596 KB Output is correct
80 Correct 32 ms 1620 KB Output is correct
81 Correct 111 ms 3052 KB Output is correct
82 Correct 125 ms 3056 KB Output is correct
83 Correct 101 ms 3032 KB Output is correct
84 Correct 126 ms 3056 KB Output is correct
85 Correct 123 ms 3060 KB Output is correct
86 Correct 365 ms 3288 KB Output is correct
87 Correct 374 ms 3344 KB Output is correct
88 Correct 421 ms 3300 KB Output is correct
89 Correct 347 ms 3276 KB Output is correct
90 Correct 400 ms 3236 KB Output is correct
91 Execution timed out 7092 ms 5476 KB Time limit exceeded
92 Halted 0 ms 0 KB -