This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
vector<int>h, t;
vector<bool>vis;
int n;
int d[] = {-1, 1};
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
h.resize(n + 1);
t.resize(n + 1);
vis.resize(n + 1, 0);
for(int i = 1; i <= n; i++) cin >> h[i];
for(int i = 1; i <= n; i++) cin >> t[i];
queue<int>q;
int x = t[1];
int ans = 0;
for(int i = 1; i <= n; i++){
if(h[i] == x){
q.push(i);
ans++;
vis[i] = true;
}
}
while(!q.empty()){
int cur = q.front(); q.pop();
for(int i = 0; i < 2; i++){
int nxt = cur + d[i];
if(nxt > 0 && nxt <= n && h[nxt] < x && !vis[nxt]){
vis[nxt] = true;
q.push(nxt);
ans++;
}
}
}
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |