#include <bits/stdc++.h>
using namespace std;
#define debug(args...) kout("[ " + string(#args) + " ]", args)
void kout() { cerr << endl; }
template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); }
template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }
const int MAXN = 200000;
int t;
int n, m;
bool flag;
int len;
int a[MAXN+1];
void solve(int n, int m) {
if (m % n == 0) {
len = m-1;
for (int i = 1; i <= len; i++)
a[i] = flag ? 1 : -1;
} else {
len = (m + n-1) / n * n - 1;
for (int i = 1; i <= len; i++) {
if (i % n == 1 && i != 1)
a[i] = flag ? -m/2-1 : m/2+1;
else if (i % n == 0)
a[i] = flag ? m/2+2 : -m/2-2;
else if (i == n-1)
a[i] = flag ? -m/2-1 : m/2+1;
else
a[i] = 0;
}
}
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
/*
for (int i = 1; i <= 10; i++)
for (int j = i; j <= 10; j++)
solve(i, j), debug(i, j, len);
return 0;
*/
cin >> t;
while (t--) {
cin >> n >> m;
if (n > m)
swap(n, m), flag = true;
else
flag = false;
assert(n != 3);
solve(n, m);
cout << len << '\n';
for (int i = 1; i <= len; i++)
cout << a[i] << " \n"[i==len];
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Ok |
2 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Ok |
2 |
Correct |
1 ms |
364 KB |
Ok |
3 |
Correct |
1 ms |
364 KB |
Ok |
4 |
Correct |
1 ms |
364 KB |
Ok |
5 |
Correct |
1 ms |
364 KB |
Ok |
6 |
Correct |
2 ms |
364 KB |
Ok |
7 |
Correct |
10 ms |
748 KB |
Ok |
8 |
Correct |
6 ms |
492 KB |
Ok |
9 |
Correct |
10 ms |
748 KB |
Ok |
10 |
Correct |
9 ms |
620 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Ok |
2 |
Correct |
1 ms |
364 KB |
Ok |
3 |
Correct |
1 ms |
364 KB |
Ok |
4 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 6 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
492 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Ok |
2 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Ok |
2 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Ok |
2 |
Runtime error |
1 ms |
492 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |