#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define PI acos(-1)
#define ld long double
const int mod = 1e9+7, N = 2e5+5;
int msb(int val){return sizeof(int)*8-__builtin_clzll(val);}
int a[N], n, m, k;
bool used[N];
vector<int> order;
int md;
void dfs(int u){
used[u] = true;
if(u-n >= 0 && !used[u-n])dfs(u-n);
if(u+m <= md && !used[u+m])dfs(u+m);
order.pb(u);
}
bool check(int mid){
int i;
md = mid;
order.clear();
memset(used, 0, sizeof(used));
for(i=0;i<=mid;i++)if(!used[i])dfs(i);
for(i=0;i<=mid;i++)a[order[i]] = i;
for(i=0;i<=n;i++){
if(i-n >= 0){
if(i==n){
if(a[i]>=0)return false;
}else if(a[i]-a[i-n-1] >=0)return false;
}else {
if(i==m){
if(a[i]>=0)return false;
}else if(a[i]-a[i-m-1] >=0)return false;
}
}return true;
}
void solve(int test_case){
int i, j;
cin >> n >> m;
int l = n+m-1-__gcd(n,m);
check(l);
cout << l << '\n';
for(i=1;i<=l;i++){
cout << -(a[i]-a[i-1]) << ' ';
}cout << '\n';
return;
}
signed main(){
FASTIO;
#define MULTITEST 1
#if MULTITEST
int ___T;
cin >> ___T;
for(int T_CASE = 1; T_CASE <= ___T; T_CASE++)
solve(T_CASE);
#else
solve(1);
#endif
return 0;
}
Compilation message
sequence.cpp: In function 'void solve(long long int)':
sequence.cpp:45:9: warning: unused variable 'j' [-Wunused-variable]
45 | int i, j;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Ok |
2 |
Correct |
1 ms |
492 KB |
Ok |
3 |
Correct |
1 ms |
492 KB |
Ok |
4 |
Correct |
1 ms |
492 KB |
Ok |
5 |
Correct |
1 ms |
492 KB |
Ok |
6 |
Correct |
1 ms |
492 KB |
Ok |
7 |
Correct |
1 ms |
492 KB |
Ok |
8 |
Correct |
1 ms |
492 KB |
Ok |
9 |
Correct |
1 ms |
492 KB |
Ok |
10 |
Correct |
1 ms |
492 KB |
Ok |
11 |
Correct |
1 ms |
492 KB |
Ok |
12 |
Correct |
1 ms |
492 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Ok |
2 |
Correct |
1 ms |
492 KB |
Ok |
3 |
Correct |
1 ms |
492 KB |
Ok |
4 |
Correct |
1 ms |
492 KB |
Ok |
5 |
Correct |
1 ms |
492 KB |
Ok |
6 |
Correct |
2 ms |
620 KB |
Ok |
7 |
Correct |
9 ms |
1388 KB |
Ok |
8 |
Correct |
5 ms |
876 KB |
Ok |
9 |
Correct |
11 ms |
1516 KB |
Ok |
10 |
Correct |
6 ms |
1004 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
620 KB |
Ok |
2 |
Correct |
1 ms |
492 KB |
Ok |
3 |
Correct |
1 ms |
492 KB |
Ok |
4 |
Correct |
1 ms |
492 KB |
Ok |
5 |
Correct |
1 ms |
492 KB |
Ok |
6 |
Correct |
1 ms |
492 KB |
Ok |
7 |
Correct |
1 ms |
492 KB |
Ok |
8 |
Correct |
1 ms |
492 KB |
Ok |
9 |
Correct |
1 ms |
492 KB |
Ok |
10 |
Correct |
1 ms |
492 KB |
Ok |
11 |
Correct |
1 ms |
492 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Ok |
2 |
Correct |
1 ms |
492 KB |
Ok |
3 |
Correct |
1 ms |
492 KB |
Ok |
4 |
Correct |
1 ms |
492 KB |
Ok |
5 |
Correct |
1 ms |
492 KB |
Ok |
6 |
Runtime error |
16 ms |
11748 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Ok |
2 |
Correct |
1 ms |
492 KB |
Ok |
3 |
Correct |
1 ms |
492 KB |
Ok |
4 |
Correct |
1 ms |
492 KB |
Ok |
5 |
Correct |
1 ms |
492 KB |
Ok |
6 |
Correct |
1 ms |
492 KB |
Ok |
7 |
Correct |
1 ms |
492 KB |
Ok |
8 |
Correct |
1 ms |
492 KB |
Ok |
9 |
Correct |
1 ms |
492 KB |
Ok |
10 |
Correct |
1 ms |
492 KB |
Ok |
11 |
Correct |
1 ms |
492 KB |
Ok |
12 |
Correct |
1 ms |
492 KB |
Ok |
13 |
Correct |
1 ms |
620 KB |
Ok |
14 |
Correct |
1 ms |
492 KB |
Ok |
15 |
Correct |
1 ms |
492 KB |
Ok |
16 |
Correct |
1 ms |
492 KB |
Ok |
17 |
Correct |
1 ms |
492 KB |
Ok |
18 |
Correct |
1 ms |
492 KB |
Ok |
19 |
Correct |
1 ms |
492 KB |
Ok |
20 |
Correct |
1 ms |
492 KB |
Ok |
21 |
Correct |
1 ms |
492 KB |
Ok |
22 |
Correct |
1 ms |
492 KB |
Ok |
23 |
Correct |
1 ms |
492 KB |
Ok |
24 |
Correct |
2 ms |
620 KB |
Ok |
25 |
Correct |
2 ms |
620 KB |
Ok |
26 |
Correct |
2 ms |
620 KB |
Ok |
27 |
Correct |
2 ms |
620 KB |
Ok |
28 |
Correct |
2 ms |
620 KB |
Ok |
29 |
Correct |
2 ms |
620 KB |
Ok |
30 |
Correct |
2 ms |
640 KB |
Ok |
31 |
Correct |
2 ms |
620 KB |
Ok |
32 |
Correct |
2 ms |
620 KB |
Ok |
33 |
Correct |
2 ms |
620 KB |
Ok |
34 |
Correct |
4 ms |
876 KB |
Ok |
35 |
Correct |
4 ms |
876 KB |
Ok |
36 |
Correct |
4 ms |
876 KB |
Ok |
37 |
Correct |
5 ms |
876 KB |
Ok |
38 |
Correct |
4 ms |
876 KB |
Ok |
39 |
Correct |
5 ms |
876 KB |
Ok |
40 |
Correct |
4 ms |
876 KB |
Ok |
41 |
Correct |
4 ms |
876 KB |
Ok |
42 |
Correct |
4 ms |
876 KB |
Ok |
43 |
Correct |
4 ms |
1004 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Ok |
2 |
Correct |
1 ms |
492 KB |
Ok |
3 |
Correct |
1 ms |
492 KB |
Ok |
4 |
Correct |
1 ms |
492 KB |
Ok |
5 |
Correct |
1 ms |
492 KB |
Ok |
6 |
Correct |
1 ms |
492 KB |
Ok |
7 |
Correct |
1 ms |
492 KB |
Ok |
8 |
Correct |
1 ms |
492 KB |
Ok |
9 |
Correct |
1 ms |
492 KB |
Ok |
10 |
Correct |
1 ms |
492 KB |
Ok |
11 |
Correct |
1 ms |
492 KB |
Ok |
12 |
Correct |
1 ms |
492 KB |
Ok |
13 |
Correct |
1 ms |
492 KB |
Ok |
14 |
Correct |
1 ms |
492 KB |
Ok |
15 |
Correct |
1 ms |
492 KB |
Ok |
16 |
Correct |
1 ms |
492 KB |
Ok |
17 |
Correct |
1 ms |
492 KB |
Ok |
18 |
Correct |
2 ms |
620 KB |
Ok |
19 |
Correct |
9 ms |
1388 KB |
Ok |
20 |
Correct |
5 ms |
876 KB |
Ok |
21 |
Correct |
11 ms |
1516 KB |
Ok |
22 |
Correct |
6 ms |
1004 KB |
Ok |
23 |
Correct |
1 ms |
620 KB |
Ok |
24 |
Correct |
1 ms |
492 KB |
Ok |
25 |
Correct |
1 ms |
492 KB |
Ok |
26 |
Correct |
1 ms |
492 KB |
Ok |
27 |
Correct |
1 ms |
492 KB |
Ok |
28 |
Correct |
1 ms |
492 KB |
Ok |
29 |
Correct |
1 ms |
492 KB |
Ok |
30 |
Correct |
1 ms |
492 KB |
Ok |
31 |
Correct |
1 ms |
492 KB |
Ok |
32 |
Correct |
1 ms |
492 KB |
Ok |
33 |
Correct |
1 ms |
492 KB |
Ok |
34 |
Correct |
2 ms |
620 KB |
Ok |
35 |
Correct |
2 ms |
620 KB |
Ok |
36 |
Correct |
2 ms |
620 KB |
Ok |
37 |
Correct |
2 ms |
620 KB |
Ok |
38 |
Correct |
2 ms |
620 KB |
Ok |
39 |
Correct |
2 ms |
620 KB |
Ok |
40 |
Correct |
2 ms |
640 KB |
Ok |
41 |
Correct |
2 ms |
620 KB |
Ok |
42 |
Correct |
2 ms |
620 KB |
Ok |
43 |
Correct |
2 ms |
620 KB |
Ok |
44 |
Correct |
4 ms |
876 KB |
Ok |
45 |
Correct |
4 ms |
876 KB |
Ok |
46 |
Correct |
4 ms |
876 KB |
Ok |
47 |
Correct |
5 ms |
876 KB |
Ok |
48 |
Correct |
4 ms |
876 KB |
Ok |
49 |
Correct |
5 ms |
876 KB |
Ok |
50 |
Correct |
4 ms |
876 KB |
Ok |
51 |
Correct |
4 ms |
876 KB |
Ok |
52 |
Correct |
4 ms |
876 KB |
Ok |
53 |
Correct |
4 ms |
1004 KB |
Ok |
54 |
Runtime error |
5 ms |
3816 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
55 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Ok |
2 |
Correct |
1 ms |
492 KB |
Ok |
3 |
Correct |
1 ms |
492 KB |
Ok |
4 |
Correct |
1 ms |
492 KB |
Ok |
5 |
Correct |
1 ms |
492 KB |
Ok |
6 |
Correct |
1 ms |
492 KB |
Ok |
7 |
Correct |
1 ms |
492 KB |
Ok |
8 |
Correct |
1 ms |
492 KB |
Ok |
9 |
Correct |
1 ms |
492 KB |
Ok |
10 |
Correct |
1 ms |
492 KB |
Ok |
11 |
Correct |
1 ms |
492 KB |
Ok |
12 |
Correct |
1 ms |
492 KB |
Ok |
13 |
Correct |
1 ms |
492 KB |
Ok |
14 |
Correct |
1 ms |
492 KB |
Ok |
15 |
Correct |
1 ms |
492 KB |
Ok |
16 |
Correct |
1 ms |
492 KB |
Ok |
17 |
Correct |
1 ms |
492 KB |
Ok |
18 |
Correct |
2 ms |
620 KB |
Ok |
19 |
Correct |
9 ms |
1388 KB |
Ok |
20 |
Correct |
5 ms |
876 KB |
Ok |
21 |
Correct |
11 ms |
1516 KB |
Ok |
22 |
Correct |
6 ms |
1004 KB |
Ok |
23 |
Correct |
1 ms |
620 KB |
Ok |
24 |
Correct |
1 ms |
492 KB |
Ok |
25 |
Correct |
1 ms |
492 KB |
Ok |
26 |
Correct |
1 ms |
492 KB |
Ok |
27 |
Correct |
1 ms |
492 KB |
Ok |
28 |
Correct |
1 ms |
492 KB |
Ok |
29 |
Correct |
1 ms |
492 KB |
Ok |
30 |
Correct |
1 ms |
492 KB |
Ok |
31 |
Correct |
1 ms |
492 KB |
Ok |
32 |
Correct |
1 ms |
492 KB |
Ok |
33 |
Correct |
1 ms |
492 KB |
Ok |
34 |
Correct |
1 ms |
492 KB |
Ok |
35 |
Correct |
1 ms |
492 KB |
Ok |
36 |
Correct |
1 ms |
492 KB |
Ok |
37 |
Correct |
1 ms |
492 KB |
Ok |
38 |
Correct |
1 ms |
492 KB |
Ok |
39 |
Runtime error |
16 ms |
11748 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
40 |
Halted |
0 ms |
0 KB |
- |