-
Notifications
You must be signed in to change notification settings - Fork 184
/
Copy pathbinxor.cc
50 lines (44 loc) · 936 Bytes
/
binxor.cc
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
// https://www.codechef.com/DEC19A/problems/BINXOR/
#include <iostream>
using namespace std;
typedef long long ll;
ll p = 1000000007;
int modinv(ll a, ll b) {
ll t, q, x0 = 0, x1 = 1;
if (b == 1) return 1;
while (a > 1) {
q = a / b;
t = b; b = a % b; a = t;
t = x0; x0 = x1 - q * x0; x1 = t;
}
return x1;
}
const int N = 1e5;
ll c[N+1];
int main() {
ll r = 1;
c[0] = 1;
for (int i = 1; i <= N; i++) {
r = r * i % p;
c[i] = r;
}
int n, t;
cin >> t;
while (t--) {
string x, y;
cin >> n >> x >> y;
int a = 0, b = 0;
for (char z : x) a += z == '1';
for (char z : y) b += z == '1';
ll s = 0;
for (int i = abs(a-b), j = 0; j <= n - max(a,b) && i <= min(n, a+b); j++, i += 2) {
ll r = c[n];
ll rr = c[i] * c[n - i] % p;
r = modinv(rr, p) * r % p;
if (r < 0) r += p;
s += r;
if (s >= p) s -= p;
}
cout << s << '\n';
}
}