#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
ll mod=1000000007;
int inf=1000000007;
ll infl=1000000000000000007;
#define int long long
ll cnt[300007];
ll x[300007];
signed main()
{
srand(time(NULL));
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
/* vector<int>P(10),p(10),best;
for(int i=0;i<10;i++)
{
P[i]=(i+1)*(i+1)*(i+1)*(i+1);
p[i]=i;
}
sort(all(P));
int ans=inf;
while(true)
{
int act=0;
for(int i=0;i<10;i++)
{
for(int j=i+1;j<10;j++)
{
act+=P[p[i]]*P[p[j]]*(j-i+1);
}
}
if(act<ans)
{
cout<<act<<endl;
ans=act;
best=p;
}
else if(act==ans) cout<<"XD"<<endl;
if(!next_permutation(all(p))) break;
}
for(int i=0;i<10;i++) cout<<best[i]<<" ";
cout<<endl;
cout<<ans<<endl;
for(int i=0;i<10;i++) cout<<P[best[i]]<<" ";*/
int n,a,q;
cin>>n>>q;
for(int i=1;i<=n;i++)
{
cin>>a;
cnt[a]++;
}
int mx=1000;
sort(cnt+1,cnt+mx+1);
int it=0,it1=mx+1;
for(int i=1;i<=mx;i++)
{
if(i%2) x[++it]=cnt[i];
else x[--it1]=cnt[i];
}
ll ans=0;
for(int i=1;i<=mx;i++)
{
ans+=x[i]*(x[i]+1)/2;
for(int j=i+1;j<=mx;j++)
{
ans+=x[i]*x[j]*(ll)(j-i+1);
}
}
cout<<ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
432 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
312 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
5 ms |
460 KB |
Output is correct |
5 |
Correct |
9 ms |
684 KB |
Output is correct |
6 |
Correct |
15 ms |
964 KB |
Output is correct |
7 |
Correct |
14 ms |
844 KB |
Output is correct |
8 |
Correct |
13 ms |
844 KB |
Output is correct |
9 |
Correct |
14 ms |
844 KB |
Output is correct |
10 |
Correct |
15 ms |
968 KB |
Output is correct |
11 |
Correct |
15 ms |
936 KB |
Output is correct |
12 |
Correct |
15 ms |
972 KB |
Output is correct |
13 |
Correct |
16 ms |
972 KB |
Output is correct |
14 |
Correct |
18 ms |
952 KB |
Output is correct |
15 |
Correct |
15 ms |
936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
312 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
5 ms |
460 KB |
Output is correct |
5 |
Correct |
9 ms |
684 KB |
Output is correct |
6 |
Correct |
15 ms |
964 KB |
Output is correct |
7 |
Correct |
14 ms |
844 KB |
Output is correct |
8 |
Correct |
13 ms |
844 KB |
Output is correct |
9 |
Correct |
14 ms |
844 KB |
Output is correct |
10 |
Correct |
15 ms |
968 KB |
Output is correct |
11 |
Correct |
15 ms |
936 KB |
Output is correct |
12 |
Correct |
15 ms |
972 KB |
Output is correct |
13 |
Correct |
16 ms |
972 KB |
Output is correct |
14 |
Correct |
18 ms |
952 KB |
Output is correct |
15 |
Correct |
15 ms |
936 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
6 ms |
564 KB |
Output is correct |
20 |
Correct |
11 ms |
828 KB |
Output is correct |
21 |
Correct |
16 ms |
1100 KB |
Output is correct |
22 |
Correct |
16 ms |
1060 KB |
Output is correct |
23 |
Correct |
16 ms |
1108 KB |
Output is correct |
24 |
Correct |
18 ms |
1080 KB |
Output is correct |
25 |
Correct |
16 ms |
1072 KB |
Output is correct |
26 |
Correct |
16 ms |
1060 KB |
Output is correct |
27 |
Correct |
16 ms |
1072 KB |
Output is correct |
28 |
Correct |
16 ms |
1064 KB |
Output is correct |
29 |
Correct |
16 ms |
972 KB |
Output is correct |
30 |
Correct |
16 ms |
1080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
312 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
5 ms |
460 KB |
Output is correct |
5 |
Correct |
9 ms |
684 KB |
Output is correct |
6 |
Correct |
15 ms |
964 KB |
Output is correct |
7 |
Correct |
14 ms |
844 KB |
Output is correct |
8 |
Correct |
13 ms |
844 KB |
Output is correct |
9 |
Correct |
14 ms |
844 KB |
Output is correct |
10 |
Correct |
15 ms |
968 KB |
Output is correct |
11 |
Correct |
15 ms |
936 KB |
Output is correct |
12 |
Correct |
15 ms |
972 KB |
Output is correct |
13 |
Correct |
16 ms |
972 KB |
Output is correct |
14 |
Correct |
18 ms |
952 KB |
Output is correct |
15 |
Correct |
15 ms |
936 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
6 ms |
564 KB |
Output is correct |
20 |
Correct |
11 ms |
828 KB |
Output is correct |
21 |
Correct |
16 ms |
1100 KB |
Output is correct |
22 |
Correct |
16 ms |
1060 KB |
Output is correct |
23 |
Correct |
16 ms |
1108 KB |
Output is correct |
24 |
Correct |
18 ms |
1080 KB |
Output is correct |
25 |
Correct |
16 ms |
1072 KB |
Output is correct |
26 |
Correct |
16 ms |
1060 KB |
Output is correct |
27 |
Correct |
16 ms |
1072 KB |
Output is correct |
28 |
Correct |
16 ms |
1064 KB |
Output is correct |
29 |
Correct |
16 ms |
972 KB |
Output is correct |
30 |
Correct |
16 ms |
1080 KB |
Output is correct |
31 |
Correct |
1 ms |
324 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
324 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
4 ms |
448 KB |
Output is correct |
38 |
Correct |
4 ms |
460 KB |
Output is correct |
39 |
Correct |
7 ms |
716 KB |
Output is correct |
40 |
Correct |
13 ms |
972 KB |
Output is correct |
41 |
Correct |
19 ms |
1460 KB |
Output is correct |
42 |
Correct |
18 ms |
1472 KB |
Output is correct |
43 |
Correct |
20 ms |
1336 KB |
Output is correct |
44 |
Correct |
20 ms |
1472 KB |
Output is correct |
45 |
Correct |
18 ms |
1456 KB |
Output is correct |
46 |
Correct |
18 ms |
1456 KB |
Output is correct |
47 |
Correct |
18 ms |
1348 KB |
Output is correct |
48 |
Correct |
18 ms |
1456 KB |
Output is correct |
49 |
Correct |
17 ms |
1452 KB |
Output is correct |
50 |
Correct |
17 ms |
1476 KB |
Output is correct |
51 |
Correct |
17 ms |
1456 KB |
Output is correct |
52 |
Correct |
20 ms |
1348 KB |
Output is correct |
53 |
Correct |
18 ms |
1348 KB |
Output is correct |
54 |
Correct |
18 ms |
1452 KB |
Output is correct |
55 |
Correct |
18 ms |
1452 KB |
Output is correct |
56 |
Correct |
20 ms |
1452 KB |
Output is correct |
57 |
Correct |
17 ms |
1484 KB |
Output is correct |
58 |
Correct |
18 ms |
1472 KB |
Output is correct |
59 |
Correct |
17 ms |
1484 KB |
Output is correct |
60 |
Correct |
17 ms |
1468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
432 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
312 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
5 ms |
460 KB |
Output is correct |
15 |
Correct |
9 ms |
684 KB |
Output is correct |
16 |
Correct |
15 ms |
964 KB |
Output is correct |
17 |
Correct |
14 ms |
844 KB |
Output is correct |
18 |
Correct |
13 ms |
844 KB |
Output is correct |
19 |
Correct |
14 ms |
844 KB |
Output is correct |
20 |
Correct |
15 ms |
968 KB |
Output is correct |
21 |
Correct |
15 ms |
936 KB |
Output is correct |
22 |
Correct |
15 ms |
972 KB |
Output is correct |
23 |
Correct |
16 ms |
972 KB |
Output is correct |
24 |
Correct |
18 ms |
952 KB |
Output is correct |
25 |
Correct |
15 ms |
936 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
6 ms |
564 KB |
Output is correct |
30 |
Correct |
11 ms |
828 KB |
Output is correct |
31 |
Correct |
16 ms |
1100 KB |
Output is correct |
32 |
Correct |
16 ms |
1060 KB |
Output is correct |
33 |
Correct |
16 ms |
1108 KB |
Output is correct |
34 |
Correct |
18 ms |
1080 KB |
Output is correct |
35 |
Correct |
16 ms |
1072 KB |
Output is correct |
36 |
Correct |
16 ms |
1060 KB |
Output is correct |
37 |
Correct |
16 ms |
1072 KB |
Output is correct |
38 |
Correct |
16 ms |
1064 KB |
Output is correct |
39 |
Correct |
16 ms |
972 KB |
Output is correct |
40 |
Correct |
16 ms |
1080 KB |
Output is correct |
41 |
Correct |
1 ms |
324 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
1 ms |
324 KB |
Output is correct |
45 |
Correct |
1 ms |
332 KB |
Output is correct |
46 |
Correct |
1 ms |
332 KB |
Output is correct |
47 |
Correct |
4 ms |
448 KB |
Output is correct |
48 |
Correct |
4 ms |
460 KB |
Output is correct |
49 |
Correct |
7 ms |
716 KB |
Output is correct |
50 |
Correct |
13 ms |
972 KB |
Output is correct |
51 |
Correct |
19 ms |
1460 KB |
Output is correct |
52 |
Correct |
18 ms |
1472 KB |
Output is correct |
53 |
Correct |
20 ms |
1336 KB |
Output is correct |
54 |
Correct |
20 ms |
1472 KB |
Output is correct |
55 |
Correct |
18 ms |
1456 KB |
Output is correct |
56 |
Correct |
18 ms |
1456 KB |
Output is correct |
57 |
Correct |
18 ms |
1348 KB |
Output is correct |
58 |
Correct |
18 ms |
1456 KB |
Output is correct |
59 |
Correct |
17 ms |
1452 KB |
Output is correct |
60 |
Correct |
17 ms |
1476 KB |
Output is correct |
61 |
Correct |
17 ms |
1456 KB |
Output is correct |
62 |
Correct |
20 ms |
1348 KB |
Output is correct |
63 |
Correct |
18 ms |
1348 KB |
Output is correct |
64 |
Correct |
18 ms |
1452 KB |
Output is correct |
65 |
Correct |
18 ms |
1452 KB |
Output is correct |
66 |
Correct |
20 ms |
1452 KB |
Output is correct |
67 |
Correct |
17 ms |
1484 KB |
Output is correct |
68 |
Correct |
18 ms |
1472 KB |
Output is correct |
69 |
Correct |
17 ms |
1484 KB |
Output is correct |
70 |
Correct |
17 ms |
1468 KB |
Output is correct |
71 |
Incorrect |
4 ms |
452 KB |
Output isn't correct |
72 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
432 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
312 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
5 ms |
460 KB |
Output is correct |
15 |
Correct |
9 ms |
684 KB |
Output is correct |
16 |
Correct |
15 ms |
964 KB |
Output is correct |
17 |
Correct |
14 ms |
844 KB |
Output is correct |
18 |
Correct |
13 ms |
844 KB |
Output is correct |
19 |
Correct |
14 ms |
844 KB |
Output is correct |
20 |
Correct |
15 ms |
968 KB |
Output is correct |
21 |
Correct |
15 ms |
936 KB |
Output is correct |
22 |
Correct |
15 ms |
972 KB |
Output is correct |
23 |
Correct |
16 ms |
972 KB |
Output is correct |
24 |
Correct |
18 ms |
952 KB |
Output is correct |
25 |
Correct |
15 ms |
936 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
6 ms |
564 KB |
Output is correct |
30 |
Correct |
11 ms |
828 KB |
Output is correct |
31 |
Correct |
16 ms |
1100 KB |
Output is correct |
32 |
Correct |
16 ms |
1060 KB |
Output is correct |
33 |
Correct |
16 ms |
1108 KB |
Output is correct |
34 |
Correct |
18 ms |
1080 KB |
Output is correct |
35 |
Correct |
16 ms |
1072 KB |
Output is correct |
36 |
Correct |
16 ms |
1060 KB |
Output is correct |
37 |
Correct |
16 ms |
1072 KB |
Output is correct |
38 |
Correct |
16 ms |
1064 KB |
Output is correct |
39 |
Correct |
16 ms |
972 KB |
Output is correct |
40 |
Correct |
16 ms |
1080 KB |
Output is correct |
41 |
Correct |
1 ms |
324 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
1 ms |
324 KB |
Output is correct |
45 |
Correct |
1 ms |
332 KB |
Output is correct |
46 |
Correct |
1 ms |
332 KB |
Output is correct |
47 |
Correct |
4 ms |
448 KB |
Output is correct |
48 |
Correct |
4 ms |
460 KB |
Output is correct |
49 |
Correct |
7 ms |
716 KB |
Output is correct |
50 |
Correct |
13 ms |
972 KB |
Output is correct |
51 |
Correct |
19 ms |
1460 KB |
Output is correct |
52 |
Correct |
18 ms |
1472 KB |
Output is correct |
53 |
Correct |
20 ms |
1336 KB |
Output is correct |
54 |
Correct |
20 ms |
1472 KB |
Output is correct |
55 |
Correct |
18 ms |
1456 KB |
Output is correct |
56 |
Correct |
18 ms |
1456 KB |
Output is correct |
57 |
Correct |
18 ms |
1348 KB |
Output is correct |
58 |
Correct |
18 ms |
1456 KB |
Output is correct |
59 |
Correct |
17 ms |
1452 KB |
Output is correct |
60 |
Correct |
17 ms |
1476 KB |
Output is correct |
61 |
Correct |
17 ms |
1456 KB |
Output is correct |
62 |
Correct |
20 ms |
1348 KB |
Output is correct |
63 |
Correct |
18 ms |
1348 KB |
Output is correct |
64 |
Correct |
18 ms |
1452 KB |
Output is correct |
65 |
Correct |
18 ms |
1452 KB |
Output is correct |
66 |
Correct |
20 ms |
1452 KB |
Output is correct |
67 |
Correct |
17 ms |
1484 KB |
Output is correct |
68 |
Correct |
18 ms |
1472 KB |
Output is correct |
69 |
Correct |
17 ms |
1484 KB |
Output is correct |
70 |
Correct |
17 ms |
1468 KB |
Output is correct |
71 |
Incorrect |
4 ms |
452 KB |
Output isn't correct |
72 |
Halted |
0 ms |
0 KB |
- |