#include <iostream> #include <vector> #include <cmath> #include <algorithm> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t, n, b; cin >> t; vector<unsigned long long> fib(92); fib[0] = 1; fib[1] = 2; unsigned long long valA; unsigned long long valB; for (int i = 2; i < fib.size(); i++) { fib[i] = fib[i - 1] + fib[i - 2]; } vector<bool> bin(92, false); int maxIdx = 0; for (int i = 0; i < t; i++) { for (int j = 0; j < bin.size(); j++) { bin[j] = false; } maxIdx = 0; valA = 0; valB = 0; cin >> n; for (int j = 0; j < n; j++) { cin >> b; if (b == 1) { valA += fib[j]; } } cin >> n; for (int j = 0; j < n; j++) { cin >> b; if (b == 1) { valB += fib[j]; } } unsigned long long result = valA * valB; while (result > 0) { auto upper = upper_bound(fib.begin(), fib.end(), result); int idx = (upper - 1) - fib.begin(); if (idx > maxIdx) { maxIdx = idx; } bin[idx] = true; result -= fib[idx]; } cout << maxIdx + 1 << " "; for (int j = 0; j <= maxIdx; j++) { if (bin[j]) { cout << 1 << " "; } else { cout << 0 << " "; } } cout << "\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 | #include <iostream> #include <vector> #include <cmath> #include <algorithm> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t, n, b; cin >> t; vector<unsigned long long> fib(92); fib[0] = 1; fib[1] = 2; unsigned long long valA; unsigned long long valB; for (int i = 2; i < fib.size(); i++) { fib[i] = fib[i - 1] + fib[i - 2]; } vector<bool> bin(92, false); int maxIdx = 0; for (int i = 0; i < t; i++) { for (int j = 0; j < bin.size(); j++) { bin[j] = false; } maxIdx = 0; valA = 0; valB = 0; cin >> n; for (int j = 0; j < n; j++) { cin >> b; if (b == 1) { valA += fib[j]; } } cin >> n; for (int j = 0; j < n; j++) { cin >> b; if (b == 1) { valB += fib[j]; } } unsigned long long result = valA * valB; while (result > 0) { auto upper = upper_bound(fib.begin(), fib.end(), result); int idx = (upper - 1) - fib.begin(); if (idx > maxIdx) { maxIdx = idx; } bin[idx] = true; result -= fib[idx]; } cout << maxIdx + 1 << " "; for (int j = 0; j <= maxIdx; j++) { if (bin[j]) { cout << 1 << " "; } else { cout << 0 << " "; } } cout << "\n"; } return 0; } |