0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2025-01-11 16:31:58 +00:00
Baoshuo Ren 2021-12-25 00:08:38 +08:00
parent 523f43341f
commit a3fe24e2d5
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

46
CodeForces/1615/C/C.cpp Normal file
View File

@ -0,0 +1,46 @@
#include <iostream>
#include <string>
using std::cin;
using std::cout;
using std::endl;
int main() {
int t;
cin >> t;
while (t--) {
int n, cnt1 = 0, cnt2 = 0;
std::string a, b;
cin >> n >> a >> b;
for (char c : a) {
cnt1 += c == '1';
}
for (char c : b) {
cnt2 += c == '1';
}
if (cnt1 != cnt2 && n - cnt1 + 1 != cnt2) {
cout << -1 << endl;
continue;
}
int m0 = 0, m1 = 0;
for (int i = 0; i < n; i++) {
if (b[i] == '1') {
if (a[i] == '0') {
m0++;
} else {
m1++;
}
}
}
int a1 = (cnt2 - m1) * 2,
a2 = (cnt2 - m0) * 2 - 1;
if (cnt1 != cnt2) {
cout << a2 << endl;
} else if (n - cnt1 + 1 != cnt2) {
cout << a1 << endl;
} else {
cout << std::min(a1, a2) << endl;
}
}
return 0;
}