#include<bits/stdc++.h>
#define ll long long
#define endl "\n"
#define fi first
#define se second
#define pb push_back
#define pll pair<long long, long long>
#define loop(i,n) for(int i=1;i<=n;i++)
#define loop0(i,n) for(int i=0;i<n;i++)
using namespace std;
//pbds template
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
ll n;
ll arr[5005] = {0};
ll beda[5005] = {0};
map<ll,ll> mp;
map<ll,ll> mp2;
void case1(ll chk){
if(!mp.count(chk)){
cout << "0" << endl;
return;
}
priority_queue<ll> pq;
ll ans = 0;
for(int i=1;i<=n;i++){
// cout << i << ' ' << pq.size() << endl;
if(arr[i]>chk){
if(pq.empty()) continue;
if(pq.top()==chk) ans += pq.size();
pq = priority_queue<ll>();
}
else if(arr[i]<=chk) pq.push(arr[i]);
}
if(!pq.empty()&&pq.top()==chk){
ans += pq.size();
}
cout << ans << endl;
return;
}
void solve(){
cin >> n;
for(int i=1;i<=n;i++){
cin >> arr[i];
mp[arr[i]] = 1;
}
ll chk;
ll cnt = 0;
for(int i=1;i<=n;i++){
cin >> beda[i];
chk = beda[i];
if(mp2.count(chk)) continue;
mp2[beda[i]] = 1;
cnt++;
}
// cout << mp2.size() << endl;
if(cnt==1){
case1(chk);
return;
}
else{
cout << '0' << endl;
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tc = 1;
// cin >> tc;
while(tc--){
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Runtime error |
2 ms |
468 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
852 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |