#include <bits/stdc++.h>
#define pb push_back
using namespace std;
int n, m, mul = -11;
const int N = 2e5 + 5;
int arr[2*N];
bool vis[2*N];
void go() {
mul = -1;
cin >> n >> m;
for (int i = 0; i <= m*2; i++) {
vis[i] = 0;
arr[i] = 0;
}
if (m < n) {
swap(n, m);
mul = 1;
}
if (m % n == 0) {
cout << m-1 << '\n';
for (int i = 1; i < m; i++)
cout << 1 * mul << " \n"[i==m-1];
return;
}
if (n == 2) {
for (int i = 1; i <= m; i++)
cout << (i & 1 ? -n : n+1) * mul << " \n"[i==m];
return;
}
int i = 0, j = (m)%n, smol = (m-1)%n;
vector <int> pos;
while(1) {
if (!vis[i]) {
vis[i] = 1;
pos.pb(i);
i = (i + 1) % n;
}
if (!vis[j]) {
vis[j] = 1;
pos.pb(j);
j = (j + 1) % n;
}
if (i == n-1) break;
}
int lst = 0;
for (i = 0; i < n; i++)
if (pos[i] <= smol) lst = i;
int Y = pos[lst]; // 0->x, 1->y
Y = (Y+1)%n;
int a, b, c = m / n + 1, d, x, y;
a = n-1, b = 1;
d = c+1, c = m - d;
x = 10 * d;
y = 10 * a * d - 1;
lst = 1;
while(1) {
int curNum = (lst%n == Y) ? -y : x;
// cout << lst << ' ' << curNum << '\n';
arr[lst] = arr[lst-1] + curNum;
if (lst >= n) {
int tmp = arr[lst] - (lst-n >= 0 ? arr[lst-n] : 0);
if (tmp <= 0) {
// cout << tmp << ' ';
// cout << "ERR: n\n";
break;
}
}
if (lst >= m) {
int tmp = arr[lst] - (lst-m >= 0 ? arr[lst-m] : 0);
if (tmp >= 0) {
// cout << tmp << ' ';
// cout << "ERR: m\n";
break;
}
}
lst++;
// pos.pb(curNum);
// cout << curNum << ' ';
}
cout << lst-1 << '\n';
for (int i = 1; i < lst; i++) cout << arr[i]-arr[i-1] << " \n"[i==lst-1];
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
int T;
cin >> T;
while(T--) go();
}
Compilation message
sequence.cpp: In function 'void go()':
sequence.cpp:50:9: warning: variable 'b' set but not used [-Wunused-but-set-variable]
50 | int a, b, c = m / n + 1, d, x, y;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Ok |
2 |
Correct |
1 ms |
316 KB |
Ok |
3 |
Correct |
0 ms |
204 KB |
Ok |
4 |
Correct |
1 ms |
316 KB |
Ok |
5 |
Correct |
1 ms |
320 KB |
Ok |
6 |
Correct |
1 ms |
204 KB |
Ok |
7 |
Correct |
1 ms |
204 KB |
Ok |
8 |
Correct |
1 ms |
316 KB |
Ok |
9 |
Correct |
1 ms |
204 KB |
Ok |
10 |
Correct |
1 ms |
204 KB |
Ok |
11 |
Correct |
1 ms |
204 KB |
Ok |
12 |
Correct |
1 ms |
204 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
320 KB |
Jury has the better answer : jans = 3, pans = -2 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
320 KB |
Jury has the better answer : jans = 3, pans = 2 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2074 ms |
204 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Ok |
2 |
Correct |
1 ms |
316 KB |
Ok |
3 |
Correct |
0 ms |
204 KB |
Ok |
4 |
Correct |
1 ms |
316 KB |
Ok |
5 |
Correct |
1 ms |
320 KB |
Ok |
6 |
Correct |
1 ms |
204 KB |
Ok |
7 |
Correct |
1 ms |
204 KB |
Ok |
8 |
Correct |
1 ms |
316 KB |
Ok |
9 |
Correct |
1 ms |
204 KB |
Ok |
10 |
Correct |
1 ms |
204 KB |
Ok |
11 |
Correct |
1 ms |
204 KB |
Ok |
12 |
Correct |
1 ms |
204 KB |
Ok |
13 |
Incorrect |
1 ms |
320 KB |
Jury has the better answer : jans = 3, pans = 2 |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Ok |
2 |
Correct |
1 ms |
316 KB |
Ok |
3 |
Correct |
0 ms |
204 KB |
Ok |
4 |
Correct |
1 ms |
316 KB |
Ok |
5 |
Correct |
1 ms |
320 KB |
Ok |
6 |
Correct |
1 ms |
204 KB |
Ok |
7 |
Correct |
1 ms |
204 KB |
Ok |
8 |
Correct |
1 ms |
316 KB |
Ok |
9 |
Correct |
1 ms |
204 KB |
Ok |
10 |
Correct |
1 ms |
204 KB |
Ok |
11 |
Correct |
1 ms |
204 KB |
Ok |
12 |
Correct |
1 ms |
204 KB |
Ok |
13 |
Incorrect |
0 ms |
320 KB |
Jury has the better answer : jans = 3, pans = -2 |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Ok |
2 |
Correct |
1 ms |
316 KB |
Ok |
3 |
Correct |
0 ms |
204 KB |
Ok |
4 |
Correct |
1 ms |
316 KB |
Ok |
5 |
Correct |
1 ms |
320 KB |
Ok |
6 |
Correct |
1 ms |
204 KB |
Ok |
7 |
Correct |
1 ms |
204 KB |
Ok |
8 |
Correct |
1 ms |
316 KB |
Ok |
9 |
Correct |
1 ms |
204 KB |
Ok |
10 |
Correct |
1 ms |
204 KB |
Ok |
11 |
Correct |
1 ms |
204 KB |
Ok |
12 |
Correct |
1 ms |
204 KB |
Ok |
13 |
Incorrect |
0 ms |
320 KB |
Jury has the better answer : jans = 3, pans = -2 |
14 |
Halted |
0 ms |
0 KB |
- |