#include <bits/stdc++.h>
using namespace std;
const int lmt = 5005;
const long long MOD = 1000000007;
#define f first
#define S second
#define ll long long
#define ld long double
#define ull unsigned long long
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define for1(i, n) for(int i = 1; i < int(n); i++)
#define forv(i,a,n) for(int i = int(a); i < int(n); i++)
#define rof(i, n) for(int i = int(n); i >= 0; i--)
#define rofv(i,a,n) for(int i = int(n); i >= int(a); i--)
#define pb push_back
#define ins insert
#define pai pair<int, int>
#define pal pair<long long, long long>
#define vi vector<int>
#define vl vector<long long>
#define vld vector<long double>
int dp[lmt];
int n, p[lmt];
/*
struct wer{
int a, b;
};
bool operator < (const wer &a, const wer &b){
return a.a < b.a;
}*/
vi a[lmt];
int precalc[lmt][lmt];
int buc[lmt][lmt];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin>>n;
for1(i, n+1){
cin>>p[i];
}
for1(i,n+1){
for1(j,n+1){
if(p[j]>=i){
buc[i][p[j]] = a[i].size();
a[i].pb(p[j]);
}
}
}
for1(i,n+1){
int j = i;
int D = 0;
vi r;
while(j<=n){
D += buc[i][j];
for(int g = 0; g < r.size(); g++){
if(r[g]>buc[i][j]){
D--;
}
}
precalc[i][j] = D;
r.pb(buc[i][j]);
j++;
}
}
memset(dp, 1, sizeof(dp));
dp[n+1]=0;
for(int i = n; i > 0; i--){
for(int j = i; j <= n; j++){
dp[i] = min(dp[i], precalc[i][j] + dp[j+1]);
}
}
cout<<dp[1];
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:57:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for(int g = 0; g < r.size(); g++){
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
588 KB |
Output is correct |
12 |
Correct |
1 ms |
588 KB |
Output is correct |
13 |
Correct |
1 ms |
588 KB |
Output is correct |
14 |
Correct |
1 ms |
588 KB |
Output is correct |
15 |
Correct |
1 ms |
588 KB |
Output is correct |
16 |
Correct |
1 ms |
588 KB |
Output is correct |
17 |
Correct |
1 ms |
588 KB |
Output is correct |
18 |
Correct |
1 ms |
588 KB |
Output is correct |
19 |
Correct |
1 ms |
588 KB |
Output is correct |
20 |
Correct |
1 ms |
556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
588 KB |
Output is correct |
12 |
Correct |
1 ms |
588 KB |
Output is correct |
13 |
Correct |
1 ms |
588 KB |
Output is correct |
14 |
Correct |
1 ms |
588 KB |
Output is correct |
15 |
Correct |
1 ms |
588 KB |
Output is correct |
16 |
Correct |
1 ms |
588 KB |
Output is correct |
17 |
Correct |
1 ms |
588 KB |
Output is correct |
18 |
Correct |
1 ms |
588 KB |
Output is correct |
19 |
Correct |
1 ms |
588 KB |
Output is correct |
20 |
Correct |
1 ms |
556 KB |
Output is correct |
21 |
Correct |
4 ms |
2252 KB |
Output is correct |
22 |
Correct |
3 ms |
2252 KB |
Output is correct |
23 |
Correct |
3 ms |
2252 KB |
Output is correct |
24 |
Correct |
4 ms |
2252 KB |
Output is correct |
25 |
Correct |
3 ms |
2252 KB |
Output is correct |
26 |
Correct |
3 ms |
2252 KB |
Output is correct |
27 |
Correct |
3 ms |
2252 KB |
Output is correct |
28 |
Correct |
4 ms |
2304 KB |
Output is correct |
29 |
Correct |
3 ms |
2252 KB |
Output is correct |
30 |
Correct |
3 ms |
2252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
588 KB |
Output is correct |
12 |
Correct |
1 ms |
588 KB |
Output is correct |
13 |
Correct |
1 ms |
588 KB |
Output is correct |
14 |
Correct |
1 ms |
588 KB |
Output is correct |
15 |
Correct |
1 ms |
588 KB |
Output is correct |
16 |
Correct |
1 ms |
588 KB |
Output is correct |
17 |
Correct |
1 ms |
588 KB |
Output is correct |
18 |
Correct |
1 ms |
588 KB |
Output is correct |
19 |
Correct |
1 ms |
588 KB |
Output is correct |
20 |
Correct |
1 ms |
556 KB |
Output is correct |
21 |
Correct |
4 ms |
2252 KB |
Output is correct |
22 |
Correct |
3 ms |
2252 KB |
Output is correct |
23 |
Correct |
3 ms |
2252 KB |
Output is correct |
24 |
Correct |
4 ms |
2252 KB |
Output is correct |
25 |
Correct |
3 ms |
2252 KB |
Output is correct |
26 |
Correct |
3 ms |
2252 KB |
Output is correct |
27 |
Correct |
3 ms |
2252 KB |
Output is correct |
28 |
Correct |
4 ms |
2304 KB |
Output is correct |
29 |
Correct |
3 ms |
2252 KB |
Output is correct |
30 |
Correct |
3 ms |
2252 KB |
Output is correct |
31 |
Correct |
76 ms |
11124 KB |
Output is correct |
32 |
Correct |
78 ms |
11216 KB |
Output is correct |
33 |
Correct |
80 ms |
11184 KB |
Output is correct |
34 |
Correct |
80 ms |
11132 KB |
Output is correct |
35 |
Correct |
79 ms |
11208 KB |
Output is correct |
36 |
Correct |
78 ms |
11244 KB |
Output is correct |
37 |
Correct |
81 ms |
11204 KB |
Output is correct |
38 |
Correct |
77 ms |
11184 KB |
Output is correct |
39 |
Correct |
77 ms |
11232 KB |
Output is correct |
40 |
Correct |
80 ms |
11240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
588 KB |
Output is correct |
12 |
Correct |
1 ms |
588 KB |
Output is correct |
13 |
Correct |
1 ms |
588 KB |
Output is correct |
14 |
Correct |
1 ms |
588 KB |
Output is correct |
15 |
Correct |
1 ms |
588 KB |
Output is correct |
16 |
Correct |
1 ms |
588 KB |
Output is correct |
17 |
Correct |
1 ms |
588 KB |
Output is correct |
18 |
Correct |
1 ms |
588 KB |
Output is correct |
19 |
Correct |
1 ms |
588 KB |
Output is correct |
20 |
Correct |
1 ms |
556 KB |
Output is correct |
21 |
Correct |
4 ms |
2252 KB |
Output is correct |
22 |
Correct |
3 ms |
2252 KB |
Output is correct |
23 |
Correct |
3 ms |
2252 KB |
Output is correct |
24 |
Correct |
4 ms |
2252 KB |
Output is correct |
25 |
Correct |
3 ms |
2252 KB |
Output is correct |
26 |
Correct |
3 ms |
2252 KB |
Output is correct |
27 |
Correct |
3 ms |
2252 KB |
Output is correct |
28 |
Correct |
4 ms |
2304 KB |
Output is correct |
29 |
Correct |
3 ms |
2252 KB |
Output is correct |
30 |
Correct |
3 ms |
2252 KB |
Output is correct |
31 |
Correct |
76 ms |
11124 KB |
Output is correct |
32 |
Correct |
78 ms |
11216 KB |
Output is correct |
33 |
Correct |
80 ms |
11184 KB |
Output is correct |
34 |
Correct |
80 ms |
11132 KB |
Output is correct |
35 |
Correct |
79 ms |
11208 KB |
Output is correct |
36 |
Correct |
78 ms |
11244 KB |
Output is correct |
37 |
Correct |
81 ms |
11204 KB |
Output is correct |
38 |
Correct |
77 ms |
11184 KB |
Output is correct |
39 |
Correct |
77 ms |
11232 KB |
Output is correct |
40 |
Correct |
80 ms |
11240 KB |
Output is correct |
41 |
Execution timed out |
5047 ms |
139800 KB |
Time limit exceeded |
42 |
Halted |
0 ms |
0 KB |
- |