#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const long long N = 3e5 + 5;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, q; cin >> n >> q;
vector <int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
int l, r; cin >> l >> r;
ll ans = 0;
for (int i = 0; i < n; i++) {
set<int> s;
for (int j = i; j < n; j++) {
s.insert(a[j]);
ans += s.size();
}
} map <vector <int>, int> used;
used[a] = 1;
while (next_permutation(a.begin(), a.end())) {
if (used[a]) continue;
used[a] = 1;
ll res = 0;
for (int i = 0; i < n; i++) {
set<int> s;
for (int j = i; j < n; j++) {
s.insert(a[j]);
res += s.size();
}
} ans = min(ans, res);
} cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
5 ms |
596 KB |
Output is correct |
4 |
Correct |
24 ms |
1660 KB |
Output is correct |
5 |
Correct |
492 ms |
26636 KB |
Output is correct |
6 |
Correct |
3464 ms |
160988 KB |
Output is correct |
7 |
Correct |
281 ms |
11596 KB |
Output is correct |
8 |
Execution timed out |
7018 ms |
280288 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
7050 ms |
57312 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
7050 ms |
57312 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
7050 ms |
57312 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
5 ms |
596 KB |
Output is correct |
4 |
Correct |
24 ms |
1660 KB |
Output is correct |
5 |
Correct |
492 ms |
26636 KB |
Output is correct |
6 |
Correct |
3464 ms |
160988 KB |
Output is correct |
7 |
Correct |
281 ms |
11596 KB |
Output is correct |
8 |
Execution timed out |
7018 ms |
280288 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
5 ms |
596 KB |
Output is correct |
4 |
Correct |
24 ms |
1660 KB |
Output is correct |
5 |
Correct |
492 ms |
26636 KB |
Output is correct |
6 |
Correct |
3464 ms |
160988 KB |
Output is correct |
7 |
Correct |
281 ms |
11596 KB |
Output is correct |
8 |
Execution timed out |
7018 ms |
280288 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |