# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
963952 | Aiperiii | Money (IZhO17_money) | C++14 | 221 ms | 262144 KiB |
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>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int N=1e3+5;
int cnt[N][N];
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
int n;
cin>>n;
vector <int> a(n+1);
vector <int> sr;
for(int i=1;i<=n;i++){
cin>>a[i];
}
vector <int> v;
vector <vector <int> > vec;
vec.pb({});
for(int i=1;i<=n;i++){
v.pb(a[i]);
vec.pb(v);
}
for(int i=0;i<vec.size();i++){
sort(all(vec[i]));
}
for(int i=0;i<=n;i++){
for(int j=0;j<=n;j++){
cnt[i][j]=1e9;
}
}
cnt[0][0]=0;
for(int i=1;i<=n;i++){
for(int j=i;j<=n;j++){
int mn=1e9,ind=-1;
for(int k=j;k>=i;k--){
bool ok=0;
auto it=upper_bound(all(vec[k-1]),a[k]);
if(it==vec[k-1].end() or *it>=a[j])ok=1;
if(ok){
cnt[i][j]=min(cnt[i][j],cnt[i-1][k-1]+1);
}
if(k-1>=i && a[k]<a[k-1])break;
}
}
}
for(int i=1;i<=n;i++){
if(cnt[i][n]!=1e9){
cout<<i<<"\n";return 0;
}
}
}
/*
6
3 6 4 5 1 2
*/
Compilation message (stderr)
# | 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... |