#include <bits/stdc++.h>
#include <fstream>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define pb push_back
#define INF 20000000000
#define fi first
#define se second
//#define cin fin
//#define cout fout
using namespace std;
//ofstream fout("input.txt");
//ifstream fin("output.txt");
//double const EPS = 1e-14;
typedef long long ll;
//const ll P = 10007;
const ll mod = 1e9 + 7;
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key
int main()
{
ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
int n; cin >> n; int arr1[n], arr2[n];
for(int i = 0; i < n; i++) cin >> arr1[i];
for(int i = 0; i < n; i++) cin >> arr2[i];
queue<int> q; bool ok[n] = {};
ll ans = 0;
for(int i = 0; i < n; i++) {
if(!q.empty() && arr2[i] == 1) {
ok[i] = 1;
int tp = q.front();
q.pop();
ans++;
arr1[tp] = 0;
}
if(arr1[i] == 1 && arr2[i] == 0) q.push(i);
}
while(!q.empty()) q.pop();
for(int i = 0; i < n; i++) {
if(!q.empty() && arr2[i] == 1 && ok[i] == 0) {
ok[i] = 1;
int tp = q.front();
q.pop();
ans++;
arr1[tp] = 0;
}
if(arr1[i] == 1) q.push(i);
}
while(!q.empty()) q.pop();
for(int i = 0; i < n; i++) {
if(arr1[i] == 1) q.push(i);
if(!q.empty() && arr2[i] == 1 && ok[i] == 0) {
int tp = q.front();
q.pop();
if(tp != i) ans++;
}
else if(arr2[i] == 1 && ok[i] == 0){
ans--;
}
}
cout << ans << endl;
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... |