#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 300 + 7;
int a[N], pos[N], dp[N][N][N];
int main() {
#ifdef ONPC
freopen("input.txt", "r", stdin);
#else
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#endif // ONPC
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
pos[a[i]] = i;
}
for (int len = 1; len <= n; len++) {
for (int l = 1; l + len - 1 <= n; l++) {
for (int t = 1; t <= 300 && t + len - 1 <= n; t++) {
int r = l + len - 1;
int tt = t + len - 1;
if (a[l] == t) {
dp[len][l][t] = dp[len - 1][l + 1][t + 1] + 1;
} else if (a[r] == t) {
dp[len][l][t] = dp[len - 1][l][t + 1] + 1;
} else if (a[l] == tt) {
dp[len][l][t] = dp[len - 1][l + 1][t] + 1;
} else if (a[r] == tt) {
dp[len][l][t] = dp[len - 1][l][t] + 1;
} else {
dp[len][l][t] = max({dp[len - 1][l][t], dp[len - 1][l + 1][t], dp[len - 1][l][t + 1], dp[len - 1][l + 1][t + 1]});
}
}
}
}
cout << n - dp[n][1][1] << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
6608 KB |
Output is correct |
16 |
Correct |
1 ms |
6744 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
6608 KB |
Output is correct |
16 |
Correct |
1 ms |
6744 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
12636 KB |
Output is correct |
22 |
Correct |
5 ms |
37212 KB |
Output is correct |
23 |
Correct |
12 ms |
69980 KB |
Output is correct |
24 |
Correct |
18 ms |
90704 KB |
Output is correct |
25 |
Correct |
26 ms |
107084 KB |
Output is correct |
26 |
Correct |
28 ms |
111168 KB |
Output is correct |
27 |
Correct |
28 ms |
111132 KB |
Output is correct |
28 |
Correct |
28 ms |
111196 KB |
Output is correct |
29 |
Correct |
30 ms |
111384 KB |
Output is correct |
30 |
Correct |
29 ms |
111448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
6608 KB |
Output is correct |
16 |
Correct |
1 ms |
6744 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
1 ms |
6492 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
12636 KB |
Output is correct |
22 |
Correct |
5 ms |
37212 KB |
Output is correct |
23 |
Correct |
12 ms |
69980 KB |
Output is correct |
24 |
Correct |
18 ms |
90704 KB |
Output is correct |
25 |
Correct |
26 ms |
107084 KB |
Output is correct |
26 |
Correct |
28 ms |
111168 KB |
Output is correct |
27 |
Correct |
28 ms |
111132 KB |
Output is correct |
28 |
Correct |
28 ms |
111196 KB |
Output is correct |
29 |
Correct |
30 ms |
111384 KB |
Output is correct |
30 |
Correct |
29 ms |
111448 KB |
Output is correct |
31 |
Runtime error |
3 ms |
604 KB |
Execution killed with signal 11 |
32 |
Halted |
0 ms |
0 KB |
- |