This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <math.h>
#include <bitset>
#include <cmath>
#include <vector>
#include <iomanip>
#include <random>
#include <chrono>
#include <cassert>
using namespace std;
#define ll long long
#define fr first
#define sc second
#define pb push_back
#define US freopen("cowmbat.in", "r", stdin); freopen("cowmbat.out", "w", stdout);
ll gcd(ll a, ll b)
{
if (a == 0 || b == 0) {
return max(a, b);
}
if (a <= b) {
return gcd(a, b % a);
}
else {
return gcd(a % b, b);
}
}
ll lcm(ll a, ll b) {
return (a / gcd(a, b)) * b;
}
const int N = 300005;
const ll oo = 1000000000000000000, MOD = 1000000007;
void solv1(int n, int m) {
if (n < m) {
cout << m - 1 << endl;
for (int i = 1; i <= m - 1; ++i) {
cout << -1 << " ";
}
cout << endl;
}
else {
cout << n - 1 << endl;
for (int i = 1; i <= n - 1; ++i) {
cout << 1 << " ";
}
cout << endl;
}
}
void solve() {
int n, m;
cin >> n >> m;
ll mx = 1000000000, mn = -mx;
if (max(n, m) % min(n, m) == 0) {
solv1(n, m);
return;
}
if (min(n, m) == 2) {
if (n == 2) {
--mx;
cout << m << endl;
for (int i = 1; i <= m;i+=2) {
if (i == m) {
cout << mx;
break;
}
cout << mx << " " << -mx - 1 << " ";
}
cout << endl;
}
else {
--mx;
cout << n << endl;
for (int i = 1; i <= n; i += 2) {
if (i == n) {
cout << -mx;
break;
}
cout << -mx << " " << mx + 1 << " ";
}
cout << endl;
}
return;
}
if (n < m) {
int sum = 0;
cout << n * 2 - 1 << endl;
for (int i = 1; i <= n - 1; ++i) {
cout << 1 << " ";
++sum;
}
cout << -(sum + 1) << " ";
for (int i = n + 1; i <= 2 * n - 1; ++i) {
cout << 1 << " ";
}
cout << endl;
}
else {
int sum = 0;
cout << m * 2 - 1 << endl;
for (int i = 1; i <= m - 1; ++i) {
cout << -1 << " ";
++sum;
}
cout << (sum + 1) << " ";
for (int i = m + 1; i <= 2 *m - 1; ++i) {
cout << -1 << " ";
}
cout << endl;
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
//US
int tt = 1;
cin >> tt;
while (tt--) {
solve();
}
}
Compilation message (stderr)
sequence.cpp: In function 'void solve()':
sequence.cpp:69:25: warning: unused variable 'mn' [-Wunused-variable]
69 | ll mx = 1000000000, mn = -mx;
| ^~
# | 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... |