#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 4e5 + 11;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
ll n, m, pos;
ll a[N], was[N], ans[N];
vector < ll > ord, g[N];
bool cyc;
void dfs(ll v){
was[v] = 1;
for(ll u : g[v])
if(!was[u])
dfs(u);
ord.push_back(v);
}
bool f(ll sz){
cyc = 0, ord.clear();
fill(was, was + sz + 1, 0);
for(ll i = 0; i <= sz; i++){
g[i].clear();
if(i - n >= 0) g[i].push_back(i - n);
if(i + m <= sz) g[i].push_back(i + m);
}
for(ll i = 0; i <= sz; i++)
if(!was[i])
dfs(i);
reverse(ord.begin(), ord.end());
fill(was, was + sz + 1, 0);
for(ll v : ord){
was[v] = 1;
for(ll u : g[v]){
if(was[u]){
return 0;
}
}
}
return 1;
}
void solve(){
cin >> n >> m;
ll l = 0, r = n + m, val = 0;
while(r - l > 1){
ll md = (l + r) / 2;
if(f(md)) l = md;
else r = md;
}
fill(ans, ans + l + 1, 0), f(l);
for(ll i = 0; i <= l; i++) ans[ord[i]] = i + 1;
ll p = ans[0];
cout << l << '\n';
for(ll i = 1; i <= l; i++) cout << ans[i] - p << ' ', p += ans[i] - p;
cout << '\n';
}
signed main(){
ll cs;
cin >> cs;
while(cs--){
solve();
}
}
Compilation message
sequence.cpp: In function 'void solve()':
sequence.cpp:52:23: warning: unused variable 'val' [-Wunused-variable]
52 | ll l = 0, r = n + m, val = 0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12880 KB |
Ok |
2 |
Correct |
3 ms |
12880 KB |
Ok |
3 |
Correct |
3 ms |
12932 KB |
Ok |
4 |
Correct |
3 ms |
12880 KB |
Ok |
5 |
Correct |
3 ms |
12880 KB |
Ok |
6 |
Correct |
3 ms |
12880 KB |
Ok |
7 |
Correct |
3 ms |
13048 KB |
Ok |
8 |
Correct |
3 ms |
12940 KB |
Ok |
9 |
Correct |
3 ms |
12880 KB |
Ok |
10 |
Correct |
3 ms |
12880 KB |
Ok |
11 |
Correct |
4 ms |
12880 KB |
Ok |
12 |
Correct |
4 ms |
12880 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12880 KB |
Ok |
2 |
Correct |
3 ms |
13052 KB |
Ok |
3 |
Correct |
3 ms |
13048 KB |
Ok |
4 |
Correct |
3 ms |
12880 KB |
Ok |
5 |
Correct |
3 ms |
12880 KB |
Ok |
6 |
Correct |
5 ms |
13136 KB |
Ok |
7 |
Correct |
28 ms |
13904 KB |
Ok |
8 |
Correct |
9 ms |
13392 KB |
Ok |
9 |
Correct |
22 ms |
14152 KB |
Ok |
10 |
Correct |
12 ms |
13648 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
12880 KB |
Ok |
2 |
Correct |
2 ms |
12880 KB |
Ok |
3 |
Correct |
2 ms |
13048 KB |
Ok |
4 |
Correct |
3 ms |
12880 KB |
Ok |
5 |
Correct |
3 ms |
12880 KB |
Ok |
6 |
Correct |
3 ms |
12936 KB |
Ok |
7 |
Correct |
3 ms |
12880 KB |
Ok |
8 |
Correct |
3 ms |
12880 KB |
Ok |
9 |
Correct |
3 ms |
12880 KB |
Ok |
10 |
Correct |
3 ms |
12880 KB |
Ok |
11 |
Correct |
3 ms |
12892 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
13052 KB |
Ok |
2 |
Correct |
3 ms |
13048 KB |
Ok |
3 |
Correct |
3 ms |
12880 KB |
Ok |
4 |
Correct |
3 ms |
12880 KB |
Ok |
5 |
Correct |
3 ms |
12880 KB |
Ok |
6 |
Correct |
218 ms |
32800 KB |
Ok |
7 |
Correct |
202 ms |
34488 KB |
Ok |
8 |
Correct |
347 ms |
36604 KB |
Ok |
9 |
Correct |
276 ms |
35864 KB |
Ok |
10 |
Correct |
165 ms |
24528 KB |
Ok |
11 |
Correct |
283 ms |
37048 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12880 KB |
Ok |
2 |
Correct |
3 ms |
12880 KB |
Ok |
3 |
Correct |
3 ms |
12932 KB |
Ok |
4 |
Correct |
3 ms |
12880 KB |
Ok |
5 |
Correct |
3 ms |
12880 KB |
Ok |
6 |
Correct |
3 ms |
12880 KB |
Ok |
7 |
Correct |
3 ms |
13048 KB |
Ok |
8 |
Correct |
3 ms |
12940 KB |
Ok |
9 |
Correct |
3 ms |
12880 KB |
Ok |
10 |
Correct |
3 ms |
12880 KB |
Ok |
11 |
Correct |
4 ms |
12880 KB |
Ok |
12 |
Correct |
4 ms |
12880 KB |
Ok |
13 |
Correct |
3 ms |
12880 KB |
Ok |
14 |
Correct |
2 ms |
12880 KB |
Ok |
15 |
Correct |
2 ms |
13048 KB |
Ok |
16 |
Correct |
3 ms |
12880 KB |
Ok |
17 |
Correct |
3 ms |
12880 KB |
Ok |
18 |
Correct |
3 ms |
12936 KB |
Ok |
19 |
Correct |
3 ms |
12880 KB |
Ok |
20 |
Correct |
3 ms |
12880 KB |
Ok |
21 |
Correct |
3 ms |
12880 KB |
Ok |
22 |
Correct |
3 ms |
12880 KB |
Ok |
23 |
Correct |
3 ms |
12892 KB |
Ok |
24 |
Correct |
6 ms |
12880 KB |
Ok |
25 |
Correct |
9 ms |
13136 KB |
Ok |
26 |
Correct |
8 ms |
13136 KB |
Ok |
27 |
Correct |
6 ms |
12880 KB |
Ok |
28 |
Correct |
5 ms |
12880 KB |
Ok |
29 |
Correct |
5 ms |
12880 KB |
Ok |
30 |
Correct |
4 ms |
12880 KB |
Ok |
31 |
Correct |
5 ms |
12936 KB |
Ok |
32 |
Correct |
5 ms |
12880 KB |
Ok |
33 |
Correct |
5 ms |
12880 KB |
Ok |
34 |
Correct |
10 ms |
13392 KB |
Ok |
35 |
Correct |
14 ms |
13392 KB |
Ok |
36 |
Correct |
13 ms |
13412 KB |
Ok |
37 |
Correct |
9 ms |
13392 KB |
Ok |
38 |
Correct |
9 ms |
13392 KB |
Ok |
39 |
Correct |
9 ms |
13392 KB |
Ok |
40 |
Correct |
13 ms |
13392 KB |
Ok |
41 |
Correct |
11 ms |
13392 KB |
Ok |
42 |
Correct |
15 ms |
13420 KB |
Ok |
43 |
Correct |
10 ms |
13392 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12880 KB |
Ok |
2 |
Correct |
3 ms |
12880 KB |
Ok |
3 |
Correct |
3 ms |
12932 KB |
Ok |
4 |
Correct |
3 ms |
12880 KB |
Ok |
5 |
Correct |
3 ms |
12880 KB |
Ok |
6 |
Correct |
3 ms |
12880 KB |
Ok |
7 |
Correct |
3 ms |
13048 KB |
Ok |
8 |
Correct |
3 ms |
12940 KB |
Ok |
9 |
Correct |
3 ms |
12880 KB |
Ok |
10 |
Correct |
3 ms |
12880 KB |
Ok |
11 |
Correct |
4 ms |
12880 KB |
Ok |
12 |
Correct |
4 ms |
12880 KB |
Ok |
13 |
Correct |
3 ms |
12880 KB |
Ok |
14 |
Correct |
3 ms |
13052 KB |
Ok |
15 |
Correct |
3 ms |
13048 KB |
Ok |
16 |
Correct |
3 ms |
12880 KB |
Ok |
17 |
Correct |
3 ms |
12880 KB |
Ok |
18 |
Correct |
5 ms |
13136 KB |
Ok |
19 |
Correct |
28 ms |
13904 KB |
Ok |
20 |
Correct |
9 ms |
13392 KB |
Ok |
21 |
Correct |
22 ms |
14152 KB |
Ok |
22 |
Correct |
12 ms |
13648 KB |
Ok |
23 |
Correct |
3 ms |
12880 KB |
Ok |
24 |
Correct |
2 ms |
12880 KB |
Ok |
25 |
Correct |
2 ms |
13048 KB |
Ok |
26 |
Correct |
3 ms |
12880 KB |
Ok |
27 |
Correct |
3 ms |
12880 KB |
Ok |
28 |
Correct |
3 ms |
12936 KB |
Ok |
29 |
Correct |
3 ms |
12880 KB |
Ok |
30 |
Correct |
3 ms |
12880 KB |
Ok |
31 |
Correct |
3 ms |
12880 KB |
Ok |
32 |
Correct |
3 ms |
12880 KB |
Ok |
33 |
Correct |
3 ms |
12892 KB |
Ok |
34 |
Correct |
6 ms |
12880 KB |
Ok |
35 |
Correct |
9 ms |
13136 KB |
Ok |
36 |
Correct |
8 ms |
13136 KB |
Ok |
37 |
Correct |
6 ms |
12880 KB |
Ok |
38 |
Correct |
5 ms |
12880 KB |
Ok |
39 |
Correct |
5 ms |
12880 KB |
Ok |
40 |
Correct |
4 ms |
12880 KB |
Ok |
41 |
Correct |
5 ms |
12936 KB |
Ok |
42 |
Correct |
5 ms |
12880 KB |
Ok |
43 |
Correct |
5 ms |
12880 KB |
Ok |
44 |
Correct |
10 ms |
13392 KB |
Ok |
45 |
Correct |
14 ms |
13392 KB |
Ok |
46 |
Correct |
13 ms |
13412 KB |
Ok |
47 |
Correct |
9 ms |
13392 KB |
Ok |
48 |
Correct |
9 ms |
13392 KB |
Ok |
49 |
Correct |
9 ms |
13392 KB |
Ok |
50 |
Correct |
13 ms |
13392 KB |
Ok |
51 |
Correct |
11 ms |
13392 KB |
Ok |
52 |
Correct |
15 ms |
13420 KB |
Ok |
53 |
Correct |
10 ms |
13392 KB |
Ok |
54 |
Correct |
141 ms |
18536 KB |
Ok |
55 |
Correct |
167 ms |
19136 KB |
Ok |
56 |
Correct |
157 ms |
18876 KB |
Ok |
57 |
Correct |
110 ms |
17852 KB |
Ok |
58 |
Correct |
157 ms |
18876 KB |
Ok |
59 |
Correct |
165 ms |
18620 KB |
Ok |
60 |
Correct |
137 ms |
18108 KB |
Ok |
61 |
Correct |
120 ms |
18384 KB |
Ok |
62 |
Correct |
188 ms |
19132 KB |
Ok |
63 |
Correct |
147 ms |
18308 KB |
Ok |
64 |
Correct |
171 ms |
18884 KB |
Ok |
65 |
Correct |
170 ms |
18880 KB |
Ok |
66 |
Correct |
136 ms |
18456 KB |
Ok |
67 |
Correct |
148 ms |
18108 KB |
Ok |
68 |
Correct |
177 ms |
18624 KB |
Ok |
69 |
Correct |
548 ms |
27648 KB |
Ok |
70 |
Correct |
511 ms |
27836 KB |
Ok |
71 |
Correct |
524 ms |
27580 KB |
Ok |
72 |
Correct |
510 ms |
27340 KB |
Ok |
73 |
Correct |
579 ms |
27736 KB |
Ok |
74 |
Correct |
522 ms |
27456 KB |
Ok |
75 |
Correct |
528 ms |
27580 KB |
Ok |
76 |
Correct |
526 ms |
27580 KB |
Ok |
77 |
Correct |
559 ms |
27568 KB |
Ok |
78 |
Correct |
557 ms |
27324 KB |
Ok |
79 |
Correct |
559 ms |
27980 KB |
Ok |
80 |
Correct |
523 ms |
27580 KB |
Ok |
81 |
Correct |
488 ms |
27836 KB |
Ok |
82 |
Correct |
628 ms |
27624 KB |
Ok |
83 |
Correct |
534 ms |
27584 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
12880 KB |
Ok |
2 |
Correct |
3 ms |
12880 KB |
Ok |
3 |
Correct |
3 ms |
12932 KB |
Ok |
4 |
Correct |
3 ms |
12880 KB |
Ok |
5 |
Correct |
3 ms |
12880 KB |
Ok |
6 |
Correct |
3 ms |
12880 KB |
Ok |
7 |
Correct |
3 ms |
13048 KB |
Ok |
8 |
Correct |
3 ms |
12940 KB |
Ok |
9 |
Correct |
3 ms |
12880 KB |
Ok |
10 |
Correct |
3 ms |
12880 KB |
Ok |
11 |
Correct |
4 ms |
12880 KB |
Ok |
12 |
Correct |
4 ms |
12880 KB |
Ok |
13 |
Correct |
3 ms |
12880 KB |
Ok |
14 |
Correct |
3 ms |
13052 KB |
Ok |
15 |
Correct |
3 ms |
13048 KB |
Ok |
16 |
Correct |
3 ms |
12880 KB |
Ok |
17 |
Correct |
3 ms |
12880 KB |
Ok |
18 |
Correct |
5 ms |
13136 KB |
Ok |
19 |
Correct |
28 ms |
13904 KB |
Ok |
20 |
Correct |
9 ms |
13392 KB |
Ok |
21 |
Correct |
22 ms |
14152 KB |
Ok |
22 |
Correct |
12 ms |
13648 KB |
Ok |
23 |
Correct |
3 ms |
12880 KB |
Ok |
24 |
Correct |
2 ms |
12880 KB |
Ok |
25 |
Correct |
2 ms |
13048 KB |
Ok |
26 |
Correct |
3 ms |
12880 KB |
Ok |
27 |
Correct |
3 ms |
12880 KB |
Ok |
28 |
Correct |
3 ms |
12936 KB |
Ok |
29 |
Correct |
3 ms |
12880 KB |
Ok |
30 |
Correct |
3 ms |
12880 KB |
Ok |
31 |
Correct |
3 ms |
12880 KB |
Ok |
32 |
Correct |
3 ms |
12880 KB |
Ok |
33 |
Correct |
3 ms |
12892 KB |
Ok |
34 |
Correct |
3 ms |
13052 KB |
Ok |
35 |
Correct |
3 ms |
13048 KB |
Ok |
36 |
Correct |
3 ms |
12880 KB |
Ok |
37 |
Correct |
3 ms |
12880 KB |
Ok |
38 |
Correct |
3 ms |
12880 KB |
Ok |
39 |
Correct |
218 ms |
32800 KB |
Ok |
40 |
Correct |
202 ms |
34488 KB |
Ok |
41 |
Correct |
347 ms |
36604 KB |
Ok |
42 |
Correct |
276 ms |
35864 KB |
Ok |
43 |
Correct |
165 ms |
24528 KB |
Ok |
44 |
Correct |
283 ms |
37048 KB |
Ok |
45 |
Correct |
6 ms |
12880 KB |
Ok |
46 |
Correct |
9 ms |
13136 KB |
Ok |
47 |
Correct |
8 ms |
13136 KB |
Ok |
48 |
Correct |
6 ms |
12880 KB |
Ok |
49 |
Correct |
5 ms |
12880 KB |
Ok |
50 |
Correct |
5 ms |
12880 KB |
Ok |
51 |
Correct |
4 ms |
12880 KB |
Ok |
52 |
Correct |
5 ms |
12936 KB |
Ok |
53 |
Correct |
5 ms |
12880 KB |
Ok |
54 |
Correct |
5 ms |
12880 KB |
Ok |
55 |
Correct |
10 ms |
13392 KB |
Ok |
56 |
Correct |
14 ms |
13392 KB |
Ok |
57 |
Correct |
13 ms |
13412 KB |
Ok |
58 |
Correct |
9 ms |
13392 KB |
Ok |
59 |
Correct |
9 ms |
13392 KB |
Ok |
60 |
Correct |
9 ms |
13392 KB |
Ok |
61 |
Correct |
13 ms |
13392 KB |
Ok |
62 |
Correct |
11 ms |
13392 KB |
Ok |
63 |
Correct |
15 ms |
13420 KB |
Ok |
64 |
Correct |
10 ms |
13392 KB |
Ok |
65 |
Correct |
141 ms |
18536 KB |
Ok |
66 |
Correct |
167 ms |
19136 KB |
Ok |
67 |
Correct |
157 ms |
18876 KB |
Ok |
68 |
Correct |
110 ms |
17852 KB |
Ok |
69 |
Correct |
157 ms |
18876 KB |
Ok |
70 |
Correct |
165 ms |
18620 KB |
Ok |
71 |
Correct |
137 ms |
18108 KB |
Ok |
72 |
Correct |
120 ms |
18384 KB |
Ok |
73 |
Correct |
188 ms |
19132 KB |
Ok |
74 |
Correct |
147 ms |
18308 KB |
Ok |
75 |
Correct |
171 ms |
18884 KB |
Ok |
76 |
Correct |
170 ms |
18880 KB |
Ok |
77 |
Correct |
136 ms |
18456 KB |
Ok |
78 |
Correct |
148 ms |
18108 KB |
Ok |
79 |
Correct |
177 ms |
18624 KB |
Ok |
80 |
Correct |
548 ms |
27648 KB |
Ok |
81 |
Correct |
511 ms |
27836 KB |
Ok |
82 |
Correct |
524 ms |
27580 KB |
Ok |
83 |
Correct |
510 ms |
27340 KB |
Ok |
84 |
Correct |
579 ms |
27736 KB |
Ok |
85 |
Correct |
522 ms |
27456 KB |
Ok |
86 |
Correct |
528 ms |
27580 KB |
Ok |
87 |
Correct |
526 ms |
27580 KB |
Ok |
88 |
Correct |
559 ms |
27568 KB |
Ok |
89 |
Correct |
557 ms |
27324 KB |
Ok |
90 |
Correct |
559 ms |
27980 KB |
Ok |
91 |
Correct |
523 ms |
27580 KB |
Ok |
92 |
Correct |
488 ms |
27836 KB |
Ok |
93 |
Correct |
628 ms |
27624 KB |
Ok |
94 |
Correct |
534 ms |
27584 KB |
Ok |
95 |
Correct |
426 ms |
30136 KB |
Ok |
96 |
Correct |
707 ms |
41136 KB |
Ok |
97 |
Correct |
555 ms |
37764 KB |
Ok |
98 |
Correct |
380 ms |
36792 KB |
Ok |
99 |
Correct |
468 ms |
36788 KB |
Ok |
100 |
Correct |
491 ms |
37296 KB |
Ok |
101 |
Correct |
487 ms |
38656 KB |
Ok |
102 |
Correct |
474 ms |
37556 KB |
Ok |
103 |
Correct |
541 ms |
38576 KB |
Ok |
104 |
Correct |
581 ms |
39912 KB |
Ok |
105 |
Correct |
642 ms |
40368 KB |
Ok |
106 |
Correct |
596 ms |
39084 KB |
Ok |
107 |
Correct |
604 ms |
39144 KB |
Ok |
108 |
Correct |
682 ms |
40628 KB |
Ok |
109 |
Correct |
551 ms |
40368 KB |
Ok |
110 |
Execution timed out |
2069 ms |
53284 KB |
Time limit exceeded |
111 |
Halted |
0 ms |
0 KB |
- |