#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 5e3 + 42, INF = 1e18 + 42;
int n, a[N], b[N], nb[N][N], cost[N][N], dp[N];
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 0; i < n; i++)
cin >> a[i];
for(int i = 0; i < n; i++)
cin >> b[i];
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++) {
nb[i][j+1] = nb[i][j];
if(a[i] == b[j])
nb[i][j+1]++;
}
for(int i = 0; i < n; i++) {
int imax = i;
for(int j = i+1; j <= n; j++) {
if(a[imax] < a[j-1])
imax = j-1;
cost[i][j] = nb[imax][j] - nb[imax][i];
}
}
for(int i = 1; i <= n; i++)
for(int j = 0; j < i; j++)
dp[i] = max(dp[i], dp[j] + cost[j][i]);
cout << dp[n];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
324 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
328 KB |
Output is correct |
5 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
20260 KB |
Output is correct |
2 |
Runtime error |
7 ms |
676 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
301 ms |
315076 KB |
Output is correct |
2 |
Runtime error |
9 ms |
816 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
324 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
328 KB |
Output is correct |
5 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
324 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
328 KB |
Output is correct |
5 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |