#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define debug(x) cout<<#x<<": "<<x<<"\n"
signed main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// freopen("input.000","r",stdin);
// freopen("output.000","w",stdout);
// srand((unsigned)time(NULL));
// rand()
int n,i,j,k,a[5005],dp[5005],b[5005],m,cost,pos;
cin>>n;
for (i=1;i<n+1;i++) cin>>a[i];
dp[n]=dp[n+1]=0;
for (i=n-1;i>0;i--)
{
dp[i]=1e12;
m=0;
for (j=1;j<n+1;j++) if (a[j]>=i)
{
m++;b[m]=a[j];
}
for (j=i+1;j<=n+1;j++)
{
cost=0;
for (k=i;k<j;k++)
{
pos=1;
while (b[pos]!=k)
{
if (b[pos]<k or b[pos]>=j) cost++;
// cout<<pos<<" "<<cost<<" "<<k<<" "<<j<<" "<<b[pos]<<"\n";
pos++;
}
}
dp[i]=min(dp[i], cost + dp[j]);
// cout<<i<<" "<<j<<" "<<cost+dp[j]<<"\n";
}
}
// for (i=1;i<n+1;i++) cout<<dp[i]<<" ";
cout<<dp[1];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
432 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
432 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
432 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
432 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
436 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
432 KB |
Output is correct |
17 |
Correct |
0 ms |
368 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
432 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
432 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
436 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
432 KB |
Output is correct |
17 |
Correct |
0 ms |
368 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
243 ms |
416 KB |
Output is correct |
22 |
Correct |
218 ms |
412 KB |
Output is correct |
23 |
Correct |
225 ms |
408 KB |
Output is correct |
24 |
Correct |
246 ms |
412 KB |
Output is correct |
25 |
Correct |
282 ms |
412 KB |
Output is correct |
26 |
Correct |
239 ms |
424 KB |
Output is correct |
27 |
Correct |
240 ms |
416 KB |
Output is correct |
28 |
Correct |
248 ms |
416 KB |
Output is correct |
29 |
Correct |
248 ms |
340 KB |
Output is correct |
30 |
Correct |
250 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
432 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
432 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
436 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
432 KB |
Output is correct |
17 |
Correct |
0 ms |
368 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
243 ms |
416 KB |
Output is correct |
22 |
Correct |
218 ms |
412 KB |
Output is correct |
23 |
Correct |
225 ms |
408 KB |
Output is correct |
24 |
Correct |
246 ms |
412 KB |
Output is correct |
25 |
Correct |
282 ms |
412 KB |
Output is correct |
26 |
Correct |
239 ms |
424 KB |
Output is correct |
27 |
Correct |
240 ms |
416 KB |
Output is correct |
28 |
Correct |
248 ms |
416 KB |
Output is correct |
29 |
Correct |
248 ms |
340 KB |
Output is correct |
30 |
Correct |
250 ms |
340 KB |
Output is correct |
31 |
Execution timed out |
5038 ms |
340 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
432 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
432 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
436 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
432 KB |
Output is correct |
17 |
Correct |
0 ms |
368 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
243 ms |
416 KB |
Output is correct |
22 |
Correct |
218 ms |
412 KB |
Output is correct |
23 |
Correct |
225 ms |
408 KB |
Output is correct |
24 |
Correct |
246 ms |
412 KB |
Output is correct |
25 |
Correct |
282 ms |
412 KB |
Output is correct |
26 |
Correct |
239 ms |
424 KB |
Output is correct |
27 |
Correct |
240 ms |
416 KB |
Output is correct |
28 |
Correct |
248 ms |
416 KB |
Output is correct |
29 |
Correct |
248 ms |
340 KB |
Output is correct |
30 |
Correct |
250 ms |
340 KB |
Output is correct |
31 |
Execution timed out |
5038 ms |
340 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |