#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ff first
#define ss second
ll ttt;
const ll INF=1e18;
const ll MOD=1e9+7;
const ll N=300007;
ll n,m,k;
ll a[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// freopen("output.txt","w",stdout);
// freopen("input.txt","r",stdin);
cin>>n>>m;
for(int i=0;i<n;i++){
int x;
cin>>x;
a[x]++;
}
cin>>m>>m;
vector<ll>d;
for(int i=0;i<N;i++){
if(a[i])d.push_back(a[i]);
}
sort(d.begin(),d.end());
ll res=LLONG_MAX;
do{
ll ans=0;
for(int i=0;i<d.size();i++){
ans+=(d[i]*(d[i]+1))/2;
for(int j=1;i+j<d.size();j++){
ans+=d[i]*d[i+j]*(j+1);
}
}
res=min(res,ans);
}
while(next_permutation(d.begin(),d.end()));
cout<<res<<endl;
}
Compilation message
diversity.cpp: In function 'int main()':
diversity.cpp:40:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for(int i=0;i<d.size();i++){
| ~^~~~~~~~~
diversity.cpp:42:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(int j=1;i+j<d.size();j++){
| ~~~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
352 KB |
Output is correct |
4 |
Correct |
18 ms |
440 KB |
Output is correct |
5 |
Correct |
166 ms |
724 KB |
Output is correct |
6 |
Correct |
2035 ms |
992 KB |
Output is correct |
7 |
Correct |
2084 ms |
912 KB |
Output is correct |
8 |
Correct |
2126 ms |
936 KB |
Output is correct |
9 |
Correct |
2167 ms |
948 KB |
Output is correct |
10 |
Correct |
2082 ms |
972 KB |
Output is correct |
11 |
Correct |
2028 ms |
956 KB |
Output is correct |
12 |
Correct |
2005 ms |
980 KB |
Output is correct |
13 |
Correct |
2013 ms |
968 KB |
Output is correct |
14 |
Correct |
2027 ms |
952 KB |
Output is correct |
15 |
Correct |
1992 ms |
956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
352 KB |
Output is correct |
4 |
Correct |
18 ms |
440 KB |
Output is correct |
5 |
Correct |
166 ms |
724 KB |
Output is correct |
6 |
Correct |
2035 ms |
992 KB |
Output is correct |
7 |
Correct |
2084 ms |
912 KB |
Output is correct |
8 |
Correct |
2126 ms |
936 KB |
Output is correct |
9 |
Correct |
2167 ms |
948 KB |
Output is correct |
10 |
Correct |
2082 ms |
972 KB |
Output is correct |
11 |
Correct |
2028 ms |
956 KB |
Output is correct |
12 |
Correct |
2005 ms |
980 KB |
Output is correct |
13 |
Correct |
2013 ms |
968 KB |
Output is correct |
14 |
Correct |
2027 ms |
952 KB |
Output is correct |
15 |
Correct |
1992 ms |
956 KB |
Output is correct |
16 |
Correct |
3687 ms |
308 KB |
Output is correct |
17 |
Execution timed out |
7037 ms |
324 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
352 KB |
Output is correct |
4 |
Correct |
18 ms |
440 KB |
Output is correct |
5 |
Correct |
166 ms |
724 KB |
Output is correct |
6 |
Correct |
2035 ms |
992 KB |
Output is correct |
7 |
Correct |
2084 ms |
912 KB |
Output is correct |
8 |
Correct |
2126 ms |
936 KB |
Output is correct |
9 |
Correct |
2167 ms |
948 KB |
Output is correct |
10 |
Correct |
2082 ms |
972 KB |
Output is correct |
11 |
Correct |
2028 ms |
956 KB |
Output is correct |
12 |
Correct |
2005 ms |
980 KB |
Output is correct |
13 |
Correct |
2013 ms |
968 KB |
Output is correct |
14 |
Correct |
2027 ms |
952 KB |
Output is correct |
15 |
Correct |
1992 ms |
956 KB |
Output is correct |
16 |
Correct |
3687 ms |
308 KB |
Output is correct |
17 |
Execution timed out |
7037 ms |
324 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
2 ms |
352 KB |
Output is correct |
14 |
Correct |
18 ms |
440 KB |
Output is correct |
15 |
Correct |
166 ms |
724 KB |
Output is correct |
16 |
Correct |
2035 ms |
992 KB |
Output is correct |
17 |
Correct |
2084 ms |
912 KB |
Output is correct |
18 |
Correct |
2126 ms |
936 KB |
Output is correct |
19 |
Correct |
2167 ms |
948 KB |
Output is correct |
20 |
Correct |
2082 ms |
972 KB |
Output is correct |
21 |
Correct |
2028 ms |
956 KB |
Output is correct |
22 |
Correct |
2005 ms |
980 KB |
Output is correct |
23 |
Correct |
2013 ms |
968 KB |
Output is correct |
24 |
Correct |
2027 ms |
952 KB |
Output is correct |
25 |
Correct |
1992 ms |
956 KB |
Output is correct |
26 |
Correct |
3687 ms |
308 KB |
Output is correct |
27 |
Execution timed out |
7037 ms |
324 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
2 ms |
352 KB |
Output is correct |
14 |
Correct |
18 ms |
440 KB |
Output is correct |
15 |
Correct |
166 ms |
724 KB |
Output is correct |
16 |
Correct |
2035 ms |
992 KB |
Output is correct |
17 |
Correct |
2084 ms |
912 KB |
Output is correct |
18 |
Correct |
2126 ms |
936 KB |
Output is correct |
19 |
Correct |
2167 ms |
948 KB |
Output is correct |
20 |
Correct |
2082 ms |
972 KB |
Output is correct |
21 |
Correct |
2028 ms |
956 KB |
Output is correct |
22 |
Correct |
2005 ms |
980 KB |
Output is correct |
23 |
Correct |
2013 ms |
968 KB |
Output is correct |
24 |
Correct |
2027 ms |
952 KB |
Output is correct |
25 |
Correct |
1992 ms |
956 KB |
Output is correct |
26 |
Correct |
3687 ms |
308 KB |
Output is correct |
27 |
Execution timed out |
7037 ms |
324 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |