#include <bits/stdc++.h>
using namespace std;
string abc = "abcdefghijklmnopqrstuvwxyz";
#define int long long
int m = 1003;
void solve(){
int n, qq;
cin >> n >> qq;
// vector<int> v(n);
vector<int> a(m, 0);
int r;
int sz = 0;
for(int i = 0; i < n; i++){
cin >> r;
if(a[r]==0) sz++;
a[r]++;
}
cin >> qq >> qq;
vector<int> w, v(sz);
for(int i = 0; i < m; i++){
if(a[i] != 0){
w.push_back(a[i]);
}
}
sort(w.rbegin(), w.rend());
int st = sz/2;
v[st]=w[0];
st--;
int res = 2;
for(int i = 1; i < sz; i++){
v[st]=w[i];
if(i%2 == 0) st-=res;
else st+=res;
res++;
}
int ans = 0;
n = v.size();
for(int i = 0; i < n; i++){
ans+=v[i]*(v[i]+1)/2;
}
queue<int> q;
int cur = 0;
res = 0;
for(int i = 1; i < n; i++){
cur+=(i+1)*v[i];
res+=v[i];
q.push(v[i]);
}
for(int i = 0; i < n-1; i++){
ans+=v[i]*cur;
int a = q.front();
cur-=res;
cur-=a;
res-=a;
q.pop();
}
cout << ans << endl;
}
signed main(){
int t = 1;
while(t--){
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
436 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
13 ms |
556 KB |
Output is correct |
5 |
Correct |
19 ms |
836 KB |
Output is correct |
6 |
Correct |
26 ms |
860 KB |
Output is correct |
7 |
Correct |
26 ms |
856 KB |
Output is correct |
8 |
Correct |
25 ms |
856 KB |
Output is correct |
9 |
Correct |
25 ms |
860 KB |
Output is correct |
10 |
Correct |
26 ms |
1052 KB |
Output is correct |
11 |
Correct |
25 ms |
856 KB |
Output is correct |
12 |
Correct |
30 ms |
1116 KB |
Output is correct |
13 |
Correct |
32 ms |
856 KB |
Output is correct |
14 |
Correct |
24 ms |
860 KB |
Output is correct |
15 |
Correct |
25 ms |
1064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
13 ms |
556 KB |
Output is correct |
5 |
Correct |
19 ms |
836 KB |
Output is correct |
6 |
Correct |
26 ms |
860 KB |
Output is correct |
7 |
Correct |
26 ms |
856 KB |
Output is correct |
8 |
Correct |
25 ms |
856 KB |
Output is correct |
9 |
Correct |
25 ms |
860 KB |
Output is correct |
10 |
Correct |
26 ms |
1052 KB |
Output is correct |
11 |
Correct |
25 ms |
856 KB |
Output is correct |
12 |
Correct |
30 ms |
1116 KB |
Output is correct |
13 |
Correct |
32 ms |
856 KB |
Output is correct |
14 |
Correct |
24 ms |
860 KB |
Output is correct |
15 |
Correct |
25 ms |
1064 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
10 ms |
604 KB |
Output is correct |
20 |
Correct |
19 ms |
856 KB |
Output is correct |
21 |
Correct |
35 ms |
1116 KB |
Output is correct |
22 |
Correct |
52 ms |
1184 KB |
Output is correct |
23 |
Correct |
36 ms |
1116 KB |
Output is correct |
24 |
Correct |
44 ms |
1056 KB |
Output is correct |
25 |
Correct |
49 ms |
1180 KB |
Output is correct |
26 |
Correct |
40 ms |
1176 KB |
Output is correct |
27 |
Correct |
30 ms |
1180 KB |
Output is correct |
28 |
Correct |
43 ms |
1104 KB |
Output is correct |
29 |
Correct |
43 ms |
1160 KB |
Output is correct |
30 |
Correct |
28 ms |
1112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
13 ms |
556 KB |
Output is correct |
5 |
Correct |
19 ms |
836 KB |
Output is correct |
6 |
Correct |
26 ms |
860 KB |
Output is correct |
7 |
Correct |
26 ms |
856 KB |
Output is correct |
8 |
Correct |
25 ms |
856 KB |
Output is correct |
9 |
Correct |
25 ms |
860 KB |
Output is correct |
10 |
Correct |
26 ms |
1052 KB |
Output is correct |
11 |
Correct |
25 ms |
856 KB |
Output is correct |
12 |
Correct |
30 ms |
1116 KB |
Output is correct |
13 |
Correct |
32 ms |
856 KB |
Output is correct |
14 |
Correct |
24 ms |
860 KB |
Output is correct |
15 |
Correct |
25 ms |
1064 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
10 ms |
604 KB |
Output is correct |
20 |
Correct |
19 ms |
856 KB |
Output is correct |
21 |
Correct |
35 ms |
1116 KB |
Output is correct |
22 |
Correct |
52 ms |
1184 KB |
Output is correct |
23 |
Correct |
36 ms |
1116 KB |
Output is correct |
24 |
Correct |
44 ms |
1056 KB |
Output is correct |
25 |
Correct |
49 ms |
1180 KB |
Output is correct |
26 |
Correct |
40 ms |
1176 KB |
Output is correct |
27 |
Correct |
30 ms |
1180 KB |
Output is correct |
28 |
Correct |
43 ms |
1104 KB |
Output is correct |
29 |
Correct |
43 ms |
1160 KB |
Output is correct |
30 |
Correct |
28 ms |
1112 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
2 ms |
348 KB |
Output is correct |
35 |
Correct |
3 ms |
348 KB |
Output is correct |
36 |
Correct |
2 ms |
348 KB |
Output is correct |
37 |
Correct |
8 ms |
628 KB |
Output is correct |
38 |
Correct |
6 ms |
604 KB |
Output is correct |
39 |
Correct |
15 ms |
748 KB |
Output is correct |
40 |
Correct |
22 ms |
1116 KB |
Output is correct |
41 |
Correct |
33 ms |
1448 KB |
Output is correct |
42 |
Correct |
34 ms |
1372 KB |
Output is correct |
43 |
Correct |
34 ms |
1372 KB |
Output is correct |
44 |
Correct |
36 ms |
1440 KB |
Output is correct |
45 |
Correct |
34 ms |
1368 KB |
Output is correct |
46 |
Correct |
42 ms |
1560 KB |
Output is correct |
47 |
Correct |
43 ms |
1552 KB |
Output is correct |
48 |
Correct |
38 ms |
1568 KB |
Output is correct |
49 |
Correct |
36 ms |
1420 KB |
Output is correct |
50 |
Correct |
34 ms |
1372 KB |
Output is correct |
51 |
Correct |
34 ms |
1448 KB |
Output is correct |
52 |
Correct |
33 ms |
1448 KB |
Output is correct |
53 |
Correct |
46 ms |
1556 KB |
Output is correct |
54 |
Correct |
37 ms |
1440 KB |
Output is correct |
55 |
Correct |
45 ms |
1440 KB |
Output is correct |
56 |
Correct |
54 ms |
1420 KB |
Output is correct |
57 |
Correct |
34 ms |
1444 KB |
Output is correct |
58 |
Correct |
45 ms |
1568 KB |
Output is correct |
59 |
Correct |
39 ms |
1568 KB |
Output is correct |
60 |
Correct |
50 ms |
1364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
436 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
13 ms |
556 KB |
Output is correct |
15 |
Correct |
19 ms |
836 KB |
Output is correct |
16 |
Correct |
26 ms |
860 KB |
Output is correct |
17 |
Correct |
26 ms |
856 KB |
Output is correct |
18 |
Correct |
25 ms |
856 KB |
Output is correct |
19 |
Correct |
25 ms |
860 KB |
Output is correct |
20 |
Correct |
26 ms |
1052 KB |
Output is correct |
21 |
Correct |
25 ms |
856 KB |
Output is correct |
22 |
Correct |
30 ms |
1116 KB |
Output is correct |
23 |
Correct |
32 ms |
856 KB |
Output is correct |
24 |
Correct |
24 ms |
860 KB |
Output is correct |
25 |
Correct |
25 ms |
1064 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
2 ms |
348 KB |
Output is correct |
29 |
Correct |
10 ms |
604 KB |
Output is correct |
30 |
Correct |
19 ms |
856 KB |
Output is correct |
31 |
Correct |
35 ms |
1116 KB |
Output is correct |
32 |
Correct |
52 ms |
1184 KB |
Output is correct |
33 |
Correct |
36 ms |
1116 KB |
Output is correct |
34 |
Correct |
44 ms |
1056 KB |
Output is correct |
35 |
Correct |
49 ms |
1180 KB |
Output is correct |
36 |
Correct |
40 ms |
1176 KB |
Output is correct |
37 |
Correct |
30 ms |
1180 KB |
Output is correct |
38 |
Correct |
43 ms |
1104 KB |
Output is correct |
39 |
Correct |
43 ms |
1160 KB |
Output is correct |
40 |
Correct |
28 ms |
1112 KB |
Output is correct |
41 |
Correct |
1 ms |
344 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
2 ms |
348 KB |
Output is correct |
45 |
Correct |
3 ms |
348 KB |
Output is correct |
46 |
Correct |
2 ms |
348 KB |
Output is correct |
47 |
Correct |
8 ms |
628 KB |
Output is correct |
48 |
Correct |
6 ms |
604 KB |
Output is correct |
49 |
Correct |
15 ms |
748 KB |
Output is correct |
50 |
Correct |
22 ms |
1116 KB |
Output is correct |
51 |
Correct |
33 ms |
1448 KB |
Output is correct |
52 |
Correct |
34 ms |
1372 KB |
Output is correct |
53 |
Correct |
34 ms |
1372 KB |
Output is correct |
54 |
Correct |
36 ms |
1440 KB |
Output is correct |
55 |
Correct |
34 ms |
1368 KB |
Output is correct |
56 |
Correct |
42 ms |
1560 KB |
Output is correct |
57 |
Correct |
43 ms |
1552 KB |
Output is correct |
58 |
Correct |
38 ms |
1568 KB |
Output is correct |
59 |
Correct |
36 ms |
1420 KB |
Output is correct |
60 |
Correct |
34 ms |
1372 KB |
Output is correct |
61 |
Correct |
34 ms |
1448 KB |
Output is correct |
62 |
Correct |
33 ms |
1448 KB |
Output is correct |
63 |
Correct |
46 ms |
1556 KB |
Output is correct |
64 |
Correct |
37 ms |
1440 KB |
Output is correct |
65 |
Correct |
45 ms |
1440 KB |
Output is correct |
66 |
Correct |
54 ms |
1420 KB |
Output is correct |
67 |
Correct |
34 ms |
1444 KB |
Output is correct |
68 |
Correct |
45 ms |
1568 KB |
Output is correct |
69 |
Correct |
39 ms |
1568 KB |
Output is correct |
70 |
Correct |
50 ms |
1364 KB |
Output is correct |
71 |
Incorrect |
7 ms |
672 KB |
Output isn't correct |
72 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
436 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
13 ms |
556 KB |
Output is correct |
15 |
Correct |
19 ms |
836 KB |
Output is correct |
16 |
Correct |
26 ms |
860 KB |
Output is correct |
17 |
Correct |
26 ms |
856 KB |
Output is correct |
18 |
Correct |
25 ms |
856 KB |
Output is correct |
19 |
Correct |
25 ms |
860 KB |
Output is correct |
20 |
Correct |
26 ms |
1052 KB |
Output is correct |
21 |
Correct |
25 ms |
856 KB |
Output is correct |
22 |
Correct |
30 ms |
1116 KB |
Output is correct |
23 |
Correct |
32 ms |
856 KB |
Output is correct |
24 |
Correct |
24 ms |
860 KB |
Output is correct |
25 |
Correct |
25 ms |
1064 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
2 ms |
348 KB |
Output is correct |
29 |
Correct |
10 ms |
604 KB |
Output is correct |
30 |
Correct |
19 ms |
856 KB |
Output is correct |
31 |
Correct |
35 ms |
1116 KB |
Output is correct |
32 |
Correct |
52 ms |
1184 KB |
Output is correct |
33 |
Correct |
36 ms |
1116 KB |
Output is correct |
34 |
Correct |
44 ms |
1056 KB |
Output is correct |
35 |
Correct |
49 ms |
1180 KB |
Output is correct |
36 |
Correct |
40 ms |
1176 KB |
Output is correct |
37 |
Correct |
30 ms |
1180 KB |
Output is correct |
38 |
Correct |
43 ms |
1104 KB |
Output is correct |
39 |
Correct |
43 ms |
1160 KB |
Output is correct |
40 |
Correct |
28 ms |
1112 KB |
Output is correct |
41 |
Correct |
1 ms |
344 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
2 ms |
348 KB |
Output is correct |
45 |
Correct |
3 ms |
348 KB |
Output is correct |
46 |
Correct |
2 ms |
348 KB |
Output is correct |
47 |
Correct |
8 ms |
628 KB |
Output is correct |
48 |
Correct |
6 ms |
604 KB |
Output is correct |
49 |
Correct |
15 ms |
748 KB |
Output is correct |
50 |
Correct |
22 ms |
1116 KB |
Output is correct |
51 |
Correct |
33 ms |
1448 KB |
Output is correct |
52 |
Correct |
34 ms |
1372 KB |
Output is correct |
53 |
Correct |
34 ms |
1372 KB |
Output is correct |
54 |
Correct |
36 ms |
1440 KB |
Output is correct |
55 |
Correct |
34 ms |
1368 KB |
Output is correct |
56 |
Correct |
42 ms |
1560 KB |
Output is correct |
57 |
Correct |
43 ms |
1552 KB |
Output is correct |
58 |
Correct |
38 ms |
1568 KB |
Output is correct |
59 |
Correct |
36 ms |
1420 KB |
Output is correct |
60 |
Correct |
34 ms |
1372 KB |
Output is correct |
61 |
Correct |
34 ms |
1448 KB |
Output is correct |
62 |
Correct |
33 ms |
1448 KB |
Output is correct |
63 |
Correct |
46 ms |
1556 KB |
Output is correct |
64 |
Correct |
37 ms |
1440 KB |
Output is correct |
65 |
Correct |
45 ms |
1440 KB |
Output is correct |
66 |
Correct |
54 ms |
1420 KB |
Output is correct |
67 |
Correct |
34 ms |
1444 KB |
Output is correct |
68 |
Correct |
45 ms |
1568 KB |
Output is correct |
69 |
Correct |
39 ms |
1568 KB |
Output is correct |
70 |
Correct |
50 ms |
1364 KB |
Output is correct |
71 |
Incorrect |
7 ms |
672 KB |
Output isn't correct |
72 |
Halted |
0 ms |
0 KB |
- |