#include<bits/stdc++.h>
#define int long long
#define MOD 1000000007
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int32_t main(){
int n;
cin>>n;
int a[n],b[n];
set<int>s;
for(int i=0;i<n;i++){
cin>>a[i];
s.insert(a[i]);
}
for(int i=0;i<n;i++)cin>>b[i];
if(*max_element(b,b+n)==*min_element(b,b+n)){
int c[n],ans=0;
for(int i=0;i<n;i++){
if(a[i]>b[i])continue;
if(!c[i]){
c[i]=1;
ans++;
}
for(int j=i-1;j>=0;j--){
if(a[j]>=b[j])break;
if(!c[j]){
c[j]=1;
ans++;
}
}
for(int j=i+1;j<n;j++){
if(a[j]>=b[j])break;
if(!c[j]){
c[j]=1;
ans++;
}
}
}
cout<<ans<<endl;
return 0;
}
vector<pair<int,int>>v;
for(int i=0;i<n;i++){
if(a[i]>b[i] || !s.count(b[i]))continue;
v.pb({b[i],i});
}
sort(all(v));
int dp[v.size()],ans=0;
for(int i=0;i<(int)v.size();i++){
int mx=0;
for(int j=0;j<i;j++){
if(v[i].ss>v[j].ss)mx=max(mx,dp[j]);
}
dp[i]=mx+1;
ans=max(ans,mx+1);
}
cout<<ans<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
224 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
4 ms |
340 KB |
Output is correct |
4 |
Correct |
25 ms |
816 KB |
Output is correct |
5 |
Correct |
10 ms |
728 KB |
Output is correct |
6 |
Correct |
12 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
12 ms |
728 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
224 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Incorrect |
3 ms |
212 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
224 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
4 ms |
340 KB |
Output is correct |
10 |
Correct |
25 ms |
816 KB |
Output is correct |
11 |
Correct |
10 ms |
728 KB |
Output is correct |
12 |
Correct |
12 ms |
724 KB |
Output is correct |
13 |
Incorrect |
3 ms |
212 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |