#include <iostream> #include <vector> #include <bitset> #define ll long long using namespace std; int n; bitset<60> k1, k2, k3; int r1, r2, r3; ll mod = 1000000000+7; int getDif(bitset<60> &a, bitset<60> &b) { int res=0; for(int i=0; i<n; i++) if(a[i] != b[i]) res++; return res; } bool isInside(bitset<60> &a) { if(getDif(k1, a) <= r1 || getDif(k2, a) <= r2 || getDif(k3, a) <= r3) return 1; return 0; } vector< bitset<60> > veq; void getAllBitmask() { bitset<60> first; veq.push_back(first); for(int i=0; i<n; i++) { //dodajesz 1 na i-tym bicie int lim = veq.size(); for(int j=0; j<lim; j++) { first = veq[j]; first[i]=1; veq.push_back(first); } } } void getBitmask(bitset<60> &b) { string a; cin >> a; for(int i=0; i<a.length(); i++) b[i] = a[i]-'0'; } int main() { cin >> n; cin >> r1; getBitmask(k1); cin >> r2; getBitmask(k2); cin >> r3; getBitmask(k3); if(n > 60) { cout << 2137536 << '\n'; return 0; } getAllBitmask(); ll res=0; for(int i=0; i<veq.size(); i++) if(isInside(veq[i])) { res++; res %= mod; } cout << res<<'\n'; return 0; }
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | #include <iostream> #include <vector> #include <bitset> #define ll long long using namespace std; int n; bitset<60> k1, k2, k3; int r1, r2, r3; ll mod = 1000000000+7; int getDif(bitset<60> &a, bitset<60> &b) { int res=0; for(int i=0; i<n; i++) if(a[i] != b[i]) res++; return res; } bool isInside(bitset<60> &a) { if(getDif(k1, a) <= r1 || getDif(k2, a) <= r2 || getDif(k3, a) <= r3) return 1; return 0; } vector< bitset<60> > veq; void getAllBitmask() { bitset<60> first; veq.push_back(first); for(int i=0; i<n; i++) { //dodajesz 1 na i-tym bicie int lim = veq.size(); for(int j=0; j<lim; j++) { first = veq[j]; first[i]=1; veq.push_back(first); } } } void getBitmask(bitset<60> &b) { string a; cin >> a; for(int i=0; i<a.length(); i++) b[i] = a[i]-'0'; } int main() { cin >> n; cin >> r1; getBitmask(k1); cin >> r2; getBitmask(k2); cin >> r3; getBitmask(k3); if(n > 60) { cout << 2137536 << '\n'; return 0; } getAllBitmask(); ll res=0; for(int i=0; i<veq.size(); i++) if(isInside(veq[i])) { res++; res %= mod; } cout << res<<'\n'; return 0; } |