Submission #520456

# Submission time Handle Problem Language Result Execution time Memory
520456 2022-01-30T03:56:05 Z KoD Diversity (CEOI21_diversity) C++17
64 / 100
188 ms 16436 KB
#include <bits/stdc++.h>

using std::vector;
using std::array;
using std::pair;
using std::tuple;

using i64 = std::int64_t;

constexpr i64 INF = std::numeric_limits<i64>::max() / 2;

template <class T> void setmin(T& lhs, const T& rhs) {
    if (lhs > rhs) {
        lhs = rhs;
    }    
}

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int N, Q;
    std::cin >> N >> Q;
    vector<int> A(N);
    std::map<int, int> count;
    for (auto& x : A) {
        std::cin >> x;
        count[x] += 1;
    }
    vector<int> block;
    for (const auto& [_, c] : count) {
        block.push_back(c);
    }
    std::sort(block.begin(), block.end());
    const int n = block.size();
    i64 ans = (i64)N * (N + 1) / 2;
    int left = 0, right = 0;
    for (int i = 0; i < n - 1; ++i) {
        if (left < right) {
            left += block[i];
            ans += (i64)left * (N - left); 
        } else {
            right += block[i];
            ans += (i64)right * (N - right);
        }
    }
    std::cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 7 ms 716 KB Output is correct
5 Correct 11 ms 1100 KB Output is correct
6 Correct 17 ms 1484 KB Output is correct
7 Correct 16 ms 1484 KB Output is correct
8 Correct 18 ms 1484 KB Output is correct
9 Correct 17 ms 1484 KB Output is correct
10 Correct 17 ms 1484 KB Output is correct
11 Correct 18 ms 1484 KB Output is correct
12 Correct 18 ms 1484 KB Output is correct
13 Correct 19 ms 1484 KB Output is correct
14 Correct 18 ms 1484 KB Output is correct
15 Correct 18 ms 1484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 7 ms 716 KB Output is correct
5 Correct 11 ms 1100 KB Output is correct
6 Correct 17 ms 1484 KB Output is correct
7 Correct 16 ms 1484 KB Output is correct
8 Correct 18 ms 1484 KB Output is correct
9 Correct 17 ms 1484 KB Output is correct
10 Correct 17 ms 1484 KB Output is correct
11 Correct 18 ms 1484 KB Output is correct
12 Correct 18 ms 1484 KB Output is correct
13 Correct 19 ms 1484 KB Output is correct
14 Correct 18 ms 1484 KB Output is correct
15 Correct 18 ms 1484 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 7 ms 588 KB Output is correct
20 Correct 16 ms 1100 KB Output is correct
21 Correct 21 ms 1484 KB Output is correct
22 Correct 22 ms 1384 KB Output is correct
23 Correct 20 ms 1484 KB Output is correct
24 Correct 21 ms 1484 KB Output is correct
25 Correct 21 ms 1484 KB Output is correct
26 Correct 22 ms 1484 KB Output is correct
27 Correct 20 ms 1484 KB Output is correct
28 Correct 20 ms 1484 KB Output is correct
29 Correct 21 ms 1484 KB Output is correct
30 Correct 21 ms 1484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 7 ms 716 KB Output is correct
5 Correct 11 ms 1100 KB Output is correct
6 Correct 17 ms 1484 KB Output is correct
7 Correct 16 ms 1484 KB Output is correct
8 Correct 18 ms 1484 KB Output is correct
9 Correct 17 ms 1484 KB Output is correct
10 Correct 17 ms 1484 KB Output is correct
11 Correct 18 ms 1484 KB Output is correct
12 Correct 18 ms 1484 KB Output is correct
13 Correct 19 ms 1484 KB Output is correct
14 Correct 18 ms 1484 KB Output is correct
15 Correct 18 ms 1484 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 7 ms 588 KB Output is correct
20 Correct 16 ms 1100 KB Output is correct
21 Correct 21 ms 1484 KB Output is correct
22 Correct 22 ms 1384 KB Output is correct
23 Correct 20 ms 1484 KB Output is correct
24 Correct 21 ms 1484 KB Output is correct
25 Correct 21 ms 1484 KB Output is correct
26 Correct 22 ms 1484 KB Output is correct
27 Correct 20 ms 1484 KB Output is correct
28 Correct 20 ms 1484 KB Output is correct
29 Correct 21 ms 1484 KB Output is correct
30 Correct 21 ms 1484 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 2 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 5 ms 460 KB Output is correct
38 Correct 6 ms 460 KB Output is correct
39 Correct 12 ms 716 KB Output is correct
40 Correct 22 ms 1152 KB Output is correct
41 Correct 33 ms 1540 KB Output is correct
42 Correct 33 ms 1532 KB Output is correct
43 Correct 33 ms 1484 KB Output is correct
44 Correct 33 ms 1484 KB Output is correct
45 Correct 33 ms 1544 KB Output is correct
46 Correct 35 ms 1484 KB Output is correct
47 Correct 32 ms 1524 KB Output is correct
48 Correct 37 ms 1484 KB Output is correct
49 Correct 33 ms 1540 KB Output is correct
50 Correct 34 ms 1536 KB Output is correct
51 Correct 35 ms 1528 KB Output is correct
52 Correct 33 ms 1540 KB Output is correct
53 Correct 34 ms 1484 KB Output is correct
54 Correct 33 ms 1484 KB Output is correct
55 Correct 33 ms 1484 KB Output is correct
56 Correct 33 ms 1484 KB Output is correct
57 Correct 33 ms 1484 KB Output is correct
58 Correct 32 ms 1548 KB Output is correct
59 Correct 33 ms 1484 KB Output is correct
60 Correct 33 ms 1524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 7 ms 716 KB Output is correct
15 Correct 11 ms 1100 KB Output is correct
16 Correct 17 ms 1484 KB Output is correct
17 Correct 16 ms 1484 KB Output is correct
18 Correct 18 ms 1484 KB Output is correct
19 Correct 17 ms 1484 KB Output is correct
20 Correct 17 ms 1484 KB Output is correct
21 Correct 18 ms 1484 KB Output is correct
22 Correct 18 ms 1484 KB Output is correct
23 Correct 19 ms 1484 KB Output is correct
24 Correct 18 ms 1484 KB Output is correct
25 Correct 18 ms 1484 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 7 ms 588 KB Output is correct
30 Correct 16 ms 1100 KB Output is correct
31 Correct 21 ms 1484 KB Output is correct
32 Correct 22 ms 1384 KB Output is correct
33 Correct 20 ms 1484 KB Output is correct
34 Correct 21 ms 1484 KB Output is correct
35 Correct 21 ms 1484 KB Output is correct
36 Correct 22 ms 1484 KB Output is correct
37 Correct 20 ms 1484 KB Output is correct
38 Correct 20 ms 1484 KB Output is correct
39 Correct 21 ms 1484 KB Output is correct
40 Correct 21 ms 1484 KB Output is correct
41 Correct 0 ms 204 KB Output is correct
42 Correct 0 ms 204 KB Output is correct
43 Correct 0 ms 204 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 2 ms 332 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 5 ms 460 KB Output is correct
48 Correct 6 ms 460 KB Output is correct
49 Correct 12 ms 716 KB Output is correct
50 Correct 22 ms 1152 KB Output is correct
51 Correct 33 ms 1540 KB Output is correct
52 Correct 33 ms 1532 KB Output is correct
53 Correct 33 ms 1484 KB Output is correct
54 Correct 33 ms 1484 KB Output is correct
55 Correct 33 ms 1544 KB Output is correct
56 Correct 35 ms 1484 KB Output is correct
57 Correct 32 ms 1524 KB Output is correct
58 Correct 37 ms 1484 KB Output is correct
59 Correct 33 ms 1540 KB Output is correct
60 Correct 34 ms 1536 KB Output is correct
61 Correct 35 ms 1528 KB Output is correct
62 Correct 33 ms 1540 KB Output is correct
63 Correct 34 ms 1484 KB Output is correct
64 Correct 33 ms 1484 KB Output is correct
65 Correct 33 ms 1484 KB Output is correct
66 Correct 33 ms 1484 KB Output is correct
67 Correct 33 ms 1484 KB Output is correct
68 Correct 32 ms 1548 KB Output is correct
69 Correct 33 ms 1484 KB Output is correct
70 Correct 33 ms 1524 KB Output is correct
71 Correct 7 ms 608 KB Output is correct
72 Correct 8 ms 612 KB Output is correct
73 Correct 8 ms 616 KB Output is correct
74 Correct 7 ms 608 KB Output is correct
75 Correct 9 ms 588 KB Output is correct
76 Correct 16 ms 972 KB Output is correct
77 Correct 17 ms 928 KB Output is correct
78 Correct 15 ms 948 KB Output is correct
79 Correct 17 ms 972 KB Output is correct
80 Correct 15 ms 972 KB Output is correct
81 Correct 35 ms 1604 KB Output is correct
82 Correct 34 ms 1632 KB Output is correct
83 Correct 39 ms 1740 KB Output is correct
84 Correct 35 ms 1656 KB Output is correct
85 Correct 34 ms 1556 KB Output is correct
86 Correct 42 ms 2116 KB Output is correct
87 Correct 41 ms 2204 KB Output is correct
88 Correct 43 ms 2228 KB Output is correct
89 Correct 41 ms 2144 KB Output is correct
90 Correct 41 ms 2232 KB Output is correct
91 Correct 91 ms 6800 KB Output is correct
92 Correct 97 ms 8464 KB Output is correct
93 Correct 94 ms 8520 KB Output is correct
94 Correct 100 ms 8512 KB Output is correct
95 Correct 99 ms 8436 KB Output is correct
96 Correct 163 ms 13864 KB Output is correct
97 Correct 143 ms 13896 KB Output is correct
98 Correct 142 ms 13880 KB Output is correct
99 Correct 163 ms 13876 KB Output is correct
100 Correct 148 ms 13872 KB Output is correct
101 Correct 143 ms 13860 KB Output is correct
102 Correct 147 ms 13888 KB Output is correct
103 Correct 140 ms 13904 KB Output is correct
104 Correct 145 ms 13920 KB Output is correct
105 Correct 144 ms 13832 KB Output is correct
106 Correct 188 ms 16436 KB Output is correct
107 Correct 168 ms 16192 KB Output is correct
108 Correct 167 ms 16192 KB Output is correct
109 Correct 181 ms 16232 KB Output is correct
110 Correct 169 ms 16180 KB Output is correct
111 Correct 176 ms 16252 KB Output is correct
112 Correct 176 ms 16304 KB Output is correct
113 Correct 181 ms 16372 KB Output is correct
114 Correct 172 ms 16308 KB Output is correct
115 Correct 178 ms 16300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 7 ms 716 KB Output is correct
15 Correct 11 ms 1100 KB Output is correct
16 Correct 17 ms 1484 KB Output is correct
17 Correct 16 ms 1484 KB Output is correct
18 Correct 18 ms 1484 KB Output is correct
19 Correct 17 ms 1484 KB Output is correct
20 Correct 17 ms 1484 KB Output is correct
21 Correct 18 ms 1484 KB Output is correct
22 Correct 18 ms 1484 KB Output is correct
23 Correct 19 ms 1484 KB Output is correct
24 Correct 18 ms 1484 KB Output is correct
25 Correct 18 ms 1484 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 7 ms 588 KB Output is correct
30 Correct 16 ms 1100 KB Output is correct
31 Correct 21 ms 1484 KB Output is correct
32 Correct 22 ms 1384 KB Output is correct
33 Correct 20 ms 1484 KB Output is correct
34 Correct 21 ms 1484 KB Output is correct
35 Correct 21 ms 1484 KB Output is correct
36 Correct 22 ms 1484 KB Output is correct
37 Correct 20 ms 1484 KB Output is correct
38 Correct 20 ms 1484 KB Output is correct
39 Correct 21 ms 1484 KB Output is correct
40 Correct 21 ms 1484 KB Output is correct
41 Correct 0 ms 204 KB Output is correct
42 Correct 0 ms 204 KB Output is correct
43 Correct 0 ms 204 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 2 ms 332 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 5 ms 460 KB Output is correct
48 Correct 6 ms 460 KB Output is correct
49 Correct 12 ms 716 KB Output is correct
50 Correct 22 ms 1152 KB Output is correct
51 Correct 33 ms 1540 KB Output is correct
52 Correct 33 ms 1532 KB Output is correct
53 Correct 33 ms 1484 KB Output is correct
54 Correct 33 ms 1484 KB Output is correct
55 Correct 33 ms 1544 KB Output is correct
56 Correct 35 ms 1484 KB Output is correct
57 Correct 32 ms 1524 KB Output is correct
58 Correct 37 ms 1484 KB Output is correct
59 Correct 33 ms 1540 KB Output is correct
60 Correct 34 ms 1536 KB Output is correct
61 Correct 35 ms 1528 KB Output is correct
62 Correct 33 ms 1540 KB Output is correct
63 Correct 34 ms 1484 KB Output is correct
64 Correct 33 ms 1484 KB Output is correct
65 Correct 33 ms 1484 KB Output is correct
66 Correct 33 ms 1484 KB Output is correct
67 Correct 33 ms 1484 KB Output is correct
68 Correct 32 ms 1548 KB Output is correct
69 Correct 33 ms 1484 KB Output is correct
70 Correct 33 ms 1524 KB Output is correct
71 Correct 7 ms 608 KB Output is correct
72 Correct 8 ms 612 KB Output is correct
73 Correct 8 ms 616 KB Output is correct
74 Correct 7 ms 608 KB Output is correct
75 Correct 9 ms 588 KB Output is correct
76 Correct 16 ms 972 KB Output is correct
77 Correct 17 ms 928 KB Output is correct
78 Correct 15 ms 948 KB Output is correct
79 Correct 17 ms 972 KB Output is correct
80 Correct 15 ms 972 KB Output is correct
81 Correct 35 ms 1604 KB Output is correct
82 Correct 34 ms 1632 KB Output is correct
83 Correct 39 ms 1740 KB Output is correct
84 Correct 35 ms 1656 KB Output is correct
85 Correct 34 ms 1556 KB Output is correct
86 Correct 42 ms 2116 KB Output is correct
87 Correct 41 ms 2204 KB Output is correct
88 Correct 43 ms 2228 KB Output is correct
89 Correct 41 ms 2144 KB Output is correct
90 Correct 41 ms 2232 KB Output is correct
91 Correct 91 ms 6800 KB Output is correct
92 Correct 97 ms 8464 KB Output is correct
93 Correct 94 ms 8520 KB Output is correct
94 Correct 100 ms 8512 KB Output is correct
95 Correct 99 ms 8436 KB Output is correct
96 Correct 163 ms 13864 KB Output is correct
97 Correct 143 ms 13896 KB Output is correct
98 Correct 142 ms 13880 KB Output is correct
99 Correct 163 ms 13876 KB Output is correct
100 Correct 148 ms 13872 KB Output is correct
101 Correct 143 ms 13860 KB Output is correct
102 Correct 147 ms 13888 KB Output is correct
103 Correct 140 ms 13904 KB Output is correct
104 Correct 145 ms 13920 KB Output is correct
105 Correct 144 ms 13832 KB Output is correct
106 Correct 188 ms 16436 KB Output is correct
107 Correct 168 ms 16192 KB Output is correct
108 Correct 167 ms 16192 KB Output is correct
109 Correct 181 ms 16232 KB Output is correct
110 Correct 169 ms 16180 KB Output is correct
111 Correct 176 ms 16252 KB Output is correct
112 Correct 176 ms 16304 KB Output is correct
113 Correct 181 ms 16372 KB Output is correct
114 Correct 172 ms 16308 KB Output is correct
115 Correct 178 ms 16300 KB Output is correct
116 Incorrect 2 ms 448 KB Output isn't correct
117 Halted 0 ms 0 KB -