#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 (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) {
cout << m << endl;
cout << n-2 << " ";
for (int i = 2; i <= n; ++i) {
cout << -1 << " ";
}
cout << n - 2 << endl;
}
else {
cout << n << endl;
cout << -(m-2) << " ";
for (int i = 2; i <= n; ++i) {
cout << 1 << " ";
}
cout << -(m - 2) << 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:69:25: warning: unused variable 'mn' [-Wunused-variable]
69 | ll mx = 1000000000, mn = -mx;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Ok |
2 |
Correct |
0 ms |
348 KB |
Ok |
3 |
Correct |
0 ms |
344 KB |
Ok |
4 |
Correct |
1 ms |
348 KB |
Ok |
5 |
Correct |
0 ms |
348 KB |
Ok |
6 |
Correct |
0 ms |
348 KB |
Ok |
7 |
Correct |
0 ms |
348 KB |
Ok |
8 |
Correct |
0 ms |
348 KB |
Ok |
9 |
Correct |
0 ms |
348 KB |
Ok |
10 |
Correct |
1 ms |
348 KB |
Ok |
11 |
Correct |
0 ms |
348 KB |
Ok |
12 |
Correct |
1 ms |
348 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Ok |
2 |
Correct |
0 ms |
348 KB |
Ok |
3 |
Correct |
0 ms |
348 KB |
Ok |
4 |
Correct |
0 ms |
344 KB |
Ok |
5 |
Correct |
0 ms |
348 KB |
Ok |
6 |
Correct |
1 ms |
348 KB |
Ok |
7 |
Correct |
6 ms |
860 KB |
Ok |
8 |
Correct |
3 ms |
600 KB |
Ok |
9 |
Correct |
6 ms |
1116 KB |
Ok |
10 |
Correct |
4 ms |
600 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Ok |
2 |
Correct |
1 ms |
348 KB |
Ok |
3 |
Correct |
0 ms |
348 KB |
Ok |
4 |
Incorrect |
1 ms |
348 KB |
Jury has the better answer : jans = 9, pans = 8 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Jury has the better answer : jans = 5, pans = 4 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Ok |
2 |
Correct |
0 ms |
348 KB |
Ok |
3 |
Correct |
0 ms |
344 KB |
Ok |
4 |
Correct |
1 ms |
348 KB |
Ok |
5 |
Correct |
0 ms |
348 KB |
Ok |
6 |
Correct |
0 ms |
348 KB |
Ok |
7 |
Correct |
0 ms |
348 KB |
Ok |
8 |
Correct |
0 ms |
348 KB |
Ok |
9 |
Correct |
0 ms |
348 KB |
Ok |
10 |
Correct |
1 ms |
348 KB |
Ok |
11 |
Correct |
0 ms |
348 KB |
Ok |
12 |
Correct |
1 ms |
348 KB |
Ok |
13 |
Correct |
0 ms |
348 KB |
Ok |
14 |
Correct |
1 ms |
348 KB |
Ok |
15 |
Correct |
0 ms |
348 KB |
Ok |
16 |
Incorrect |
1 ms |
348 KB |
Jury has the better answer : jans = 9, pans = 8 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Ok |
2 |
Correct |
0 ms |
348 KB |
Ok |
3 |
Correct |
0 ms |
344 KB |
Ok |
4 |
Correct |
1 ms |
348 KB |
Ok |
5 |
Correct |
0 ms |
348 KB |
Ok |
6 |
Correct |
0 ms |
348 KB |
Ok |
7 |
Correct |
0 ms |
348 KB |
Ok |
8 |
Correct |
0 ms |
348 KB |
Ok |
9 |
Correct |
0 ms |
348 KB |
Ok |
10 |
Correct |
1 ms |
348 KB |
Ok |
11 |
Correct |
0 ms |
348 KB |
Ok |
12 |
Correct |
1 ms |
348 KB |
Ok |
13 |
Correct |
0 ms |
348 KB |
Ok |
14 |
Correct |
0 ms |
348 KB |
Ok |
15 |
Correct |
0 ms |
348 KB |
Ok |
16 |
Correct |
0 ms |
344 KB |
Ok |
17 |
Correct |
0 ms |
348 KB |
Ok |
18 |
Correct |
1 ms |
348 KB |
Ok |
19 |
Correct |
6 ms |
860 KB |
Ok |
20 |
Correct |
3 ms |
600 KB |
Ok |
21 |
Correct |
6 ms |
1116 KB |
Ok |
22 |
Correct |
4 ms |
600 KB |
Ok |
23 |
Correct |
0 ms |
348 KB |
Ok |
24 |
Correct |
1 ms |
348 KB |
Ok |
25 |
Correct |
0 ms |
348 KB |
Ok |
26 |
Incorrect |
1 ms |
348 KB |
Jury has the better answer : jans = 9, pans = 8 |
27 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Ok |
2 |
Correct |
0 ms |
348 KB |
Ok |
3 |
Correct |
0 ms |
344 KB |
Ok |
4 |
Correct |
1 ms |
348 KB |
Ok |
5 |
Correct |
0 ms |
348 KB |
Ok |
6 |
Correct |
0 ms |
348 KB |
Ok |
7 |
Correct |
0 ms |
348 KB |
Ok |
8 |
Correct |
0 ms |
348 KB |
Ok |
9 |
Correct |
0 ms |
348 KB |
Ok |
10 |
Correct |
1 ms |
348 KB |
Ok |
11 |
Correct |
0 ms |
348 KB |
Ok |
12 |
Correct |
1 ms |
348 KB |
Ok |
13 |
Correct |
0 ms |
348 KB |
Ok |
14 |
Correct |
0 ms |
348 KB |
Ok |
15 |
Correct |
0 ms |
348 KB |
Ok |
16 |
Correct |
0 ms |
344 KB |
Ok |
17 |
Correct |
0 ms |
348 KB |
Ok |
18 |
Correct |
1 ms |
348 KB |
Ok |
19 |
Correct |
6 ms |
860 KB |
Ok |
20 |
Correct |
3 ms |
600 KB |
Ok |
21 |
Correct |
6 ms |
1116 KB |
Ok |
22 |
Correct |
4 ms |
600 KB |
Ok |
23 |
Correct |
0 ms |
348 KB |
Ok |
24 |
Correct |
1 ms |
348 KB |
Ok |
25 |
Correct |
0 ms |
348 KB |
Ok |
26 |
Incorrect |
1 ms |
348 KB |
Jury has the better answer : jans = 9, pans = 8 |
27 |
Halted |
0 ms |
0 KB |
- |