#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const long long N = 3e5 + 5;
long long cont (long long r) {
return (r + 1) * (r) / 2;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, q; cin >> n >> q;
vector <int> b(n), a;
map <int, int> cnt;
for (int i = 0; i < n; i++) {
cin >> b[i];
cnt[b[i]]++;
} for (auto it : cnt) a.push_back(it.second);
n = a.size();
int l, r; cin >> l >> r;
ll ans = 0;
for (int i = 0; i < a.size(); i++) {
ll k = 2, nwres = a[i];
for (int j = i + 1; j < a.size(); j++) {
nwres += k * a[j], k++;
} ans += nwres * a[i] - cont(a[i] - 1);
} map <vector <int>, int> used;
used[a] = 1;
while (next_permutation(a.begin(), a.end())) {
if (used[a]) continue;
used[a] = 1;
ll x = 0;
for (int i = 0; i < a.size(); i++) {
ll k = 2, nwres = a[i];
for (int j = i + 1; j < a.size(); j++) {
nwres += k * a[j], k++;
} x += nwres * a[i] - cont(a[i] - 1);
} ans = min(ans, x);
} cout << ans << '\n';
return 0;
}
Compilation message
diversity.cpp: In function 'int main()':
diversity.cpp:21:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for (int i = 0; i < a.size(); i++) {
| ~~^~~~~~~~~~
diversity.cpp:23:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for (int j = i + 1; j < a.size(); j++) {
| ~~^~~~~~~~~~
diversity.cpp:32:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for (int i = 0; i < a.size(); i++) {
| ~~^~~~~~~~~~
diversity.cpp:34:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for (int j = i + 1; j < a.size(); j++) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |