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;
#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;
}
# | 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... |