#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>
using namespace std;
const long long oo = 1000000000000000000;
long long int sum, ans = 0, mx = 0, mn = 1000000000, num, pos;
/*
ViHHiPuh
(( `'-""``""-'` ))
)-__-_.._-__-(
/ --- (o _ o) --- \
\ .-* ( .0. ) *-. /
_'-. ,_ '=' _, .-'_
/ `;#'#'# - #'#'#;` \
\_)) -----'#'----- ((_/
# --------- #
'# ------- ------ #'
/..-'# ------- #'-.\
_\...-\'# -- #'/-.../_
((____)- '#' -(____))
cout << fixed << setprecision(6) << x;
freopen ( "sum.in", "r", stdin )
*/
int main () {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t;
cin >> t;
int n, m;
while ( t -- ) {
cin >> n >> m;
mn = min( n, m );
mx = max( n, m );
if ( n % m == 0 || m % n == 0 ) {
if ( n > m ) {
cout << n - 1 << "\n";
for ( int i = 1; i < n; i ++ )
cout << 1 << " ";
}
else {
cout << m - 1 << "\n";
for ( int i = 1; i < m; i ++ )
cout << -1 << " ";
}
cout << "\n";
}
else if ( min( n, m ) == 2 ) {
cout << max( n, m ) << "\n";
mx = max( n, m );
if ( n == 2 ) {
for ( int i = 1; i <= mx; i ++ ) {
if ( i % 2 )
cout << mx << " ";
else
cout << ( mx * -1 ) - 1 << " ";
}
cout << "\n";
}
else {
for ( int i = 1; i <= mx; i ++ ) {
if ( i % 2 == 0 )
cout << mx + 1 << " ";
else
cout << ( mx * -1 ) << " ";
}
cout << "\n";
}
}
else if ( abs( n - m ) <= 2 ) {
if ( abs( n - m ) == 1 ) {
if ( m > n ) {
cout << max( n, m ) + 1 << "\n";
mx = max( n, m );
num = mx - 2;
cout << num - 1 << " ";
for ( int i = 1; i <= num; i ++ )
cout << "-1" << " ";
cout << num - 1 << "\n";
}
else {
cout << max( n, m ) << "\n";
mx = max( n, m );
num = mx - 2;
cout << (num - 1) * -1 << " ";
for ( int i = 1; i <= num; i ++ )
cout << "1" << " ";
cout << (num - 1) * -1 << "\n";
}
}
else {
if ( m > n ) {
cout << max( n, m ) << "\n";
mx = max( n, m );
num = mx - 4;
sum = num * -1;
if ( sum % 2 )
cout << sum / 2 << " " << sum / 2 << " ";
else
cout << sum / 2 - 1 << " " << sum / 2 - 1 << " ";
for ( int i = 1; i <= num; i ++ )
cout << "-1 ";
if ( sum % 2 )
cout << sum / 2 << " " << sum / 2 << " ";
else
cout << sum / 2 - 1 << " " << sum / 2 - 1 << " ";
cout << "\n";
}
else {
cout << max( n, m ) << "\n";
mx = max( n, m );
num = mx - 4;
num *= -1;
sum = num * -1;
if ( sum % 2 )
cout << sum / 2 << " " << sum / 2 << " ";
else
cout << sum / 2 - 1 << " " << sum / 2 - 1 << " ";
for ( int i = 1; i <= num; i ++ )
cout << "1 ";
if ( sum % 2 )
cout << sum / 2 << " " << sum / 2 << " ";
else
cout << sum / 2 - 1 << " " << sum / 2 - 1 << " ";
cout << "\n";
}
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Ok |
2 |
Correct |
1 ms |
204 KB |
Ok |
3 |
Correct |
1 ms |
204 KB |
Ok |
4 |
Correct |
0 ms |
256 KB |
Ok |
5 |
Correct |
0 ms |
204 KB |
Ok |
6 |
Correct |
1 ms |
204 KB |
Ok |
7 |
Correct |
0 ms |
204 KB |
Ok |
8 |
Correct |
0 ms |
204 KB |
Ok |
9 |
Correct |
0 ms |
204 KB |
Ok |
10 |
Correct |
1 ms |
204 KB |
Ok |
11 |
Correct |
0 ms |
204 KB |
Ok |
12 |
Correct |
0 ms |
204 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Ok |
2 |
Correct |
0 ms |
204 KB |
Ok |
3 |
Correct |
1 ms |
204 KB |
Ok |
4 |
Correct |
0 ms |
204 KB |
Ok |
5 |
Correct |
1 ms |
204 KB |
Ok |
6 |
Correct |
3 ms |
332 KB |
Ok |
7 |
Correct |
10 ms |
640 KB |
Ok |
8 |
Correct |
3 ms |
460 KB |
Ok |
9 |
Correct |
18 ms |
684 KB |
Ok |
10 |
Correct |
5 ms |
460 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Ok |
2 |
Correct |
1 ms |
204 KB |
Ok |
3 |
Correct |
0 ms |
204 KB |
Ok |
4 |
Incorrect |
0 ms |
204 KB |
Jury has the better answer : jans = 9, pans = 2 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Jury has the better answer : jans = 5, pans = 4 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Ok |
2 |
Correct |
1 ms |
204 KB |
Ok |
3 |
Correct |
1 ms |
204 KB |
Ok |
4 |
Correct |
0 ms |
256 KB |
Ok |
5 |
Correct |
0 ms |
204 KB |
Ok |
6 |
Correct |
1 ms |
204 KB |
Ok |
7 |
Correct |
0 ms |
204 KB |
Ok |
8 |
Correct |
0 ms |
204 KB |
Ok |
9 |
Correct |
0 ms |
204 KB |
Ok |
10 |
Correct |
1 ms |
204 KB |
Ok |
11 |
Correct |
0 ms |
204 KB |
Ok |
12 |
Correct |
0 ms |
204 KB |
Ok |
13 |
Correct |
0 ms |
204 KB |
Ok |
14 |
Correct |
1 ms |
204 KB |
Ok |
15 |
Correct |
0 ms |
204 KB |
Ok |
16 |
Incorrect |
0 ms |
204 KB |
Jury has the better answer : jans = 9, pans = 2 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Ok |
2 |
Correct |
1 ms |
204 KB |
Ok |
3 |
Correct |
1 ms |
204 KB |
Ok |
4 |
Correct |
0 ms |
256 KB |
Ok |
5 |
Correct |
0 ms |
204 KB |
Ok |
6 |
Correct |
1 ms |
204 KB |
Ok |
7 |
Correct |
0 ms |
204 KB |
Ok |
8 |
Correct |
0 ms |
204 KB |
Ok |
9 |
Correct |
0 ms |
204 KB |
Ok |
10 |
Correct |
1 ms |
204 KB |
Ok |
11 |
Correct |
0 ms |
204 KB |
Ok |
12 |
Correct |
0 ms |
204 KB |
Ok |
13 |
Correct |
0 ms |
204 KB |
Ok |
14 |
Correct |
0 ms |
204 KB |
Ok |
15 |
Correct |
1 ms |
204 KB |
Ok |
16 |
Correct |
0 ms |
204 KB |
Ok |
17 |
Correct |
1 ms |
204 KB |
Ok |
18 |
Correct |
3 ms |
332 KB |
Ok |
19 |
Correct |
10 ms |
640 KB |
Ok |
20 |
Correct |
3 ms |
460 KB |
Ok |
21 |
Correct |
18 ms |
684 KB |
Ok |
22 |
Correct |
5 ms |
460 KB |
Ok |
23 |
Correct |
0 ms |
204 KB |
Ok |
24 |
Correct |
1 ms |
204 KB |
Ok |
25 |
Correct |
0 ms |
204 KB |
Ok |
26 |
Incorrect |
0 ms |
204 KB |
Jury has the better answer : jans = 9, pans = 2 |
27 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Ok |
2 |
Correct |
1 ms |
204 KB |
Ok |
3 |
Correct |
1 ms |
204 KB |
Ok |
4 |
Correct |
0 ms |
256 KB |
Ok |
5 |
Correct |
0 ms |
204 KB |
Ok |
6 |
Correct |
1 ms |
204 KB |
Ok |
7 |
Correct |
0 ms |
204 KB |
Ok |
8 |
Correct |
0 ms |
204 KB |
Ok |
9 |
Correct |
0 ms |
204 KB |
Ok |
10 |
Correct |
1 ms |
204 KB |
Ok |
11 |
Correct |
0 ms |
204 KB |
Ok |
12 |
Correct |
0 ms |
204 KB |
Ok |
13 |
Correct |
0 ms |
204 KB |
Ok |
14 |
Correct |
0 ms |
204 KB |
Ok |
15 |
Correct |
1 ms |
204 KB |
Ok |
16 |
Correct |
0 ms |
204 KB |
Ok |
17 |
Correct |
1 ms |
204 KB |
Ok |
18 |
Correct |
3 ms |
332 KB |
Ok |
19 |
Correct |
10 ms |
640 KB |
Ok |
20 |
Correct |
3 ms |
460 KB |
Ok |
21 |
Correct |
18 ms |
684 KB |
Ok |
22 |
Correct |
5 ms |
460 KB |
Ok |
23 |
Correct |
0 ms |
204 KB |
Ok |
24 |
Correct |
1 ms |
204 KB |
Ok |
25 |
Correct |
0 ms |
204 KB |
Ok |
26 |
Incorrect |
0 ms |
204 KB |
Jury has the better answer : jans = 9, pans = 2 |
27 |
Halted |
0 ms |
0 KB |
- |