#include <bits/stdc++.h>
#define int long long
#define mod 1000000007
#define endl '\n'
using namespace std;
bool m[5000];
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n;
cin>>n;
bool bol=true;
pair<int,int>pr[n];
for(int i=0;i<n;i++){
cin>>pr[i].first;
}
for(int i=0;i<n;i++){
cin>>pr[i].second;
if(i>0&&pr[i].second!=pr[i-1].second)bol=false;
}
if(!bol){
int ans=0,z=0,b=pr[0].second;
bool bl=false;
for(int i=0;i<n;i++){
if(pr[i].first==b){
bl=true;
}
if(pr[i].first<=b&&i!=n-1){
z++;
}
else if(bl){
ans+=z+(pr[i].first<=b?1:0);
z=0;
bl=false;
}
else{
z=0;
}
}
cout<<ans;
}
else{
for(int i=n-1;i>=0;i--){
int a=0,b=0,z=n;
for(int w=i;w>=0;w--){
if(m[w])b++;
if(pr[w].second==pr[i].first)a++;
if(a>b)z=w;
}
for(int w=i;w>=z;w--){
if(pr[w].second==pr[i].first)m[w]=true;
else m[w]=false;
}
}
int ans=0;
for(int i=0;i<n;i++){
if(m[i])ans++;
}
cout<<ans;
}
}
//5 1 1 1 6 5
//5 5 6 5 6
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |