This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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() {
if (m % n == 0) {
len = m-1;
for (int i = 1; i <= len; i++)
a[i] = flag ? 1 : -1;
} else if (n == 2) {
len = m;
for (int i = 1; i <= len; i++) {
if (i & 1)
a[i] = flag ? -m/2-1 : m/2+1;
else
a[i] = flag ? m/2+2 : -m/2-2;
}
}
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> t;
while (t--) {
cin >> n >> m;
if (n > m)
swap(n, m), flag = true;
else
flag = false;
solve();
cout << len << '\n';
for (int i = 1; i <= len; i++)
cout << a[i] << " \n"[i==len];
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |