이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define PB push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int N = 310;
const int oo = 2e9;
int a[N], n, f[N];
vector<int> vc;
bool ok(int l, int r){
if (r >= n) return 0;
for (int j = l + 1; j <= r; j++)
if (a[j] < a[j - 1])
return 0;
int lc = -1;
while (lc < sz(vc) - 1 && vc[lc + 1] <= a[l])
lc++;
if (lc + 1 == sz(vc)) return 1;
if (vc[lc + 1] >= a[r])
return 1;
else return 0;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
// freopen("in.txt","r",stdin);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
vc.PB(a[i]);
}
f[n] = 0;
for (int it = n - 1; it >= 0; it--){
for (int i = 0; i < sz(vc); i++){
if (vc[i] == a[it]){
swap(vc[i], vc.back());
vc.pop_back();
break;
}
}
sort(all(vc));
int mx = it;
for (; mx < n; mx++)
if (!ok(it, mx + 1))
break;
f[it] = oo;
for (int i = it; i <= mx; i++)
f[it] = min(f[it], f[i + 1] + 1);
}
cout << f[0];
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... |