#include <bits/stdc++.h>
using namespace std;
int A[5050], B[5050], C[5050], D[5050];
int n, a;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int i, j, m;
cin >> n;
for (i = 1; i <= n; i++) {
cin >> A[i];
}
for (i = 1; i <= n; i++) {
cin >> B[i];
}
for (i = 1; i <= n; i++) {
for (j = i, m = A[i]; j <= n; j++) {
if (m <= A[j]) C[j] = 1, m = A[j];
else C[j] = 0;
}
for (j = i, m = A[i]; j >= 1; j--) {
if (m <= A[j]) C[j] = 1, m = A[j];
else C[j] = 0;
}
for (j = 1, m = 0; j <= n; j++) {
m = max(m, D[j]);
if (C[j]) D[j] = m + (B[i] == A[j]);
else D[j] = 0;
a = max(a, D[j]);
}
}
cout << a << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
364 KB |
Output is correct |
2 |
Runtime error |
2 ms |
748 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
11 ms |
364 KB |
Output is correct |
4 |
Correct |
62 ms |
620 KB |
Output is correct |
5 |
Correct |
64 ms |
492 KB |
Output is correct |
6 |
Correct |
65 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
67 ms |
576 KB |
Output is correct |
2 |
Runtime error |
2 ms |
748 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
11 ms |
364 KB |
Output is correct |
10 |
Correct |
62 ms |
620 KB |
Output is correct |
11 |
Correct |
64 ms |
492 KB |
Output is correct |
12 |
Correct |
65 ms |
492 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
4 ms |
364 KB |
Output is correct |
23 |
Correct |
64 ms |
492 KB |
Output is correct |
24 |
Correct |
172 ms |
492 KB |
Output is correct |
25 |
Correct |
89 ms |
620 KB |
Output is correct |
26 |
Correct |
74 ms |
492 KB |
Output is correct |
27 |
Correct |
68 ms |
504 KB |
Output is correct |
28 |
Correct |
70 ms |
492 KB |
Output is correct |
29 |
Correct |
64 ms |
492 KB |
Output is correct |
30 |
Correct |
68 ms |
620 KB |
Output is correct |
31 |
Correct |
64 ms |
492 KB |
Output is correct |
32 |
Correct |
65 ms |
492 KB |
Output is correct |