#include <bits/stdc++.h>
#define pb push_back
using namespace std;
int n, m, mul;
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) {
cout << m << '\n';
for (int i = 1; i <= m; i++)
cout << (i & 1 ? -m : m+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);
}
if (!vis[j]) {
vis[j] = 1;
pos.pb(j);
}
i = (i + 1) % n;
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;
arr[lst] = arr[lst-1] + curNum;
if (lst >= n) {
int tmp = arr[lst] - (lst-n >= 0 ? arr[lst-n] : 0);
if (tmp <= 0) {
break;
}
}
if (lst >= m) {
int tmp = arr[lst] - (lst-m >= 0 ? arr[lst-m] : 0);
if (tmp >= 0) {
break;
}
}
if (lst > 2*m) {
cout << "GG\n";
cout << n << ' ' << m << '\n';
exit(0);
break;
}
lst++;
}
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:51:9: warning: variable 'b' set but not used [-Wunused-but-set-variable]
51 | int a, b, c = m / n + 1, d, x, y;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Ok |
2 |
Correct |
0 ms |
204 KB |
Ok |
3 |
Correct |
1 ms |
204 KB |
Ok |
4 |
Correct |
1 ms |
204 KB |
Ok |
5 |
Correct |
0 ms |
204 KB |
Ok |
6 |
Correct |
1 ms |
204 KB |
Ok |
7 |
Correct |
1 ms |
204 KB |
Ok |
8 |
Correct |
0 ms |
204 KB |
Ok |
9 |
Correct |
0 ms |
204 KB |
Ok |
10 |
Correct |
0 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 |
Correct |
1 ms |
204 KB |
Ok |
2 |
Correct |
0 ms |
204 KB |
Ok |
3 |
Correct |
0 ms |
208 KB |
Ok |
4 |
Correct |
0 ms |
208 KB |
Ok |
5 |
Correct |
1 ms |
204 KB |
Ok |
6 |
Correct |
3 ms |
332 KB |
Ok |
7 |
Correct |
10 ms |
716 KB |
Ok |
8 |
Correct |
5 ms |
460 KB |
Ok |
9 |
Correct |
9 ms |
716 KB |
Ok |
10 |
Correct |
5 ms |
588 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Ok |
2 |
Correct |
0 ms |
204 KB |
Ok |
3 |
Correct |
1 ms |
204 KB |
Ok |
4 |
Incorrect |
1 ms |
204 KB |
there is incorrect sequence |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Jury has the better answer : jans = 5, pans = 4 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Ok |
2 |
Correct |
0 ms |
204 KB |
Ok |
3 |
Correct |
1 ms |
204 KB |
Ok |
4 |
Correct |
1 ms |
204 KB |
Ok |
5 |
Correct |
0 ms |
204 KB |
Ok |
6 |
Correct |
1 ms |
204 KB |
Ok |
7 |
Correct |
1 ms |
204 KB |
Ok |
8 |
Correct |
0 ms |
204 KB |
Ok |
9 |
Correct |
0 ms |
204 KB |
Ok |
10 |
Correct |
0 ms |
204 KB |
Ok |
11 |
Correct |
1 ms |
204 KB |
Ok |
12 |
Correct |
1 ms |
204 KB |
Ok |
13 |
Correct |
0 ms |
204 KB |
Ok |
14 |
Correct |
0 ms |
204 KB |
Ok |
15 |
Correct |
1 ms |
204 KB |
Ok |
16 |
Incorrect |
1 ms |
204 KB |
there is incorrect sequence |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Ok |
2 |
Correct |
0 ms |
204 KB |
Ok |
3 |
Correct |
1 ms |
204 KB |
Ok |
4 |
Correct |
1 ms |
204 KB |
Ok |
5 |
Correct |
0 ms |
204 KB |
Ok |
6 |
Correct |
1 ms |
204 KB |
Ok |
7 |
Correct |
1 ms |
204 KB |
Ok |
8 |
Correct |
0 ms |
204 KB |
Ok |
9 |
Correct |
0 ms |
204 KB |
Ok |
10 |
Correct |
0 ms |
204 KB |
Ok |
11 |
Correct |
1 ms |
204 KB |
Ok |
12 |
Correct |
1 ms |
204 KB |
Ok |
13 |
Correct |
1 ms |
204 KB |
Ok |
14 |
Correct |
0 ms |
204 KB |
Ok |
15 |
Correct |
0 ms |
208 KB |
Ok |
16 |
Correct |
0 ms |
208 KB |
Ok |
17 |
Correct |
1 ms |
204 KB |
Ok |
18 |
Correct |
3 ms |
332 KB |
Ok |
19 |
Correct |
10 ms |
716 KB |
Ok |
20 |
Correct |
5 ms |
460 KB |
Ok |
21 |
Correct |
9 ms |
716 KB |
Ok |
22 |
Correct |
5 ms |
588 KB |
Ok |
23 |
Correct |
0 ms |
204 KB |
Ok |
24 |
Correct |
0 ms |
204 KB |
Ok |
25 |
Correct |
1 ms |
204 KB |
Ok |
26 |
Incorrect |
1 ms |
204 KB |
there is incorrect sequence |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Ok |
2 |
Correct |
0 ms |
204 KB |
Ok |
3 |
Correct |
1 ms |
204 KB |
Ok |
4 |
Correct |
1 ms |
204 KB |
Ok |
5 |
Correct |
0 ms |
204 KB |
Ok |
6 |
Correct |
1 ms |
204 KB |
Ok |
7 |
Correct |
1 ms |
204 KB |
Ok |
8 |
Correct |
0 ms |
204 KB |
Ok |
9 |
Correct |
0 ms |
204 KB |
Ok |
10 |
Correct |
0 ms |
204 KB |
Ok |
11 |
Correct |
1 ms |
204 KB |
Ok |
12 |
Correct |
1 ms |
204 KB |
Ok |
13 |
Correct |
1 ms |
204 KB |
Ok |
14 |
Correct |
0 ms |
204 KB |
Ok |
15 |
Correct |
0 ms |
208 KB |
Ok |
16 |
Correct |
0 ms |
208 KB |
Ok |
17 |
Correct |
1 ms |
204 KB |
Ok |
18 |
Correct |
3 ms |
332 KB |
Ok |
19 |
Correct |
10 ms |
716 KB |
Ok |
20 |
Correct |
5 ms |
460 KB |
Ok |
21 |
Correct |
9 ms |
716 KB |
Ok |
22 |
Correct |
5 ms |
588 KB |
Ok |
23 |
Correct |
0 ms |
204 KB |
Ok |
24 |
Correct |
0 ms |
204 KB |
Ok |
25 |
Correct |
1 ms |
204 KB |
Ok |
26 |
Incorrect |
1 ms |
204 KB |
there is incorrect sequence |
27 |
Halted |
0 ms |
0 KB |
- |