-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaxmex.cpp
58 lines (50 loc) · 1.08 KB
/
maxmex.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<ll, ll>;
using vi = vector<ll>;
void solve() {
int n;
cin >> n;
vector<char> ai(n);
vector<char> bi(n);
vi a(n);
for (int i = 0; i < n; i++) {
cin >> ai[i];
}
for (int i = 0; i < n; i++) {
cin >> bi[i];
}
int zeros = 0;
for (int i = 0; i < n; i++) {
char x = ai[i];
char y = bi[i];
if (x == y && x == '0') {
a[i] = 0;
zeros++;
}
if (x == y && x == '1') a[i] = 1;
if (x != y) a[i] = 2;
}
int ans = 0;
bool sol = false;
for (int i = 0; i < n; i++) {
if (a[i] == 2) ans += 2;
if (i != 0 && !sol && ((a[i] == 1 && a[i - 1] == 0) || (a[i] == 0 && a[i - 1] == 1))) {
ans += 2;
sol = true;
zeros--;
} else
sol = false;
}
ans += zeros;
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) solve();
return 0;
}