#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";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
7054 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
7054 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
7054 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |