#include <iostream> #include <fstream> #include <vector> #include <algorithm> #include <map> #include <array> #include <string> #include <set> using namespace std; #ifdef USE_CERR_LOG #define LOG if (true) cerr const bool LogEnabled = true; #else #define LOG if (false) cerr const bool LogEnabled = false; #endif #ifdef USE_FILE_CIN ifstream fin("../kul.in"); #define cin fin #endif typedef long long ll; typedef unsigned long long ull; typedef vector<vector<ull>> UnsignedMatrix; typedef vector<ull> UnsignedVector; struct Ball { unsigned idx; unsigned radius; vector<unsigned> centreBits; ull encodedCentre; }; const ull Modulo = 1'000'000'007; const unsigned BallCount = 3; unsigned n; unsigned maxRadius; UnsignedMatrix distMatrix; array<Ball, BallCount> balls; void printBalls() { if (LogEnabled) { for (const Ball& ball : balls) { LOG << ball.idx << ": "; for (auto bit : ball.centreBits) LOG << bit; LOG << " " << ball.encodedCentre << endl; } LOG << "--------------------------------" << endl; } } void printDistMatrix(const UnsignedMatrix& matrix) { if (LogEnabled) { int idx = 0; for (const UnsignedVector& row : matrix) { LOG << idx << ": "; for (auto num : row) LOG << num << ", "; LOG << endl; idx++; } LOG << "--------------------------------" << endl; } } void computeDistMatrix(unsigned radius) { pair<vector<vector<ull>>, vector<vector<ull>>> matrices; matrices.first.push_back({0}); matrices.first.push_back({1}); for (unsigned b=2; b<=n; b++) { vector<vector<ull>>& prev = (b % 2 == 0) ? matrices.first : matrices.second; vector<vector<ull>>& curr = (b % 2 == 0) ? matrices.second : matrices.first; curr.clear(); curr.push_back({0}); ull prefix = (ull) 1 << (b - 1); for (unsigned r=1; r<min(b, radius+1); r++) { curr.push_back(prev[r]); for (size_t i=0; i<prev[r-1].size(); i++) { curr[r].push_back(prev[r-1][i] + prefix); } } if (prev.size() >= b) { curr.push_back({prev[b-1][0] + prefix}); } LOG << b << endl; // printDistMatrix(curr); } distMatrix = (n % 2 == 0) ? matrices.second : matrices.first; } void solve() { set<ull> points; for (const Ball& ball : balls) { for (unsigned r=0; r <= ball.radius; r++) { for (auto num : distMatrix[r]) { points.insert(num ^ ball.encodedCentre); } } } cout << points.size(); } void readData() { cin >> n; string strCentre; maxRadius = 0; for (unsigned i=0; i<BallCount; i++) { Ball& ball = balls[i]; ball.idx = i; ball.encodedCentre = 0; cin >> ball.radius >> strCentre; maxRadius = max(maxRadius, ball.radius); for (unsigned j=0; j<n; j++) { int bit = strCentre[j] - '0'; ball.centreBits.push_back(bit); ball.encodedCentre = 2 * ball.encodedCentre + bit; } } printBalls(); } int main() { ios_base::sync_with_stdio(false); readData(); computeDistMatrix(maxRadius); 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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | #include <iostream> #include <fstream> #include <vector> #include <algorithm> #include <map> #include <array> #include <string> #include <set> using namespace std; #ifdef USE_CERR_LOG #define LOG if (true) cerr const bool LogEnabled = true; #else #define LOG if (false) cerr const bool LogEnabled = false; #endif #ifdef USE_FILE_CIN ifstream fin("../kul.in"); #define cin fin #endif typedef long long ll; typedef unsigned long long ull; typedef vector<vector<ull>> UnsignedMatrix; typedef vector<ull> UnsignedVector; struct Ball { unsigned idx; unsigned radius; vector<unsigned> centreBits; ull encodedCentre; }; const ull Modulo = 1'000'000'007; const unsigned BallCount = 3; unsigned n; unsigned maxRadius; UnsignedMatrix distMatrix; array<Ball, BallCount> balls; void printBalls() { if (LogEnabled) { for (const Ball& ball : balls) { LOG << ball.idx << ": "; for (auto bit : ball.centreBits) LOG << bit; LOG << " " << ball.encodedCentre << endl; } LOG << "--------------------------------" << endl; } } void printDistMatrix(const UnsignedMatrix& matrix) { if (LogEnabled) { int idx = 0; for (const UnsignedVector& row : matrix) { LOG << idx << ": "; for (auto num : row) LOG << num << ", "; LOG << endl; idx++; } LOG << "--------------------------------" << endl; } } void computeDistMatrix(unsigned radius) { pair<vector<vector<ull>>, vector<vector<ull>>> matrices; matrices.first.push_back({0}); matrices.first.push_back({1}); for (unsigned b=2; b<=n; b++) { vector<vector<ull>>& prev = (b % 2 == 0) ? matrices.first : matrices.second; vector<vector<ull>>& curr = (b % 2 == 0) ? matrices.second : matrices.first; curr.clear(); curr.push_back({0}); ull prefix = (ull) 1 << (b - 1); for (unsigned r=1; r<min(b, radius+1); r++) { curr.push_back(prev[r]); for (size_t i=0; i<prev[r-1].size(); i++) { curr[r].push_back(prev[r-1][i] + prefix); } } if (prev.size() >= b) { curr.push_back({prev[b-1][0] + prefix}); } LOG << b << endl; // printDistMatrix(curr); } distMatrix = (n % 2 == 0) ? matrices.second : matrices.first; } void solve() { set<ull> points; for (const Ball& ball : balls) { for (unsigned r=0; r <= ball.radius; r++) { for (auto num : distMatrix[r]) { points.insert(num ^ ball.encodedCentre); } } } cout << points.size(); } void readData() { cin >> n; string strCentre; maxRadius = 0; for (unsigned i=0; i<BallCount; i++) { Ball& ball = balls[i]; ball.idx = i; ball.encodedCentre = 0; cin >> ball.radius >> strCentre; maxRadius = max(maxRadius, ball.radius); for (unsigned j=0; j<n; j++) { int bit = strCentre[j] - '0'; ball.centreBits.push_back(bit); ball.encodedCentre = 2 * ball.encodedCentre + bit; } } printBalls(); } int main() { ios_base::sync_with_stdio(false); readData(); computeDistMatrix(maxRadius); solve(); return 0; } |