Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- #define endl "\n"
- #define MOD 1000000007
- #define mod 998244353
- #define ar array
- #define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
- void test_case() {
- int n; cin >> n;
- vector<int> a(n);
- bool zero = true;
- for (int i = 0; i < n; i++) {
- cin >> a[i];
- if (a[i] == 1) zero = false;
- }
- if (zero) {
- cout << 0 << "\n";
- return;
- }
- // a = 0010 --> 0100
- reverse(a.begin(), a.end());
- vector<int> res(105);
- for (int i = 0; i < n; i++) {
- if (a[i] == 0) {
- // convert number to 2*n
- int carry = 0;
- for (int j = 0; j < 104; j++) {
- int num_here = 2*res[j] + carry;
- carry = num_here/6;
- res[j] = num_here%6;
- }
- assert(carry == 0);
- }
- else {
- // convert number to 2*n + 1
- int carry = 0;
- for (int j = 0; j < 104; j++) {
- int num_here = 2*res[j] + carry;
- carry = num_here/6;
- res[j] = num_here%6;
- }
- carry = 1;
- for (int j = 0; j < 104; j++) {
- int num_here = res[j] + carry;
- carry = num_here/6;
- res[j] = num_here%6;
- }
- assert(carry == 0);
- }
- }
- assert(res.back() == 0);
- while (res.back() == 0) res.pop_back();
- for (int i = 0; i < (int) res.size(); i++) {
- if (i > 0) cout << " ";
- cout << res[i];
- }
- cout << endl;
- }
- int32_t main() {
- fast_io;
- int t; cin >> t;
- while (t--) {
- test_case();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement