답안 #657221

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
657221 2022-11-09T09:06:41 Z dooompy Diversity (CEOI21_diversity) C++17
64 / 100
204 ms 24512 KB
#include "bits/stdc++.h"

using namespace std;

void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
    cout << a << ' ', abc(b...);
}
template <typename T> void printv(T l, T r) {
    while (l != r) cout << *l << " \n"[++l == r];
}
template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) {
    return o >> a.first >> a.second;
}
template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) {
    return o << '(' << a.first << ", " << a.second << ')';
}
template <typename T> ostream& operator << (ostream& o, vector<T> a) {
    bool is = false;
    for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;}
    return o << '}';
}

#ifdef local
#define test(args...) abc("[" + string(#args) + "]", args)
#else
#define test(args...) void(0)
#endif

using ll = long long;

int a[300005];
map<int, int> ct;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
//    freopen("", "r", stdin);
//    freopen("", "w", stdout);
    int n, q; cin >> n >> q;

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        ct[a[i]]++;
    }

    vector<pair<ll, ll>> v;
    for (auto cru : ct) {
        v.push_back({cru.second, cru.first});
    }

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

    vector<ll> st, en;
    for (int i = 0; i < v.size(); i++) {
        if (i % 2 == 0) {
            st.push_back(v[i].first);
        } else en.push_back(v[i].first);
    }

    reverse(en.begin(), en.end());

    for (auto cur : en) st.push_back(cur);

    ll total = n;
    ll ans = 0 ;
    ll before = 0;

    for (auto cur : st) {
        ans += (cur * (cur + 1) / 2);
        ans += (before * cur);
        ans += ((total - cur - before) * cur);
        ans += (before * (total - before - cur));

        before += cur;
    }

    cout << ans;
}

Compilation message

diversity.cpp: In function 'int main()':
diversity.cpp:54:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     for (int i = 0; i < v.size(); i++) {
      |                     ~~^~~~~~~~~~
# 결과 실행 시간 메모리 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 1 ms 212 KB Output is correct
7 Correct 0 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 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 1 ms 340 KB Output is correct
4 Correct 6 ms 632 KB Output is correct
5 Correct 13 ms 980 KB Output is correct
6 Correct 21 ms 2100 KB Output is correct
7 Correct 23 ms 2084 KB Output is correct
8 Correct 21 ms 2088 KB Output is correct
9 Correct 21 ms 2108 KB Output is correct
10 Correct 19 ms 2144 KB Output is correct
11 Correct 21 ms 2040 KB Output is correct
12 Correct 20 ms 2116 KB Output is correct
13 Correct 20 ms 2048 KB Output is correct
14 Correct 20 ms 1996 KB Output is correct
15 Correct 20 ms 2132 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 1 ms 340 KB Output is correct
4 Correct 6 ms 632 KB Output is correct
5 Correct 13 ms 980 KB Output is correct
6 Correct 21 ms 2100 KB Output is correct
7 Correct 23 ms 2084 KB Output is correct
8 Correct 21 ms 2088 KB Output is correct
9 Correct 21 ms 2108 KB Output is correct
10 Correct 19 ms 2144 KB Output is correct
11 Correct 21 ms 2040 KB Output is correct
12 Correct 20 ms 2116 KB Output is correct
13 Correct 20 ms 2048 KB Output is correct
14 Correct 20 ms 1996 KB Output is correct
15 Correct 20 ms 2132 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 9 ms 936 KB Output is correct
20 Correct 15 ms 1576 KB Output is correct
21 Correct 25 ms 2244 KB Output is correct
22 Correct 22 ms 2236 KB Output is correct
23 Correct 23 ms 2256 KB Output is correct
24 Correct 22 ms 2260 KB Output is correct
25 Correct 25 ms 2248 KB Output is correct
26 Correct 23 ms 2124 KB Output is correct
27 Correct 26 ms 2252 KB Output is correct
28 Correct 21 ms 2212 KB Output is correct
29 Correct 23 ms 2188 KB Output is correct
30 Correct 23 ms 2244 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 1 ms 340 KB Output is correct
4 Correct 6 ms 632 KB Output is correct
5 Correct 13 ms 980 KB Output is correct
6 Correct 21 ms 2100 KB Output is correct
7 Correct 23 ms 2084 KB Output is correct
8 Correct 21 ms 2088 KB Output is correct
9 Correct 21 ms 2108 KB Output is correct
10 Correct 19 ms 2144 KB Output is correct
11 Correct 21 ms 2040 KB Output is correct
12 Correct 20 ms 2116 KB Output is correct
13 Correct 20 ms 2048 KB Output is correct
14 Correct 20 ms 1996 KB Output is correct
15 Correct 20 ms 2132 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 9 ms 936 KB Output is correct
20 Correct 15 ms 1576 KB Output is correct
21 Correct 25 ms 2244 KB Output is correct
22 Correct 22 ms 2236 KB Output is correct
23 Correct 23 ms 2256 KB Output is correct
24 Correct 22 ms 2260 KB Output is correct
25 Correct 25 ms 2248 KB Output is correct
26 Correct 23 ms 2124 KB Output is correct
27 Correct 26 ms 2252 KB Output is correct
28 Correct 21 ms 2212 KB Output is correct
29 Correct 23 ms 2188 KB Output is correct
30 Correct 23 ms 2244 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 332 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 340 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 6 ms 852 KB Output is correct
38 Correct 7 ms 724 KB Output is correct
39 Correct 12 ms 1096 KB Output is correct
40 Correct 24 ms 1864 KB Output is correct
41 Correct 36 ms 2648 KB Output is correct
42 Correct 36 ms 2660 KB Output is correct
43 Correct 37 ms 2616 KB Output is correct
44 Correct 36 ms 2616 KB Output is correct
45 Correct 34 ms 2648 KB Output is correct
46 Correct 35 ms 2704 KB Output is correct
47 Correct 36 ms 2636 KB Output is correct
48 Correct 36 ms 2704 KB Output is correct
49 Correct 35 ms 2600 KB Output is correct
50 Correct 37 ms 2592 KB Output is correct
51 Correct 35 ms 2680 KB Output is correct
52 Correct 37 ms 2688 KB Output is correct
53 Correct 36 ms 2648 KB Output is correct
54 Correct 35 ms 2628 KB Output is correct
55 Correct 35 ms 2636 KB Output is correct
56 Correct 36 ms 2708 KB Output is correct
57 Correct 36 ms 2696 KB Output is correct
58 Correct 35 ms 2632 KB Output is correct
59 Correct 35 ms 2636 KB Output is correct
60 Correct 34 ms 2636 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 1 ms 212 KB Output is correct
7 Correct 0 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 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 1 ms 340 KB Output is correct
14 Correct 6 ms 632 KB Output is correct
15 Correct 13 ms 980 KB Output is correct
16 Correct 21 ms 2100 KB Output is correct
17 Correct 23 ms 2084 KB Output is correct
18 Correct 21 ms 2088 KB Output is correct
19 Correct 21 ms 2108 KB Output is correct
20 Correct 19 ms 2144 KB Output is correct
21 Correct 21 ms 2040 KB Output is correct
22 Correct 20 ms 2116 KB Output is correct
23 Correct 20 ms 2048 KB Output is correct
24 Correct 20 ms 1996 KB Output is correct
25 Correct 20 ms 2132 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 9 ms 936 KB Output is correct
30 Correct 15 ms 1576 KB Output is correct
31 Correct 25 ms 2244 KB Output is correct
32 Correct 22 ms 2236 KB Output is correct
33 Correct 23 ms 2256 KB Output is correct
34 Correct 22 ms 2260 KB Output is correct
35 Correct 25 ms 2248 KB Output is correct
36 Correct 23 ms 2124 KB Output is correct
37 Correct 26 ms 2252 KB Output is correct
38 Correct 21 ms 2212 KB Output is correct
39 Correct 23 ms 2188 KB Output is correct
40 Correct 23 ms 2244 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 0 ms 332 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 340 KB Output is correct
46 Correct 2 ms 468 KB Output is correct
47 Correct 6 ms 852 KB Output is correct
48 Correct 7 ms 724 KB Output is correct
49 Correct 12 ms 1096 KB Output is correct
50 Correct 24 ms 1864 KB Output is correct
51 Correct 36 ms 2648 KB Output is correct
52 Correct 36 ms 2660 KB Output is correct
53 Correct 37 ms 2616 KB Output is correct
54 Correct 36 ms 2616 KB Output is correct
55 Correct 34 ms 2648 KB Output is correct
56 Correct 35 ms 2704 KB Output is correct
57 Correct 36 ms 2636 KB Output is correct
58 Correct 36 ms 2704 KB Output is correct
59 Correct 35 ms 2600 KB Output is correct
60 Correct 37 ms 2592 KB Output is correct
61 Correct 35 ms 2680 KB Output is correct
62 Correct 37 ms 2688 KB Output is correct
63 Correct 36 ms 2648 KB Output is correct
64 Correct 35 ms 2628 KB Output is correct
65 Correct 35 ms 2636 KB Output is correct
66 Correct 36 ms 2708 KB Output is correct
67 Correct 36 ms 2696 KB Output is correct
68 Correct 35 ms 2632 KB Output is correct
69 Correct 35 ms 2636 KB Output is correct
70 Correct 34 ms 2636 KB Output is correct
71 Correct 8 ms 820 KB Output is correct
72 Correct 8 ms 852 KB Output is correct
73 Correct 7 ms 848 KB Output is correct
74 Correct 9 ms 852 KB Output is correct
75 Correct 8 ms 852 KB Output is correct
76 Correct 16 ms 1612 KB Output is correct
77 Correct 19 ms 1576 KB Output is correct
78 Correct 16 ms 1628 KB Output is correct
79 Correct 16 ms 1664 KB Output is correct
80 Correct 16 ms 1620 KB Output is correct
81 Correct 36 ms 2916 KB Output is correct
82 Correct 36 ms 2944 KB Output is correct
83 Correct 39 ms 2900 KB Output is correct
84 Correct 36 ms 2920 KB Output is correct
85 Correct 36 ms 2892 KB Output is correct
86 Correct 44 ms 3920 KB Output is correct
87 Correct 43 ms 3904 KB Output is correct
88 Correct 44 ms 3908 KB Output is correct
89 Correct 44 ms 3884 KB Output is correct
90 Correct 45 ms 3856 KB Output is correct
91 Correct 113 ms 11536 KB Output is correct
92 Correct 102 ms 11584 KB Output is correct
93 Correct 109 ms 11588 KB Output is correct
94 Correct 105 ms 11568 KB Output is correct
95 Correct 103 ms 11604 KB Output is correct
96 Correct 168 ms 20536 KB Output is correct
97 Correct 169 ms 20536 KB Output is correct
98 Correct 167 ms 20672 KB Output is correct
99 Correct 173 ms 20548 KB Output is correct
100 Correct 161 ms 20596 KB Output is correct
101 Correct 175 ms 20656 KB Output is correct
102 Correct 166 ms 20652 KB Output is correct
103 Correct 164 ms 20560 KB Output is correct
104 Correct 168 ms 20600 KB Output is correct
105 Correct 170 ms 20664 KB Output is correct
106 Correct 190 ms 24484 KB Output is correct
107 Correct 184 ms 24404 KB Output is correct
108 Correct 199 ms 24372 KB Output is correct
109 Correct 188 ms 24392 KB Output is correct
110 Correct 190 ms 24308 KB Output is correct
111 Correct 191 ms 24324 KB Output is correct
112 Correct 192 ms 24364 KB Output is correct
113 Correct 204 ms 24356 KB Output is correct
114 Correct 188 ms 24400 KB Output is correct
115 Correct 193 ms 24512 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 1 ms 212 KB Output is correct
7 Correct 0 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 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 1 ms 340 KB Output is correct
14 Correct 6 ms 632 KB Output is correct
15 Correct 13 ms 980 KB Output is correct
16 Correct 21 ms 2100 KB Output is correct
17 Correct 23 ms 2084 KB Output is correct
18 Correct 21 ms 2088 KB Output is correct
19 Correct 21 ms 2108 KB Output is correct
20 Correct 19 ms 2144 KB Output is correct
21 Correct 21 ms 2040 KB Output is correct
22 Correct 20 ms 2116 KB Output is correct
23 Correct 20 ms 2048 KB Output is correct
24 Correct 20 ms 1996 KB Output is correct
25 Correct 20 ms 2132 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 9 ms 936 KB Output is correct
30 Correct 15 ms 1576 KB Output is correct
31 Correct 25 ms 2244 KB Output is correct
32 Correct 22 ms 2236 KB Output is correct
33 Correct 23 ms 2256 KB Output is correct
34 Correct 22 ms 2260 KB Output is correct
35 Correct 25 ms 2248 KB Output is correct
36 Correct 23 ms 2124 KB Output is correct
37 Correct 26 ms 2252 KB Output is correct
38 Correct 21 ms 2212 KB Output is correct
39 Correct 23 ms 2188 KB Output is correct
40 Correct 23 ms 2244 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 0 ms 332 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 340 KB Output is correct
46 Correct 2 ms 468 KB Output is correct
47 Correct 6 ms 852 KB Output is correct
48 Correct 7 ms 724 KB Output is correct
49 Correct 12 ms 1096 KB Output is correct
50 Correct 24 ms 1864 KB Output is correct
51 Correct 36 ms 2648 KB Output is correct
52 Correct 36 ms 2660 KB Output is correct
53 Correct 37 ms 2616 KB Output is correct
54 Correct 36 ms 2616 KB Output is correct
55 Correct 34 ms 2648 KB Output is correct
56 Correct 35 ms 2704 KB Output is correct
57 Correct 36 ms 2636 KB Output is correct
58 Correct 36 ms 2704 KB Output is correct
59 Correct 35 ms 2600 KB Output is correct
60 Correct 37 ms 2592 KB Output is correct
61 Correct 35 ms 2680 KB Output is correct
62 Correct 37 ms 2688 KB Output is correct
63 Correct 36 ms 2648 KB Output is correct
64 Correct 35 ms 2628 KB Output is correct
65 Correct 35 ms 2636 KB Output is correct
66 Correct 36 ms 2708 KB Output is correct
67 Correct 36 ms 2696 KB Output is correct
68 Correct 35 ms 2632 KB Output is correct
69 Correct 35 ms 2636 KB Output is correct
70 Correct 34 ms 2636 KB Output is correct
71 Correct 8 ms 820 KB Output is correct
72 Correct 8 ms 852 KB Output is correct
73 Correct 7 ms 848 KB Output is correct
74 Correct 9 ms 852 KB Output is correct
75 Correct 8 ms 852 KB Output is correct
76 Correct 16 ms 1612 KB Output is correct
77 Correct 19 ms 1576 KB Output is correct
78 Correct 16 ms 1628 KB Output is correct
79 Correct 16 ms 1664 KB Output is correct
80 Correct 16 ms 1620 KB Output is correct
81 Correct 36 ms 2916 KB Output is correct
82 Correct 36 ms 2944 KB Output is correct
83 Correct 39 ms 2900 KB Output is correct
84 Correct 36 ms 2920 KB Output is correct
85 Correct 36 ms 2892 KB Output is correct
86 Correct 44 ms 3920 KB Output is correct
87 Correct 43 ms 3904 KB Output is correct
88 Correct 44 ms 3908 KB Output is correct
89 Correct 44 ms 3884 KB Output is correct
90 Correct 45 ms 3856 KB Output is correct
91 Correct 113 ms 11536 KB Output is correct
92 Correct 102 ms 11584 KB Output is correct
93 Correct 109 ms 11588 KB Output is correct
94 Correct 105 ms 11568 KB Output is correct
95 Correct 103 ms 11604 KB Output is correct
96 Correct 168 ms 20536 KB Output is correct
97 Correct 169 ms 20536 KB Output is correct
98 Correct 167 ms 20672 KB Output is correct
99 Correct 173 ms 20548 KB Output is correct
100 Correct 161 ms 20596 KB Output is correct
101 Correct 175 ms 20656 KB Output is correct
102 Correct 166 ms 20652 KB Output is correct
103 Correct 164 ms 20560 KB Output is correct
104 Correct 168 ms 20600 KB Output is correct
105 Correct 170 ms 20664 KB Output is correct
106 Correct 190 ms 24484 KB Output is correct
107 Correct 184 ms 24404 KB Output is correct
108 Correct 199 ms 24372 KB Output is correct
109 Correct 188 ms 24392 KB Output is correct
110 Correct 190 ms 24308 KB Output is correct
111 Correct 191 ms 24324 KB Output is correct
112 Correct 192 ms 24364 KB Output is correct
113 Correct 204 ms 24356 KB Output is correct
114 Correct 188 ms 24400 KB Output is correct
115 Correct 193 ms 24512 KB Output is correct
116 Incorrect 1 ms 468 KB Output isn't correct
117 Halted 0 ms 0 KB -