#include<bits/stdc++.h>
using namespace std;
int n;
vector<int> h(100002), t(100002);
map<pair<int, vector<int>>, int> m;
int dp(int i, vector<int> v){
if(i == n) return 0;
if(m.count({i, v})>0) return m[{i, v}];
int best=dp(i+1, v);
vector<int> temp=v;
for(int j=i; j<n; j++){
if(v[j] > t[i]) break;
if(v[j] == t[i]){
while(j>i){
v[j]=t[i];
j--;
}
best=max(best, dp(i+1, v)+1);
break;
}
}
v=temp;
for(int j=i; j>=0; j--){
if(v[j] > t[i]) break;
if(v[j] == t[i]){
while(j<i){
v[j]=t[i];
j++;
}
best=max(best, dp(i+1, v)+1);
break;
}
}
m[{i, temp}]=best;
return best;
}
int main(){
cin>>n;
for(int i=0; i<n; i++){
cin>>h[i];
}
for(int j=0; j<n; j++){
cin>>t[j];
}
cout<<dp(0, h);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2636 KB |
Output is correct |
2 |
Correct |
3 ms |
3788 KB |
Output is correct |
3 |
Correct |
3 ms |
5324 KB |
Output is correct |
4 |
Correct |
5 ms |
6092 KB |
Output is correct |
5 |
Correct |
14 ms |
18252 KB |
Output is correct |
6 |
Correct |
5 ms |
8140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
216 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
26896 KB |
Output is correct |
2 |
Runtime error |
216 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
185 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2636 KB |
Output is correct |
2 |
Correct |
3 ms |
3788 KB |
Output is correct |
3 |
Correct |
3 ms |
5324 KB |
Output is correct |
4 |
Correct |
5 ms |
6092 KB |
Output is correct |
5 |
Correct |
14 ms |
18252 KB |
Output is correct |
6 |
Correct |
5 ms |
8140 KB |
Output is correct |
7 |
Correct |
4 ms |
6476 KB |
Output is correct |
8 |
Runtime error |
661 ms |
524288 KB |
Execution killed with signal 9 |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2636 KB |
Output is correct |
2 |
Correct |
3 ms |
3788 KB |
Output is correct |
3 |
Correct |
3 ms |
5324 KB |
Output is correct |
4 |
Correct |
5 ms |
6092 KB |
Output is correct |
5 |
Correct |
14 ms |
18252 KB |
Output is correct |
6 |
Correct |
5 ms |
8140 KB |
Output is correct |
7 |
Correct |
15 ms |
26896 KB |
Output is correct |
8 |
Runtime error |
216 ms |
524288 KB |
Execution killed with signal 9 |
9 |
Halted |
0 ms |
0 KB |
- |