#include "bits/stdc++.h"
using namespace std;
const int mod = (int) 1e9 + 7;
int get(int a, int b) {
if (a > b) {
swap(a, b);
}
if (a < 0 || b < 0) {
return -1;
}
if (a == 0 && b == 0) {
return 0;
}
if (a == b) {
return -1;
}
int add = b / (a + 1);
b %= (a + 1);
int res = get(a, b);
if (res == -1) {
return -1;
}
return res + add;
}
void solve() {
int k;
cin >> k;
k++;
int ans = 0;
int optj = -1;
for (int j = 0; j < k; j++) {
int res = get(j, k - j - 1);
if (res != -1) {
ans++;
if (optj == -1 || res < get(optj, k - optj - 1)) {
optj = j;
}
}
}
// cout << optj << endl;
cout << ans << '\n';
// exit(0);
{
int a = optj, b = k - optj - 1, x = 0;
while (a + b) {
if (a > b) {
x ^= 1;
swap(a, b);
}
while (b >= a + 1) {
cout << x << " ";
b -= a + 1;
}
}
}
cout << '\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
107 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
336 KB |
Output is correct |
2 |
Correct |
96 ms |
504 KB |
Output is correct |
3 |
Correct |
97 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
926 ms |
504 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |