#include <vector>
#include <iostream>
#if defined (_MSC_VER)
#include <intrin.h>
#define popcnt __popcnt
#else
#define popcnt __builtin_popcount
#endif
//using ull = unsigned long long;
using ul = unsigned long;
struct sphere
{
ul center;
ul coords;
};
short n;
sphere sphereA, sphereB, sphereC;
inline bool intersects(const sphere& s, const ul point)
{
return popcnt(s.coords ^ point) <= s.center;
}
ul solve()
{
const ul maxDim = ul(1) << n;
ul answer = 0;
for(ul x = 0; x < maxDim; ++x)
{
if (intersects(sphereA, x) || intersects(sphereB, x) || intersects(sphereC, x))
++answer;
}
return answer;
}
void read_sphere(sphere& s)
{
char x;
std::cin >> s.center;
s.coords = 0;
for(int i = n - 1; i >= 0; --i)
{
std::cin >> x;
if(x == '1')
s.coords |= ul(1) << (ul)i;
}
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin >> n;
read_sphere(sphereA);
read_sphere(sphereB);
read_sphere(sphereC);
std::cout << solve();
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 | #include <vector> #include <iostream> #if defined (_MSC_VER) #include <intrin.h> #define popcnt __popcnt #else #define popcnt __builtin_popcount #endif //using ull = unsigned long long; using ul = unsigned long; struct sphere { ul center; ul coords; }; short n; sphere sphereA, sphereB, sphereC; inline bool intersects(const sphere& s, const ul point) { return popcnt(s.coords ^ point) <= s.center; } ul solve() { const ul maxDim = ul(1) << n; ul answer = 0; for(ul x = 0; x < maxDim; ++x) { if (intersects(sphereA, x) || intersects(sphereB, x) || intersects(sphereC, x)) ++answer; } return answer; } void read_sphere(sphere& s) { char x; std::cin >> s.center; s.coords = 0; for(int i = n - 1; i >= 0; --i) { std::cin >> x; if(x == '1') s.coords |= ul(1) << (ul)i; } } int main() { std::ios::sync_with_stdio(false); std::cin >> n; read_sphere(sphereA); read_sphere(sphereB); read_sphere(sphereC); std::cout << solve(); return 0; } |
English