#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 600005
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define sz(s) (int)s.size()
ll T, n, a[N], t, ans,b[25];
string s, g;
map <string,int> vis;
int main () {
cin >> n;
while(n--) {
cin >> t;
int ans = t + 1, ans1 = t+1,inx = 0;
vector <pair<int,int>> answer;
for(int i = 0; i <= t;i++) {
int x1 = t - i, x2 = i, new_sz = 0;
while(x1 != x2 && new_sz < ans) {
if(x1 > x2) {
new_sz += (x1/(x2 + 1));
x1 = (x1 % (x2 + 1));
}
else {
new_sz += (x2/(x1 + 1));
x2 = (x2 % (x1 + 1));
}
}
if(x1 == 0 && x2 == 0 && new_sz < ans) {
ans = new_sz;
inx = i;
}
if (x1 > 0 || x2 > 0)ans1--;
}
cout << ans1 << '\n';
int x1 = t - inx, x2 = inx;
while(x1 != x2) {
if(x1 > x2) {
for(int i = 1; i <= (x1 / (x2 + 1)); i++) {
cout << '1' << " ";
}
x1 = (x1 % (x2 + 1));
}
else {
for(int i = 1; i <= (x2 / (x1 + 1)); i++) {
cout << '0' << " ";
}
x2 = (x2 % (x1 + 1));
}
}
cout << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |