#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;
ll a[N];
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 (abs(n - m) == 2) {
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;
}
}
else {
if (n < m) {
ll x = 2, sum = 0;
cout << n*2-1 << endl;
for (int i = 1; i <= n - 1; ++i) {
a[i] = x;
++x;
sum += a[i];
cout << a[i] << " ";
}
a[n] = -(sum + 1);
cout << a[n] << " ";
for (int i = n + 1; i <= n * 2 - 1; ++i) {
a[i] = a[i - n];
cout << a[i] << " ";
}
cout << endl;
}
else {
ll x = 2, sum = 0;
cout << m * 2 - 1 << endl;
for (int i = 1; i <= m - 1; ++i) {
a[i] = -x;
++x;
sum += a[i];
cout << a[i] << " ";
}
a[n] = -sum+1;
cout << a[m] << " ";
for (int i = m + 1; i <= m * 2 - 1; ++i) {
a[i] = a[i - m];
cout << a[i] << " ";
}
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
sequence.cpp: In function 'void solve()':
sequence.cpp:71:25: warning: unused variable 'mn' [-Wunused-variable]
71 | ll mx = 1000000000, mn = -mx;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Ok |
2 |
Correct |
0 ms |
460 KB |
Ok |
3 |
Correct |
0 ms |
348 KB |
Ok |
4 |
Correct |
0 ms |
348 KB |
Ok |
5 |
Correct |
0 ms |
348 KB |
Ok |
6 |
Correct |
0 ms |
348 KB |
Ok |
7 |
Correct |
1 ms |
348 KB |
Ok |
8 |
Correct |
0 ms |
348 KB |
Ok |
9 |
Correct |
0 ms |
348 KB |
Ok |
10 |
Correct |
0 ms |
348 KB |
Ok |
11 |
Correct |
0 ms |
348 KB |
Ok |
12 |
Correct |
1 ms |
460 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Ok |
2 |
Correct |
0 ms |
348 KB |
Ok |
3 |
Correct |
1 ms |
344 KB |
Ok |
4 |
Correct |
1 ms |
348 KB |
Ok |
5 |
Correct |
1 ms |
464 KB |
Ok |
6 |
Correct |
1 ms |
348 KB |
Ok |
7 |
Correct |
5 ms |
800 KB |
Ok |
8 |
Correct |
3 ms |
604 KB |
Ok |
9 |
Correct |
6 ms |
1112 KB |
Ok |
10 |
Correct |
4 ms |
860 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Ok |
2 |
Correct |
0 ms |
348 KB |
Ok |
3 |
Correct |
0 ms |
348 KB |
Ok |
4 |
Incorrect |
0 ms |
348 KB |
Jury has the better answer : jans = 9, pans = 5 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
All the numbers must be nonzero |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Ok |
2 |
Correct |
0 ms |
460 KB |
Ok |
3 |
Correct |
0 ms |
348 KB |
Ok |
4 |
Correct |
0 ms |
348 KB |
Ok |
5 |
Correct |
0 ms |
348 KB |
Ok |
6 |
Correct |
0 ms |
348 KB |
Ok |
7 |
Correct |
1 ms |
348 KB |
Ok |
8 |
Correct |
0 ms |
348 KB |
Ok |
9 |
Correct |
0 ms |
348 KB |
Ok |
10 |
Correct |
0 ms |
348 KB |
Ok |
11 |
Correct |
0 ms |
348 KB |
Ok |
12 |
Correct |
1 ms |
460 KB |
Ok |
13 |
Correct |
1 ms |
348 KB |
Ok |
14 |
Correct |
0 ms |
348 KB |
Ok |
15 |
Correct |
0 ms |
348 KB |
Ok |
16 |
Incorrect |
0 ms |
348 KB |
Jury has the better answer : jans = 9, pans = 5 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Ok |
2 |
Correct |
0 ms |
460 KB |
Ok |
3 |
Correct |
0 ms |
348 KB |
Ok |
4 |
Correct |
0 ms |
348 KB |
Ok |
5 |
Correct |
0 ms |
348 KB |
Ok |
6 |
Correct |
0 ms |
348 KB |
Ok |
7 |
Correct |
1 ms |
348 KB |
Ok |
8 |
Correct |
0 ms |
348 KB |
Ok |
9 |
Correct |
0 ms |
348 KB |
Ok |
10 |
Correct |
0 ms |
348 KB |
Ok |
11 |
Correct |
0 ms |
348 KB |
Ok |
12 |
Correct |
1 ms |
460 KB |
Ok |
13 |
Correct |
0 ms |
348 KB |
Ok |
14 |
Correct |
0 ms |
348 KB |
Ok |
15 |
Correct |
1 ms |
344 KB |
Ok |
16 |
Correct |
1 ms |
348 KB |
Ok |
17 |
Correct |
1 ms |
464 KB |
Ok |
18 |
Correct |
1 ms |
348 KB |
Ok |
19 |
Correct |
5 ms |
800 KB |
Ok |
20 |
Correct |
3 ms |
604 KB |
Ok |
21 |
Correct |
6 ms |
1112 KB |
Ok |
22 |
Correct |
4 ms |
860 KB |
Ok |
23 |
Correct |
1 ms |
348 KB |
Ok |
24 |
Correct |
0 ms |
348 KB |
Ok |
25 |
Correct |
0 ms |
348 KB |
Ok |
26 |
Incorrect |
0 ms |
348 KB |
Jury has the better answer : jans = 9, pans = 5 |
27 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Ok |
2 |
Correct |
0 ms |
460 KB |
Ok |
3 |
Correct |
0 ms |
348 KB |
Ok |
4 |
Correct |
0 ms |
348 KB |
Ok |
5 |
Correct |
0 ms |
348 KB |
Ok |
6 |
Correct |
0 ms |
348 KB |
Ok |
7 |
Correct |
1 ms |
348 KB |
Ok |
8 |
Correct |
0 ms |
348 KB |
Ok |
9 |
Correct |
0 ms |
348 KB |
Ok |
10 |
Correct |
0 ms |
348 KB |
Ok |
11 |
Correct |
0 ms |
348 KB |
Ok |
12 |
Correct |
1 ms |
460 KB |
Ok |
13 |
Correct |
0 ms |
348 KB |
Ok |
14 |
Correct |
0 ms |
348 KB |
Ok |
15 |
Correct |
1 ms |
344 KB |
Ok |
16 |
Correct |
1 ms |
348 KB |
Ok |
17 |
Correct |
1 ms |
464 KB |
Ok |
18 |
Correct |
1 ms |
348 KB |
Ok |
19 |
Correct |
5 ms |
800 KB |
Ok |
20 |
Correct |
3 ms |
604 KB |
Ok |
21 |
Correct |
6 ms |
1112 KB |
Ok |
22 |
Correct |
4 ms |
860 KB |
Ok |
23 |
Correct |
1 ms |
348 KB |
Ok |
24 |
Correct |
0 ms |
348 KB |
Ok |
25 |
Correct |
0 ms |
348 KB |
Ok |
26 |
Incorrect |
0 ms |
348 KB |
Jury has the better answer : jans = 9, pans = 5 |
27 |
Halted |
0 ms |
0 KB |
- |