#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 = 4e5+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 |
748 KB |
Ok |
2 |
Correct |
1 ms |
748 KB |
Ok |
3 |
Correct |
1 ms |
748 KB |
Ok |
4 |
Correct |
1 ms |
748 KB |
Ok |
5 |
Correct |
1 ms |
748 KB |
Ok |
6 |
Correct |
1 ms |
748 KB |
Ok |
7 |
Correct |
1 ms |
748 KB |
Ok |
8 |
Correct |
1 ms |
748 KB |
Ok |
9 |
Correct |
1 ms |
764 KB |
Ok |
10 |
Correct |
1 ms |
748 KB |
Ok |
11 |
Correct |
1 ms |
748 KB |
Ok |
12 |
Correct |
1 ms |
748 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
748 KB |
Ok |
2 |
Correct |
1 ms |
748 KB |
Ok |
3 |
Correct |
1 ms |
748 KB |
Ok |
4 |
Correct |
1 ms |
748 KB |
Ok |
5 |
Correct |
1 ms |
748 KB |
Ok |
6 |
Correct |
3 ms |
876 KB |
Ok |
7 |
Correct |
12 ms |
1516 KB |
Ok |
8 |
Correct |
5 ms |
1132 KB |
Ok |
9 |
Correct |
13 ms |
1644 KB |
Ok |
10 |
Correct |
6 ms |
1260 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
748 KB |
Ok |
2 |
Correct |
1 ms |
748 KB |
Ok |
3 |
Correct |
1 ms |
748 KB |
Ok |
4 |
Correct |
1 ms |
748 KB |
Ok |
5 |
Correct |
2 ms |
748 KB |
Ok |
6 |
Correct |
1 ms |
748 KB |
Ok |
7 |
Correct |
38 ms |
748 KB |
Ok |
8 |
Correct |
1 ms |
704 KB |
Ok |
9 |
Correct |
1 ms |
748 KB |
Ok |
10 |
Correct |
1 ms |
748 KB |
Ok |
11 |
Correct |
1 ms |
748 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
748 KB |
Ok |
2 |
Correct |
1 ms |
748 KB |
Ok |
3 |
Correct |
1 ms |
764 KB |
Ok |
4 |
Correct |
1 ms |
748 KB |
Ok |
5 |
Correct |
1 ms |
748 KB |
Ok |
6 |
Runtime error |
18 ms |
12132 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 |
748 KB |
Ok |
2 |
Correct |
1 ms |
748 KB |
Ok |
3 |
Correct |
1 ms |
748 KB |
Ok |
4 |
Correct |
1 ms |
748 KB |
Ok |
5 |
Correct |
1 ms |
748 KB |
Ok |
6 |
Correct |
1 ms |
748 KB |
Ok |
7 |
Correct |
1 ms |
748 KB |
Ok |
8 |
Correct |
1 ms |
748 KB |
Ok |
9 |
Correct |
1 ms |
764 KB |
Ok |
10 |
Correct |
1 ms |
748 KB |
Ok |
11 |
Correct |
1 ms |
748 KB |
Ok |
12 |
Correct |
1 ms |
748 KB |
Ok |
13 |
Correct |
1 ms |
748 KB |
Ok |
14 |
Correct |
1 ms |
748 KB |
Ok |
15 |
Correct |
1 ms |
748 KB |
Ok |
16 |
Correct |
1 ms |
748 KB |
Ok |
17 |
Correct |
2 ms |
748 KB |
Ok |
18 |
Correct |
1 ms |
748 KB |
Ok |
19 |
Correct |
38 ms |
748 KB |
Ok |
20 |
Correct |
1 ms |
704 KB |
Ok |
21 |
Correct |
1 ms |
748 KB |
Ok |
22 |
Correct |
1 ms |
748 KB |
Ok |
23 |
Correct |
1 ms |
748 KB |
Ok |
24 |
Correct |
3 ms |
900 KB |
Ok |
25 |
Correct |
4 ms |
876 KB |
Ok |
26 |
Correct |
3 ms |
876 KB |
Ok |
27 |
Correct |
3 ms |
876 KB |
Ok |
28 |
Correct |
2 ms |
876 KB |
Ok |
29 |
Correct |
2 ms |
876 KB |
Ok |
30 |
Correct |
2 ms |
876 KB |
Ok |
31 |
Correct |
3 ms |
876 KB |
Ok |
32 |
Correct |
3 ms |
876 KB |
Ok |
33 |
Correct |
3 ms |
876 KB |
Ok |
34 |
Correct |
106 ms |
1176 KB |
Ok |
35 |
Correct |
4 ms |
1132 KB |
Ok |
36 |
Correct |
4 ms |
1132 KB |
Ok |
37 |
Correct |
4 ms |
1132 KB |
Ok |
38 |
Correct |
6 ms |
1132 KB |
Ok |
39 |
Correct |
5 ms |
1004 KB |
Ok |
40 |
Correct |
6 ms |
1132 KB |
Ok |
41 |
Correct |
6 ms |
1004 KB |
Ok |
42 |
Correct |
5 ms |
1132 KB |
Ok |
43 |
Correct |
5 ms |
1132 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
748 KB |
Ok |
2 |
Correct |
1 ms |
748 KB |
Ok |
3 |
Correct |
1 ms |
748 KB |
Ok |
4 |
Correct |
1 ms |
748 KB |
Ok |
5 |
Correct |
1 ms |
748 KB |
Ok |
6 |
Correct |
1 ms |
748 KB |
Ok |
7 |
Correct |
1 ms |
748 KB |
Ok |
8 |
Correct |
1 ms |
748 KB |
Ok |
9 |
Correct |
1 ms |
764 KB |
Ok |
10 |
Correct |
1 ms |
748 KB |
Ok |
11 |
Correct |
1 ms |
748 KB |
Ok |
12 |
Correct |
1 ms |
748 KB |
Ok |
13 |
Correct |
1 ms |
748 KB |
Ok |
14 |
Correct |
1 ms |
748 KB |
Ok |
15 |
Correct |
1 ms |
748 KB |
Ok |
16 |
Correct |
1 ms |
748 KB |
Ok |
17 |
Correct |
1 ms |
748 KB |
Ok |
18 |
Correct |
3 ms |
876 KB |
Ok |
19 |
Correct |
12 ms |
1516 KB |
Ok |
20 |
Correct |
5 ms |
1132 KB |
Ok |
21 |
Correct |
13 ms |
1644 KB |
Ok |
22 |
Correct |
6 ms |
1260 KB |
Ok |
23 |
Correct |
1 ms |
748 KB |
Ok |
24 |
Correct |
1 ms |
748 KB |
Ok |
25 |
Correct |
1 ms |
748 KB |
Ok |
26 |
Correct |
1 ms |
748 KB |
Ok |
27 |
Correct |
2 ms |
748 KB |
Ok |
28 |
Correct |
1 ms |
748 KB |
Ok |
29 |
Correct |
38 ms |
748 KB |
Ok |
30 |
Correct |
1 ms |
704 KB |
Ok |
31 |
Correct |
1 ms |
748 KB |
Ok |
32 |
Correct |
1 ms |
748 KB |
Ok |
33 |
Correct |
1 ms |
748 KB |
Ok |
34 |
Correct |
3 ms |
900 KB |
Ok |
35 |
Correct |
4 ms |
876 KB |
Ok |
36 |
Correct |
3 ms |
876 KB |
Ok |
37 |
Correct |
3 ms |
876 KB |
Ok |
38 |
Correct |
2 ms |
876 KB |
Ok |
39 |
Correct |
2 ms |
876 KB |
Ok |
40 |
Correct |
2 ms |
876 KB |
Ok |
41 |
Correct |
3 ms |
876 KB |
Ok |
42 |
Correct |
3 ms |
876 KB |
Ok |
43 |
Correct |
3 ms |
876 KB |
Ok |
44 |
Correct |
106 ms |
1176 KB |
Ok |
45 |
Correct |
4 ms |
1132 KB |
Ok |
46 |
Correct |
4 ms |
1132 KB |
Ok |
47 |
Correct |
4 ms |
1132 KB |
Ok |
48 |
Correct |
6 ms |
1132 KB |
Ok |
49 |
Correct |
5 ms |
1004 KB |
Ok |
50 |
Correct |
6 ms |
1132 KB |
Ok |
51 |
Correct |
6 ms |
1004 KB |
Ok |
52 |
Correct |
5 ms |
1132 KB |
Ok |
53 |
Correct |
5 ms |
1132 KB |
Ok |
54 |
Correct |
66 ms |
4456 KB |
Ok |
55 |
Correct |
74 ms |
4872 KB |
Ok |
56 |
Correct |
87 ms |
4840 KB |
Ok |
57 |
Correct |
55 ms |
3944 KB |
Ok |
58 |
Correct |
70 ms |
4712 KB |
Ok |
59 |
Correct |
66 ms |
4584 KB |
Ok |
60 |
Correct |
62 ms |
4160 KB |
Ok |
61 |
Correct |
58 ms |
4200 KB |
Ok |
62 |
Correct |
78 ms |
5096 KB |
Ok |
63 |
Correct |
66 ms |
4456 KB |
Ok |
64 |
Correct |
73 ms |
4964 KB |
Ok |
65 |
Correct |
74 ms |
4712 KB |
Ok |
66 |
Correct |
64 ms |
4456 KB |
Ok |
67 |
Correct |
58 ms |
4200 KB |
Ok |
68 |
Correct |
65 ms |
4624 KB |
Ok |
69 |
Correct |
113 ms |
11568 KB |
Ok |
70 |
Correct |
114 ms |
11712 KB |
Ok |
71 |
Correct |
112 ms |
10088 KB |
Ok |
72 |
Correct |
111 ms |
11624 KB |
Ok |
73 |
Correct |
113 ms |
10344 KB |
Ok |
74 |
Correct |
112 ms |
10972 KB |
Ok |
75 |
Correct |
114 ms |
11308 KB |
Ok |
76 |
Correct |
123 ms |
11556 KB |
Ok |
77 |
Correct |
111 ms |
10728 KB |
Ok |
78 |
Correct |
113 ms |
11496 KB |
Ok |
79 |
Correct |
115 ms |
11112 KB |
Ok |
80 |
Correct |
129 ms |
10216 KB |
Ok |
81 |
Correct |
129 ms |
11624 KB |
Ok |
82 |
Correct |
111 ms |
10984 KB |
Ok |
83 |
Correct |
113 ms |
11624 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
748 KB |
Ok |
2 |
Correct |
1 ms |
748 KB |
Ok |
3 |
Correct |
1 ms |
748 KB |
Ok |
4 |
Correct |
1 ms |
748 KB |
Ok |
5 |
Correct |
1 ms |
748 KB |
Ok |
6 |
Correct |
1 ms |
748 KB |
Ok |
7 |
Correct |
1 ms |
748 KB |
Ok |
8 |
Correct |
1 ms |
748 KB |
Ok |
9 |
Correct |
1 ms |
764 KB |
Ok |
10 |
Correct |
1 ms |
748 KB |
Ok |
11 |
Correct |
1 ms |
748 KB |
Ok |
12 |
Correct |
1 ms |
748 KB |
Ok |
13 |
Correct |
1 ms |
748 KB |
Ok |
14 |
Correct |
1 ms |
748 KB |
Ok |
15 |
Correct |
1 ms |
748 KB |
Ok |
16 |
Correct |
1 ms |
748 KB |
Ok |
17 |
Correct |
1 ms |
748 KB |
Ok |
18 |
Correct |
3 ms |
876 KB |
Ok |
19 |
Correct |
12 ms |
1516 KB |
Ok |
20 |
Correct |
5 ms |
1132 KB |
Ok |
21 |
Correct |
13 ms |
1644 KB |
Ok |
22 |
Correct |
6 ms |
1260 KB |
Ok |
23 |
Correct |
1 ms |
748 KB |
Ok |
24 |
Correct |
1 ms |
748 KB |
Ok |
25 |
Correct |
1 ms |
748 KB |
Ok |
26 |
Correct |
1 ms |
748 KB |
Ok |
27 |
Correct |
2 ms |
748 KB |
Ok |
28 |
Correct |
1 ms |
748 KB |
Ok |
29 |
Correct |
38 ms |
748 KB |
Ok |
30 |
Correct |
1 ms |
704 KB |
Ok |
31 |
Correct |
1 ms |
748 KB |
Ok |
32 |
Correct |
1 ms |
748 KB |
Ok |
33 |
Correct |
1 ms |
748 KB |
Ok |
34 |
Correct |
1 ms |
748 KB |
Ok |
35 |
Correct |
1 ms |
748 KB |
Ok |
36 |
Correct |
1 ms |
764 KB |
Ok |
37 |
Correct |
1 ms |
748 KB |
Ok |
38 |
Correct |
1 ms |
748 KB |
Ok |
39 |
Runtime error |
18 ms |
12132 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
40 |
Halted |
0 ms |
0 KB |
- |