#include"bits/stdc++.h"
using namespace std;
#define ll long long
const ll mod = 1000000007;
int b[1000001];
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n;
cin >> n;
int a[n];
for(int i = 0; i < n; i++)
cin >> a[i];
int ans = n;
for(int i = 0; i <= (1 << n); i++) {
b[1] = 1e6;
set<int> s;
s.insert(-1);
bool bad = 0;
int cur = 0;
for(int j = 0; j < n; j++) {
int l = j, r;
for(int k = j; k < n; k++) {
r = k;
if(i & (1 << k))
break;
if(k - 1 >= j && a[k] < a[k - 1])
bad = 1;
}
int g = *s.lower_bound(-a[j]) * -1;
if(a[r] > b[g])
bad = 1;
if(bad)
break;
b[a[r]] = b[g];
b[g] = a[l];
s.insert(-a[r]);
s.insert(-g);
for(int k = l; k < r; k++) {
b[a[k]] = a[k + 1];
s.insert(-a[k]);
}
cur++;
j = r;
}
if(!bad)
ans = min(ans, cur);
while(s.size()) {
b[*s.begin()] = 0;
s.erase(s.begin());
}
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
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 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
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 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
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 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |