#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MX = 5005;
int N;
int H[MX], T[MX], dp[MX][MX], mx[MX][MX];
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
cin >> N;
for(int i = 1; i <= N; i++) cin >> H[i];
for(int i = 1; i <= N; i++) cin >> T[i];
for(int i = N; i >= 1; i--) {
for(int j = i; j <= N; j++) {
dp[i][j] = max(dp[i][j], mx[i + 1][j] + (T[i] == H[j]));
}
for(int j = N; j >= 1; j--) {
mx[i][j] = max(dp[i][j], mx[i][j + 1]);
}
}
cout << mx[1][1] << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
14216 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
4 ms |
5844 KB |
Output is correct |
3 |
Correct |
34 ms |
39920 KB |
Output is correct |
4 |
Correct |
148 ms |
157428 KB |
Output is correct |
5 |
Correct |
158 ms |
165232 KB |
Output is correct |
6 |
Correct |
159 ms |
165356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
160 ms |
165280 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |