#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(a) a.begin() , a.end()
#define F first
#define S second
using namespace std;
using ll = long long;
const int N = 2e5+5 , inf = 2e9 + 7;
const ll INF = 1e18 , mod = 1e9+7 , P = 6547;
void solve(int tc) {
int n, m;
cin >> n >> m;
int coef = 1;
if(n > m) {
swap(n , m);
coef *= -1;
}
if(m % n == 0) {
cout << m-1 << '\n';
for(int i = 1; i < m; i ++) {
cout << (-1)*coef << ' ';
}
cout << '\n';
// return;c
return;
}
int mx = 9e8;
int otr = -mx/(n-1);
int psv = -otr*(n-1)-1;
vector<int> vec;
int sum = 0;
for(int i = 1; i <= m; i ++) {
if(i%n == m%n) {
vec.push_back(psv);
}
else {
vec.push_back(otr);
}
sum += vec.back();
}
int cur = 0;
for(int i = m+1; 1; i ++) {
if(i%n == m%n) {
vec.push_back(psv);
}
else {
vec.push_back(otr);
}
sum += vec.back();
sum -= vec[cur++];
if(sum <= 0) {
vec.pop_back();
break;
}
}
cout << vec.size() << '\n';
for(auto to: vec) {
cout << to*coef << ' ';
}
cout << '\n';
}
/*
-4 7 -4 -4 7 -4 -4 7 -4
*/
main() {
ios;
int tt = 1 , tc = 0;
cin >> tt;
while(tt --) {
solve(++tc);
}
return 0;
}
Compilation message
sequence.cpp:70:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
70 | main() {
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Ok |
2 |
Correct |
1 ms |
312 KB |
Ok |
3 |
Correct |
1 ms |
212 KB |
Ok |
4 |
Correct |
1 ms |
212 KB |
Ok |
5 |
Correct |
1 ms |
212 KB |
Ok |
6 |
Correct |
1 ms |
212 KB |
Ok |
7 |
Correct |
0 ms |
212 KB |
Ok |
8 |
Correct |
0 ms |
316 KB |
Ok |
9 |
Correct |
1 ms |
212 KB |
Ok |
10 |
Correct |
1 ms |
212 KB |
Ok |
11 |
Correct |
0 ms |
212 KB |
Ok |
12 |
Correct |
1 ms |
212 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
316 KB |
Ok |
2 |
Correct |
0 ms |
316 KB |
Ok |
3 |
Correct |
1 ms |
212 KB |
Ok |
4 |
Correct |
1 ms |
212 KB |
Ok |
5 |
Correct |
1 ms |
212 KB |
Ok |
6 |
Correct |
2 ms |
448 KB |
Ok |
7 |
Correct |
7 ms |
852 KB |
Ok |
8 |
Correct |
4 ms |
596 KB |
Ok |
9 |
Correct |
9 ms |
1060 KB |
Ok |
10 |
Correct |
5 ms |
724 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Ok |
2 |
Correct |
0 ms |
212 KB |
Ok |
3 |
Correct |
1 ms |
324 KB |
Ok |
4 |
Incorrect |
0 ms |
316 KB |
Jury has the better answer : jans = 11, pans = 10 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
324 KB |
Jury has the better answer : jans = 5, pans = 4 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Ok |
2 |
Correct |
1 ms |
312 KB |
Ok |
3 |
Correct |
1 ms |
212 KB |
Ok |
4 |
Correct |
1 ms |
212 KB |
Ok |
5 |
Correct |
1 ms |
212 KB |
Ok |
6 |
Correct |
1 ms |
212 KB |
Ok |
7 |
Correct |
0 ms |
212 KB |
Ok |
8 |
Correct |
0 ms |
316 KB |
Ok |
9 |
Correct |
1 ms |
212 KB |
Ok |
10 |
Correct |
1 ms |
212 KB |
Ok |
11 |
Correct |
0 ms |
212 KB |
Ok |
12 |
Correct |
1 ms |
212 KB |
Ok |
13 |
Correct |
1 ms |
324 KB |
Ok |
14 |
Correct |
0 ms |
212 KB |
Ok |
15 |
Correct |
1 ms |
324 KB |
Ok |
16 |
Incorrect |
0 ms |
316 KB |
Jury has the better answer : jans = 11, pans = 10 |
17 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Ok |
2 |
Correct |
1 ms |
312 KB |
Ok |
3 |
Correct |
1 ms |
212 KB |
Ok |
4 |
Correct |
1 ms |
212 KB |
Ok |
5 |
Correct |
1 ms |
212 KB |
Ok |
6 |
Correct |
1 ms |
212 KB |
Ok |
7 |
Correct |
0 ms |
212 KB |
Ok |
8 |
Correct |
0 ms |
316 KB |
Ok |
9 |
Correct |
1 ms |
212 KB |
Ok |
10 |
Correct |
1 ms |
212 KB |
Ok |
11 |
Correct |
0 ms |
212 KB |
Ok |
12 |
Correct |
1 ms |
212 KB |
Ok |
13 |
Correct |
1 ms |
316 KB |
Ok |
14 |
Correct |
0 ms |
316 KB |
Ok |
15 |
Correct |
1 ms |
212 KB |
Ok |
16 |
Correct |
1 ms |
212 KB |
Ok |
17 |
Correct |
1 ms |
212 KB |
Ok |
18 |
Correct |
2 ms |
448 KB |
Ok |
19 |
Correct |
7 ms |
852 KB |
Ok |
20 |
Correct |
4 ms |
596 KB |
Ok |
21 |
Correct |
9 ms |
1060 KB |
Ok |
22 |
Correct |
5 ms |
724 KB |
Ok |
23 |
Correct |
1 ms |
324 KB |
Ok |
24 |
Correct |
0 ms |
212 KB |
Ok |
25 |
Correct |
1 ms |
324 KB |
Ok |
26 |
Incorrect |
0 ms |
316 KB |
Jury has the better answer : jans = 11, pans = 10 |
27 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Ok |
2 |
Correct |
1 ms |
312 KB |
Ok |
3 |
Correct |
1 ms |
212 KB |
Ok |
4 |
Correct |
1 ms |
212 KB |
Ok |
5 |
Correct |
1 ms |
212 KB |
Ok |
6 |
Correct |
1 ms |
212 KB |
Ok |
7 |
Correct |
0 ms |
212 KB |
Ok |
8 |
Correct |
0 ms |
316 KB |
Ok |
9 |
Correct |
1 ms |
212 KB |
Ok |
10 |
Correct |
1 ms |
212 KB |
Ok |
11 |
Correct |
0 ms |
212 KB |
Ok |
12 |
Correct |
1 ms |
212 KB |
Ok |
13 |
Correct |
1 ms |
316 KB |
Ok |
14 |
Correct |
0 ms |
316 KB |
Ok |
15 |
Correct |
1 ms |
212 KB |
Ok |
16 |
Correct |
1 ms |
212 KB |
Ok |
17 |
Correct |
1 ms |
212 KB |
Ok |
18 |
Correct |
2 ms |
448 KB |
Ok |
19 |
Correct |
7 ms |
852 KB |
Ok |
20 |
Correct |
4 ms |
596 KB |
Ok |
21 |
Correct |
9 ms |
1060 KB |
Ok |
22 |
Correct |
5 ms |
724 KB |
Ok |
23 |
Correct |
1 ms |
324 KB |
Ok |
24 |
Correct |
0 ms |
212 KB |
Ok |
25 |
Correct |
1 ms |
324 KB |
Ok |
26 |
Incorrect |
0 ms |
316 KB |
Jury has the better answer : jans = 11, pans = 10 |
27 |
Halted |
0 ms |
0 KB |
- |