This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
#define ins insert
const ll inf = numeric_limits<ll> :: max();
const int A = 3e5;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, q; cin>>n>>q;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++){
cin>>a[i];
}
if (n > 11) return 0;
ll out = inf;
int num = 1;
for (int i = 2; i <= n; i++) num *= i;
vector<int> p;
for (int i = 1; i <= n; i++) p.pb(i);
vector<bool> used(A + 1);
while (num--){
vector<int> b(n + 1);
for (int i = 1; i <= n; i++) b[i] = a[p[i - 1]];
ll sum = 0;
for (int i = 1; i <= n; i++){
int cnt = 0;
for (int j = i; j <= n; j++){
if (!used[b[j]]){
used[b[j]] = 1;
cnt++;
}
sum += cnt;
}
for (int j = i; j <= n; j++) used[b[j]] = 0;
}
out = min(out, sum);
next_permutation(p.begin(), p.end());
}
cout<<out<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |