#include<bits/stdc++.h>
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;
bool f(int x, int y, string& s){
if(x == 0 && y == 0) return true;
if(x == y) return false;
if(x > y){
s.pb('0');
return f(x - y - 1, y, s);
}
else{
s.pb('1');
return f(x, y - x - 1, s);
}
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int q;
cin >> q;
while(q--){
int k, ans = 0;
cin >> k;
string s;
for(int i = 0; i <= k; i++){
string t;
if(f(i, k - i, t)){
ans++;
if(s.empty() || sz(s) > sz(t)) swap(s, t);
}
}
cout << ans << "\n";
reverse(all(s));
for(auto p : s) cout << p << " ";
cout << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
607 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
337 ms |
596 KB |
Output is correct |
2 |
Correct |
804 ms |
652 KB |
Output is correct |
3 |
Correct |
711 ms |
776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1083 ms |
3332 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |