#include <bits/stdc++.h> using namespace std; #define st first #define nd second #define pb push_back typedef long long ll; typedef double db; typedef long double ldb; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ll, db> pdd; typedef pair<ldb, ldb> pldd; typedef pair<int, ll> pil; typedef pair<ll, int> pli; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<char> vc; typedef vector<string> vs; typedef vector<db> vdb; typedef vector<ldb> vldb; typedef vector<pii> vpii; typedef vector<pll> vpll; typedef vector<pdd> vpdd; typedef vector<pldd> vpldd; typedef vector<pil> vpil; typedef vector<pli> vpli; template<typename T> void print(T begin, T end, char = ' ', string msg = "", char = '\n'); template<typename It, typename T> void in(It, int, T (*)()); int si (); ll sl (); string ss (int); char sc (); float sf (); db sd (); ldb sld (); void pi (int, char = '\n'); void pl (ll, char = '\n'); void pf (float, char = '\n'); void pc (char, char = '\n'); void pdb (db, char = '\n'); void pldb (ldb, char = '\n'); void ps (string, char = '\n'); template<typename T> void pv (vector<T> v, char = ' ', char = '\n'); ll russian(ll, ll, ll); ll fastpow(ll, ll, ll); ll slowpow(ll, ll, ll); ll _gcd(ll, ll); ll _lcm(ll, ll); ll extgcd(ll, ll, ll&, ll&); ll _inv(ll, ll); const int INF = 1e9; const ll LINF = 1e18; vector<int> R; vector<ull> fib; ull get() { int n; cin >> n; ull a = 1, b = 1; ull res = 0; for (int i = 0; i < n; ++i) { int bit; cin >> bit; if (bit) res += b; ull c = b; b += a; a = c; } return res; } void write(ull n) { R.clear(); int it = fib.size() - 1; while (it >= 0 && fib[it] > n) --it; for (int i = it; i >= 0; --i) if (n >= fib[i]) { n -= fib[i]; R.push_back(1); } else R.push_back(0); cout << R.size() << " "; for (int i = R.size() - 1; i >= 0; --i) cout << R[i] << " "; cout << "\n"; } int main() { ios_base::sync_with_stdio(false); int t; cin >> t; ull a = 1, b = 1; for (int i = 0; i < 92; ++i) { fib.push_back(b); ll c = b; b += a; a = c; } while (t--) { ull num1 = get(); ull num2 = get(); write(num1 * num2); } return 0; } template<typename T> string get_token_pointer() { if (is_same<T, int*>::value) return "%d"; if (is_same<T, ll*>::value) return "%lld"; if (is_same<T, char*>::value) return "%c"; if (is_same<T, db*>::value) return "%.8lf"; if (is_same<T, ldb*>::value) return "%.10Lf"; if (is_same<T, float*>::value) return "%.6f"; return "%d"; } template<typename T> string get_token() { if (is_same<T, int>::value) return "%d"; if (is_same<T, ll>::value) return "%lld"; if (is_same<T, char>::value) return "%c"; if (is_same<T, db>::value) return "%.8lf"; if (is_same<T, ldb>::value) return "%.10Lf"; if (is_same<T, float>::value) return "%.6f"; return "%d"; } template<typename It, typename T> void in(It begin, int nn, T (*get)()) { while (nn--) *begin++ = get(); } template <typename T> T scanf_t(string s) { T a; scanf(s.c_str(), &a); return a; } template <typename T> void printf_t(T a, string s, char end_l) { s.push_back(end_l); printf(s.c_str(), a); } // stworzone do tablic tylko template <typename T> void print(T begin, T end, char sep, string msg, char end_l) { if (msg != "") { printf(msg.c_str()); printf("\n"); } string s = get_token_pointer<T>(); s.push_back(sep); while (begin + 1 != end) { printf(s.c_str(), *begin); begin++; } if (begin != end) { s.back() = end_l; printf(s.c_str(), *begin); } } int si () { return scanf_t<int>("%d"); } ll sl () { return scanf_t<ll>("%lld"); } float sf () { return scanf_t<float>("%.6f"); } char sc () { return scanf_t<char>(" %c"); } db sdb () { return scanf_t<db>("%.8lf"); } ldb sldb () { return scanf_t<ldb>("%.10Lf"); } void pi (int a, char end_l) { printf_t<int>(a, "%d", end_l); } void pl (ll a, char end_l) { printf_t<ll>(a, "%lld", end_l); } void pf (float a, char end_l) { printf_t<float>(a, "%.6f", end_l); } void pc (char a, char end_l) { printf_t<char>(a, "%c", end_l); } void pdb (db a, char end_l) { printf_t<db>(a, "%.8lf", end_l); } void pldb (ldb a, char end_l) { printf_t<ldb>(a, "%.10Lf", end_l); } void ps(string a, char end_l) { string s = "%s"; s.push_back(end_l); printf(s.c_str(), a.c_str()); } template<typename T> void pv (vector<T> v, char sep, char end_l) { string s = get_token<T>(); for (size_t i = 0; i < v.size() - 1; ++i) printf_t<T>(v[i], s, sep); if (!v.empty()) printf_t<T>(v.back(), s, end_l); } string ss(int NN) { char T[NN + 7]; scanf("%s", T); return (string)T; } ll fastpow(ll a, ll k, ll m) { ll r = 1LL; while (k) { if (k & 1LL) r = (r * a) % m; a = (a * a) % m; k >>= 1LL; } return r; } ll slowpow(ll a, ll k, ll m) { ll r = 1LL; while (k) { if (k & 1LL) r = russian(r, a, m); a = russian(a, a, m); k >>= 1LL; } return r; } ll russian(ll a, ll k, ll m) { ll r = 0LL; while (k) { if (k & 1LL) r = (r + a) % m; a = (a + a) % m; k >>= 1LL; } return r; } ll _gcd(ll a, ll b) { while (b) swap(a %= b, b); return a; } ll _lcm(ll a, ll b) { return a / _gcd(a, b) * b; } ll extgcd(ll a, ll b, ll& k, ll& l) { if (b == 0) { k = 1; l = 0; return a; } ll res = extgcd(b, a % b, l, k); l -= a / b * k; return res; } ll _inv(ll a, ll p) { return fastpow(a, p - 2, p); }
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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | #include <bits/stdc++.h> using namespace std; #define st first #define nd second #define pb push_back typedef long long ll; typedef double db; typedef long double ldb; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ll, db> pdd; typedef pair<ldb, ldb> pldd; typedef pair<int, ll> pil; typedef pair<ll, int> pli; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<char> vc; typedef vector<string> vs; typedef vector<db> vdb; typedef vector<ldb> vldb; typedef vector<pii> vpii; typedef vector<pll> vpll; typedef vector<pdd> vpdd; typedef vector<pldd> vpldd; typedef vector<pil> vpil; typedef vector<pli> vpli; template<typename T> void print(T begin, T end, char = ' ', string msg = "", char = '\n'); template<typename It, typename T> void in(It, int, T (*)()); int si (); ll sl (); string ss (int); char sc (); float sf (); db sd (); ldb sld (); void pi (int, char = '\n'); void pl (ll, char = '\n'); void pf (float, char = '\n'); void pc (char, char = '\n'); void pdb (db, char = '\n'); void pldb (ldb, char = '\n'); void ps (string, char = '\n'); template<typename T> void pv (vector<T> v, char = ' ', char = '\n'); ll russian(ll, ll, ll); ll fastpow(ll, ll, ll); ll slowpow(ll, ll, ll); ll _gcd(ll, ll); ll _lcm(ll, ll); ll extgcd(ll, ll, ll&, ll&); ll _inv(ll, ll); const int INF = 1e9; const ll LINF = 1e18; vector<int> R; vector<ull> fib; ull get() { int n; cin >> n; ull a = 1, b = 1; ull res = 0; for (int i = 0; i < n; ++i) { int bit; cin >> bit; if (bit) res += b; ull c = b; b += a; a = c; } return res; } void write(ull n) { R.clear(); int it = fib.size() - 1; while (it >= 0 && fib[it] > n) --it; for (int i = it; i >= 0; --i) if (n >= fib[i]) { n -= fib[i]; R.push_back(1); } else R.push_back(0); cout << R.size() << " "; for (int i = R.size() - 1; i >= 0; --i) cout << R[i] << " "; cout << "\n"; } int main() { ios_base::sync_with_stdio(false); int t; cin >> t; ull a = 1, b = 1; for (int i = 0; i < 92; ++i) { fib.push_back(b); ll c = b; b += a; a = c; } while (t--) { ull num1 = get(); ull num2 = get(); write(num1 * num2); } return 0; } template<typename T> string get_token_pointer() { if (is_same<T, int*>::value) return "%d"; if (is_same<T, ll*>::value) return "%lld"; if (is_same<T, char*>::value) return "%c"; if (is_same<T, db*>::value) return "%.8lf"; if (is_same<T, ldb*>::value) return "%.10Lf"; if (is_same<T, float*>::value) return "%.6f"; return "%d"; } template<typename T> string get_token() { if (is_same<T, int>::value) return "%d"; if (is_same<T, ll>::value) return "%lld"; if (is_same<T, char>::value) return "%c"; if (is_same<T, db>::value) return "%.8lf"; if (is_same<T, ldb>::value) return "%.10Lf"; if (is_same<T, float>::value) return "%.6f"; return "%d"; } template<typename It, typename T> void in(It begin, int nn, T (*get)()) { while (nn--) *begin++ = get(); } template <typename T> T scanf_t(string s) { T a; scanf(s.c_str(), &a); return a; } template <typename T> void printf_t(T a, string s, char end_l) { s.push_back(end_l); printf(s.c_str(), a); } // stworzone do tablic tylko template <typename T> void print(T begin, T end, char sep, string msg, char end_l) { if (msg != "") { printf(msg.c_str()); printf("\n"); } string s = get_token_pointer<T>(); s.push_back(sep); while (begin + 1 != end) { printf(s.c_str(), *begin); begin++; } if (begin != end) { s.back() = end_l; printf(s.c_str(), *begin); } } int si () { return scanf_t<int>("%d"); } ll sl () { return scanf_t<ll>("%lld"); } float sf () { return scanf_t<float>("%.6f"); } char sc () { return scanf_t<char>(" %c"); } db sdb () { return scanf_t<db>("%.8lf"); } ldb sldb () { return scanf_t<ldb>("%.10Lf"); } void pi (int a, char end_l) { printf_t<int>(a, "%d", end_l); } void pl (ll a, char end_l) { printf_t<ll>(a, "%lld", end_l); } void pf (float a, char end_l) { printf_t<float>(a, "%.6f", end_l); } void pc (char a, char end_l) { printf_t<char>(a, "%c", end_l); } void pdb (db a, char end_l) { printf_t<db>(a, "%.8lf", end_l); } void pldb (ldb a, char end_l) { printf_t<ldb>(a, "%.10Lf", end_l); } void ps(string a, char end_l) { string s = "%s"; s.push_back(end_l); printf(s.c_str(), a.c_str()); } template<typename T> void pv (vector<T> v, char sep, char end_l) { string s = get_token<T>(); for (size_t i = 0; i < v.size() - 1; ++i) printf_t<T>(v[i], s, sep); if (!v.empty()) printf_t<T>(v.back(), s, end_l); } string ss(int NN) { char T[NN + 7]; scanf("%s", T); return (string)T; } ll fastpow(ll a, ll k, ll m) { ll r = 1LL; while (k) { if (k & 1LL) r = (r * a) % m; a = (a * a) % m; k >>= 1LL; } return r; } ll slowpow(ll a, ll k, ll m) { ll r = 1LL; while (k) { if (k & 1LL) r = russian(r, a, m); a = russian(a, a, m); k >>= 1LL; } return r; } ll russian(ll a, ll k, ll m) { ll r = 0LL; while (k) { if (k & 1LL) r = (r + a) % m; a = (a + a) % m; k >>= 1LL; } return r; } ll _gcd(ll a, ll b) { while (b) swap(a %= b, b); return a; } ll _lcm(ll a, ll b) { return a / _gcd(a, b) * b; } ll extgcd(ll a, ll b, ll& k, ll& l) { if (b == 0) { k = 1; l = 0; return a; } ll res = extgcd(b, a % b, l, k); l -= a / b * k; return res; } ll _inv(ll a, ll p) { return fastpow(a, p - 2, p); } |