답안 #613611

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
613611 2022-07-30T07:42:13 Z yuto1115 Diversity (CEOI21_diversity) C++17
64 / 100
210 ms 16368 KB
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, s, n) for(ll i = ll(s); i < ll(n); ++i)
#define rrep(i, n) for(ll i = ll(n) - 1; i >= 0; --i)
#define rrep2(i, n, t) for(ll i = ll(n) - 1; i >= ll(t); --i)
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define SZ(a) int(a.size())
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<P>;
using vvp = vector<vp>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;
const int inf = 1001001001;
const ll linf = 1001001001001001001;

template<class T>
bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    int n, q;
    cin >> n >> q;
    vi a(n);
    map<int, int> mp;
    for (int &i: a) {
        cin >> i;
        ++mp[i];
    }
    vi ls;
    for (auto[f, s]: mp) ls.pb(s);
    sort(all(ls));
    ls.pop_back();
    vi v(2);
    ll ans = 0;
    for (int i: ls) {
        if (v[0] > v[1]) swap(v[0], v[1]);
        v[0] += i;
        ans += (ll) v[0] * (n - v[0]);
    }
    rep(i, 2) assert(v[i] <= n / 2);
    ans += (ll) n * (n + 1) / 2;
    cout << ans << endl;
}
# 결과 실행 시간 메모리 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 324 KB Output is correct
5 Correct 0 ms 320 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 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 1 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 7 ms 836 KB Output is correct
5 Correct 14 ms 1492 KB Output is correct
6 Correct 19 ms 2132 KB Output is correct
7 Correct 17 ms 2004 KB Output is correct
8 Correct 19 ms 2008 KB Output is correct
9 Correct 18 ms 2132 KB Output is correct
10 Correct 19 ms 2132 KB Output is correct
11 Correct 21 ms 2040 KB Output is correct
12 Correct 19 ms 2128 KB Output is correct
13 Correct 18 ms 2132 KB Output is correct
14 Correct 18 ms 2124 KB Output is correct
15 Correct 19 ms 2132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 7 ms 836 KB Output is correct
5 Correct 14 ms 1492 KB Output is correct
6 Correct 19 ms 2132 KB Output is correct
7 Correct 17 ms 2004 KB Output is correct
8 Correct 19 ms 2008 KB Output is correct
9 Correct 18 ms 2132 KB Output is correct
10 Correct 19 ms 2132 KB Output is correct
11 Correct 21 ms 2040 KB Output is correct
12 Correct 19 ms 2128 KB Output is correct
13 Correct 18 ms 2132 KB Output is correct
14 Correct 18 ms 2124 KB Output is correct
15 Correct 19 ms 2132 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 7 ms 996 KB Output is correct
20 Correct 15 ms 1652 KB Output is correct
21 Correct 21 ms 2260 KB Output is correct
22 Correct 22 ms 2260 KB Output is correct
23 Correct 21 ms 2248 KB Output is correct
24 Correct 20 ms 2252 KB Output is correct
25 Correct 21 ms 2264 KB Output is correct
26 Correct 22 ms 2260 KB Output is correct
27 Correct 23 ms 2168 KB Output is correct
28 Correct 22 ms 2132 KB Output is correct
29 Correct 21 ms 2132 KB Output is correct
30 Correct 22 ms 2256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 7 ms 836 KB Output is correct
5 Correct 14 ms 1492 KB Output is correct
6 Correct 19 ms 2132 KB Output is correct
7 Correct 17 ms 2004 KB Output is correct
8 Correct 19 ms 2008 KB Output is correct
9 Correct 18 ms 2132 KB Output is correct
10 Correct 19 ms 2132 KB Output is correct
11 Correct 21 ms 2040 KB Output is correct
12 Correct 19 ms 2128 KB Output is correct
13 Correct 18 ms 2132 KB Output is correct
14 Correct 18 ms 2124 KB Output is correct
15 Correct 19 ms 2132 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 7 ms 996 KB Output is correct
20 Correct 15 ms 1652 KB Output is correct
21 Correct 21 ms 2260 KB Output is correct
22 Correct 22 ms 2260 KB Output is correct
23 Correct 21 ms 2248 KB Output is correct
24 Correct 20 ms 2252 KB Output is correct
25 Correct 21 ms 2264 KB Output is correct
26 Correct 22 ms 2260 KB Output is correct
27 Correct 23 ms 2168 KB Output is correct
28 Correct 22 ms 2132 KB Output is correct
29 Correct 21 ms 2132 KB Output is correct
30 Correct 22 ms 2256 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 324 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 2 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 6 ms 744 KB Output is correct
38 Correct 7 ms 772 KB Output is correct
39 Correct 12 ms 1100 KB Output is correct
40 Correct 24 ms 1908 KB Output is correct
41 Correct 37 ms 2688 KB Output is correct
42 Correct 40 ms 2692 KB Output is correct
43 Correct 35 ms 2676 KB Output is correct
44 Correct 34 ms 2688 KB Output is correct
45 Correct 35 ms 2676 KB Output is correct
46 Correct 34 ms 2628 KB Output is correct
47 Correct 35 ms 2676 KB Output is correct
48 Correct 35 ms 2680 KB Output is correct
49 Correct 35 ms 2636 KB Output is correct
50 Correct 35 ms 2684 KB Output is correct
51 Correct 36 ms 2636 KB Output is correct
52 Correct 38 ms 2684 KB Output is correct
53 Correct 35 ms 2668 KB Output is correct
54 Correct 34 ms 2672 KB Output is correct
55 Correct 34 ms 2676 KB Output is correct
56 Correct 34 ms 2700 KB Output is correct
57 Correct 35 ms 2684 KB Output is correct
58 Correct 35 ms 2688 KB Output is correct
59 Correct 38 ms 2688 KB Output is correct
60 Correct 34 ms 2684 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 324 KB Output is correct
5 Correct 0 ms 320 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 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 7 ms 836 KB Output is correct
15 Correct 14 ms 1492 KB Output is correct
16 Correct 19 ms 2132 KB Output is correct
17 Correct 17 ms 2004 KB Output is correct
18 Correct 19 ms 2008 KB Output is correct
19 Correct 18 ms 2132 KB Output is correct
20 Correct 19 ms 2132 KB Output is correct
21 Correct 21 ms 2040 KB Output is correct
22 Correct 19 ms 2128 KB Output is correct
23 Correct 18 ms 2132 KB Output is correct
24 Correct 18 ms 2124 KB Output is correct
25 Correct 19 ms 2132 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 7 ms 996 KB Output is correct
30 Correct 15 ms 1652 KB Output is correct
31 Correct 21 ms 2260 KB Output is correct
32 Correct 22 ms 2260 KB Output is correct
33 Correct 21 ms 2248 KB Output is correct
34 Correct 20 ms 2252 KB Output is correct
35 Correct 21 ms 2264 KB Output is correct
36 Correct 22 ms 2260 KB Output is correct
37 Correct 23 ms 2168 KB Output is correct
38 Correct 22 ms 2132 KB Output is correct
39 Correct 21 ms 2132 KB Output is correct
40 Correct 22 ms 2256 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 1 ms 324 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 2 ms 340 KB Output is correct
47 Correct 6 ms 744 KB Output is correct
48 Correct 7 ms 772 KB Output is correct
49 Correct 12 ms 1100 KB Output is correct
50 Correct 24 ms 1908 KB Output is correct
51 Correct 37 ms 2688 KB Output is correct
52 Correct 40 ms 2692 KB Output is correct
53 Correct 35 ms 2676 KB Output is correct
54 Correct 34 ms 2688 KB Output is correct
55 Correct 35 ms 2676 KB Output is correct
56 Correct 34 ms 2628 KB Output is correct
57 Correct 35 ms 2676 KB Output is correct
58 Correct 35 ms 2680 KB Output is correct
59 Correct 35 ms 2636 KB Output is correct
60 Correct 35 ms 2684 KB Output is correct
61 Correct 36 ms 2636 KB Output is correct
62 Correct 38 ms 2684 KB Output is correct
63 Correct 35 ms 2668 KB Output is correct
64 Correct 34 ms 2672 KB Output is correct
65 Correct 34 ms 2676 KB Output is correct
66 Correct 34 ms 2700 KB Output is correct
67 Correct 35 ms 2684 KB Output is correct
68 Correct 35 ms 2688 KB Output is correct
69 Correct 38 ms 2688 KB Output is correct
70 Correct 34 ms 2684 KB Output is correct
71 Correct 7 ms 852 KB Output is correct
72 Correct 8 ms 816 KB Output is correct
73 Correct 9 ms 852 KB Output is correct
74 Correct 7 ms 852 KB Output is correct
75 Correct 7 ms 856 KB Output is correct
76 Correct 16 ms 1488 KB Output is correct
77 Correct 16 ms 1448 KB Output is correct
78 Correct 16 ms 1492 KB Output is correct
79 Correct 16 ms 1424 KB Output is correct
80 Correct 16 ms 1424 KB Output is correct
81 Correct 37 ms 2508 KB Output is correct
82 Correct 35 ms 2556 KB Output is correct
83 Correct 36 ms 2536 KB Output is correct
84 Correct 35 ms 2556 KB Output is correct
85 Correct 39 ms 2636 KB Output is correct
86 Correct 46 ms 3196 KB Output is correct
87 Correct 42 ms 3228 KB Output is correct
88 Correct 43 ms 3324 KB Output is correct
89 Correct 43 ms 3276 KB Output is correct
90 Correct 51 ms 3276 KB Output is correct
91 Correct 110 ms 8536 KB Output is correct
92 Correct 110 ms 8644 KB Output is correct
93 Correct 116 ms 8532 KB Output is correct
94 Correct 92 ms 8548 KB Output is correct
95 Correct 94 ms 8520 KB Output is correct
96 Correct 161 ms 13860 KB Output is correct
97 Correct 150 ms 13924 KB Output is correct
98 Correct 151 ms 13896 KB Output is correct
99 Correct 147 ms 13828 KB Output is correct
100 Correct 149 ms 13912 KB Output is correct
101 Correct 164 ms 13928 KB Output is correct
102 Correct 170 ms 13848 KB Output is correct
103 Correct 153 ms 13928 KB Output is correct
104 Correct 171 ms 13912 KB Output is correct
105 Correct 155 ms 13836 KB Output is correct
106 Correct 168 ms 16324 KB Output is correct
107 Correct 178 ms 16252 KB Output is correct
108 Correct 181 ms 16292 KB Output is correct
109 Correct 172 ms 16212 KB Output is correct
110 Correct 179 ms 16284 KB Output is correct
111 Correct 201 ms 16232 KB Output is correct
112 Correct 185 ms 16340 KB Output is correct
113 Correct 210 ms 16368 KB Output is correct
114 Correct 179 ms 16308 KB Output is correct
115 Correct 181 ms 16268 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 324 KB Output is correct
5 Correct 0 ms 320 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 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 7 ms 836 KB Output is correct
15 Correct 14 ms 1492 KB Output is correct
16 Correct 19 ms 2132 KB Output is correct
17 Correct 17 ms 2004 KB Output is correct
18 Correct 19 ms 2008 KB Output is correct
19 Correct 18 ms 2132 KB Output is correct
20 Correct 19 ms 2132 KB Output is correct
21 Correct 21 ms 2040 KB Output is correct
22 Correct 19 ms 2128 KB Output is correct
23 Correct 18 ms 2132 KB Output is correct
24 Correct 18 ms 2124 KB Output is correct
25 Correct 19 ms 2132 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 7 ms 996 KB Output is correct
30 Correct 15 ms 1652 KB Output is correct
31 Correct 21 ms 2260 KB Output is correct
32 Correct 22 ms 2260 KB Output is correct
33 Correct 21 ms 2248 KB Output is correct
34 Correct 20 ms 2252 KB Output is correct
35 Correct 21 ms 2264 KB Output is correct
36 Correct 22 ms 2260 KB Output is correct
37 Correct 23 ms 2168 KB Output is correct
38 Correct 22 ms 2132 KB Output is correct
39 Correct 21 ms 2132 KB Output is correct
40 Correct 22 ms 2256 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 1 ms 324 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 2 ms 340 KB Output is correct
47 Correct 6 ms 744 KB Output is correct
48 Correct 7 ms 772 KB Output is correct
49 Correct 12 ms 1100 KB Output is correct
50 Correct 24 ms 1908 KB Output is correct
51 Correct 37 ms 2688 KB Output is correct
52 Correct 40 ms 2692 KB Output is correct
53 Correct 35 ms 2676 KB Output is correct
54 Correct 34 ms 2688 KB Output is correct
55 Correct 35 ms 2676 KB Output is correct
56 Correct 34 ms 2628 KB Output is correct
57 Correct 35 ms 2676 KB Output is correct
58 Correct 35 ms 2680 KB Output is correct
59 Correct 35 ms 2636 KB Output is correct
60 Correct 35 ms 2684 KB Output is correct
61 Correct 36 ms 2636 KB Output is correct
62 Correct 38 ms 2684 KB Output is correct
63 Correct 35 ms 2668 KB Output is correct
64 Correct 34 ms 2672 KB Output is correct
65 Correct 34 ms 2676 KB Output is correct
66 Correct 34 ms 2700 KB Output is correct
67 Correct 35 ms 2684 KB Output is correct
68 Correct 35 ms 2688 KB Output is correct
69 Correct 38 ms 2688 KB Output is correct
70 Correct 34 ms 2684 KB Output is correct
71 Correct 7 ms 852 KB Output is correct
72 Correct 8 ms 816 KB Output is correct
73 Correct 9 ms 852 KB Output is correct
74 Correct 7 ms 852 KB Output is correct
75 Correct 7 ms 856 KB Output is correct
76 Correct 16 ms 1488 KB Output is correct
77 Correct 16 ms 1448 KB Output is correct
78 Correct 16 ms 1492 KB Output is correct
79 Correct 16 ms 1424 KB Output is correct
80 Correct 16 ms 1424 KB Output is correct
81 Correct 37 ms 2508 KB Output is correct
82 Correct 35 ms 2556 KB Output is correct
83 Correct 36 ms 2536 KB Output is correct
84 Correct 35 ms 2556 KB Output is correct
85 Correct 39 ms 2636 KB Output is correct
86 Correct 46 ms 3196 KB Output is correct
87 Correct 42 ms 3228 KB Output is correct
88 Correct 43 ms 3324 KB Output is correct
89 Correct 43 ms 3276 KB Output is correct
90 Correct 51 ms 3276 KB Output is correct
91 Correct 110 ms 8536 KB Output is correct
92 Correct 110 ms 8644 KB Output is correct
93 Correct 116 ms 8532 KB Output is correct
94 Correct 92 ms 8548 KB Output is correct
95 Correct 94 ms 8520 KB Output is correct
96 Correct 161 ms 13860 KB Output is correct
97 Correct 150 ms 13924 KB Output is correct
98 Correct 151 ms 13896 KB Output is correct
99 Correct 147 ms 13828 KB Output is correct
100 Correct 149 ms 13912 KB Output is correct
101 Correct 164 ms 13928 KB Output is correct
102 Correct 170 ms 13848 KB Output is correct
103 Correct 153 ms 13928 KB Output is correct
104 Correct 171 ms 13912 KB Output is correct
105 Correct 155 ms 13836 KB Output is correct
106 Correct 168 ms 16324 KB Output is correct
107 Correct 178 ms 16252 KB Output is correct
108 Correct 181 ms 16292 KB Output is correct
109 Correct 172 ms 16212 KB Output is correct
110 Correct 179 ms 16284 KB Output is correct
111 Correct 201 ms 16232 KB Output is correct
112 Correct 185 ms 16340 KB Output is correct
113 Correct 210 ms 16368 KB Output is correct
114 Correct 179 ms 16308 KB Output is correct
115 Correct 181 ms 16268 KB Output is correct
116 Incorrect 1 ms 468 KB Output isn't correct
117 Halted 0 ms 0 KB -