#include <bits/stdc++.h>
using namespace std;
const int N = 400005;
vector<int> vec, res;
vector<int> G[N];
int vis[N];
int n, m;
bool ok;
void dfs(int u, bool trace) {
vis[u] = 1;
for (auto v : G[u]) {
if (!vis[v]) dfs(v, trace);
else ok &= vis[v] == 2;
}
vis[u] = 2;
if (trace) vec.push_back(u);
}
bool check(int x, bool trace) {
for (int i = 0; i <= x; ++i) {
G[i].clear(), vis[i] = 0;
}
// u -> v <-> S(u) < S(v)
for (int i = n; i <= x; ++i) {
G[i].push_back(i - n);
}
for (int i = m; i <= x; ++i) {
G[i - m].push_back(i);
}
ok = 1;
for (int i = 0; i <= x; ++i) {
if (!vis[i]) dfs(i, trace);
}
return ok;
}
void solve() {
cin >> n >> m;
int l = 0, r = max(n, m) * 2;
while (l < r) {
int mid = (l + r + 1) >> 1;
if (check(mid, 0)) l = mid;
else r = mid - 1;
}
vec.clear(), check(l, 1);
reverse(vec.begin(), vec.end());
int len = vec.size(), pos0 = 0;
for (int i = 0; i < len; ++i) if (!vec[i]) pos0 = i;
res.assign(len, 0);
for (int i = 0; i < len; ++i) {
res[vec[i]] = i - pos0;
}
printf("%d\n", len - 1);
for (int i = 1; i < len; ++i) printf("%d ", res[i] - res[i - 1]); printf("\n");
}
int main() {
ios::sync_with_stdio(false);
int t; cin >> t; while (t--) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9720 KB |
Ok |
2 |
Correct |
9 ms |
9720 KB |
Ok |
3 |
Correct |
9 ms |
9748 KB |
Ok |
4 |
Correct |
10 ms |
9748 KB |
Ok |
5 |
Correct |
9 ms |
9932 KB |
Ok |
6 |
Correct |
9 ms |
10004 KB |
Ok |
7 |
Correct |
9 ms |
10004 KB |
Ok |
8 |
Correct |
9 ms |
10004 KB |
Ok |
9 |
Correct |
10 ms |
10004 KB |
Ok |
10 |
Correct |
9 ms |
10004 KB |
Ok |
11 |
Correct |
9 ms |
10004 KB |
Ok |
12 |
Correct |
9 ms |
10004 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
10004 KB |
Ok |
2 |
Correct |
9 ms |
10004 KB |
Ok |
3 |
Correct |
9 ms |
10004 KB |
Ok |
4 |
Correct |
10 ms |
10004 KB |
Ok |
5 |
Correct |
10 ms |
10004 KB |
Ok |
6 |
Correct |
17 ms |
10348 KB |
Ok |
7 |
Correct |
49 ms |
11640 KB |
Ok |
8 |
Correct |
25 ms |
11640 KB |
Ok |
9 |
Correct |
61 ms |
12044 KB |
Ok |
10 |
Correct |
33 ms |
12044 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
12044 KB |
Ok |
2 |
Correct |
8 ms |
12044 KB |
Ok |
3 |
Correct |
9 ms |
12044 KB |
Ok |
4 |
Correct |
9 ms |
12044 KB |
Ok |
5 |
Correct |
9 ms |
12044 KB |
Ok |
6 |
Correct |
9 ms |
12044 KB |
Ok |
7 |
Correct |
9 ms |
12044 KB |
Ok |
8 |
Correct |
9 ms |
12044 KB |
Ok |
9 |
Correct |
10 ms |
12044 KB |
Ok |
10 |
Correct |
9 ms |
12044 KB |
Ok |
11 |
Correct |
9 ms |
12044 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
12044 KB |
Ok |
2 |
Correct |
11 ms |
12044 KB |
Ok |
3 |
Correct |
9 ms |
12044 KB |
Ok |
4 |
Correct |
8 ms |
12044 KB |
Ok |
5 |
Correct |
9 ms |
12044 KB |
Ok |
6 |
Correct |
426 ms |
30212 KB |
Ok |
7 |
Correct |
347 ms |
33124 KB |
Ok |
8 |
Correct |
662 ms |
34788 KB |
Ok |
9 |
Correct |
557 ms |
34788 KB |
Ok |
10 |
Correct |
323 ms |
34788 KB |
Ok |
11 |
Correct |
613 ms |
35764 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9720 KB |
Ok |
2 |
Correct |
9 ms |
9720 KB |
Ok |
3 |
Correct |
9 ms |
9748 KB |
Ok |
4 |
Correct |
10 ms |
9748 KB |
Ok |
5 |
Correct |
9 ms |
9932 KB |
Ok |
6 |
Correct |
9 ms |
10004 KB |
Ok |
7 |
Correct |
9 ms |
10004 KB |
Ok |
8 |
Correct |
9 ms |
10004 KB |
Ok |
9 |
Correct |
10 ms |
10004 KB |
Ok |
10 |
Correct |
9 ms |
10004 KB |
Ok |
11 |
Correct |
9 ms |
10004 KB |
Ok |
12 |
Correct |
9 ms |
10004 KB |
Ok |
13 |
Correct |
9 ms |
12044 KB |
Ok |
14 |
Correct |
8 ms |
12044 KB |
Ok |
15 |
Correct |
9 ms |
12044 KB |
Ok |
16 |
Correct |
9 ms |
12044 KB |
Ok |
17 |
Correct |
9 ms |
12044 KB |
Ok |
18 |
Correct |
9 ms |
12044 KB |
Ok |
19 |
Correct |
9 ms |
12044 KB |
Ok |
20 |
Correct |
9 ms |
12044 KB |
Ok |
21 |
Correct |
10 ms |
12044 KB |
Ok |
22 |
Correct |
9 ms |
12044 KB |
Ok |
23 |
Correct |
9 ms |
12044 KB |
Ok |
24 |
Correct |
20 ms |
35764 KB |
Ok |
25 |
Correct |
14 ms |
35764 KB |
Ok |
26 |
Correct |
15 ms |
35764 KB |
Ok |
27 |
Correct |
14 ms |
35764 KB |
Ok |
28 |
Correct |
13 ms |
35764 KB |
Ok |
29 |
Correct |
14 ms |
35764 KB |
Ok |
30 |
Correct |
13 ms |
35764 KB |
Ok |
31 |
Correct |
14 ms |
35764 KB |
Ok |
32 |
Correct |
15 ms |
35764 KB |
Ok |
33 |
Correct |
13 ms |
35764 KB |
Ok |
34 |
Correct |
23 ms |
35764 KB |
Ok |
35 |
Correct |
25 ms |
35764 KB |
Ok |
36 |
Correct |
24 ms |
35764 KB |
Ok |
37 |
Correct |
26 ms |
35764 KB |
Ok |
38 |
Correct |
24 ms |
35764 KB |
Ok |
39 |
Correct |
23 ms |
35764 KB |
Ok |
40 |
Correct |
26 ms |
35764 KB |
Ok |
41 |
Correct |
25 ms |
35764 KB |
Ok |
42 |
Correct |
27 ms |
35764 KB |
Ok |
43 |
Correct |
31 ms |
35764 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9720 KB |
Ok |
2 |
Correct |
9 ms |
9720 KB |
Ok |
3 |
Correct |
9 ms |
9748 KB |
Ok |
4 |
Correct |
10 ms |
9748 KB |
Ok |
5 |
Correct |
9 ms |
9932 KB |
Ok |
6 |
Correct |
9 ms |
10004 KB |
Ok |
7 |
Correct |
9 ms |
10004 KB |
Ok |
8 |
Correct |
9 ms |
10004 KB |
Ok |
9 |
Correct |
10 ms |
10004 KB |
Ok |
10 |
Correct |
9 ms |
10004 KB |
Ok |
11 |
Correct |
9 ms |
10004 KB |
Ok |
12 |
Correct |
9 ms |
10004 KB |
Ok |
13 |
Correct |
9 ms |
10004 KB |
Ok |
14 |
Correct |
9 ms |
10004 KB |
Ok |
15 |
Correct |
9 ms |
10004 KB |
Ok |
16 |
Correct |
10 ms |
10004 KB |
Ok |
17 |
Correct |
10 ms |
10004 KB |
Ok |
18 |
Correct |
17 ms |
10348 KB |
Ok |
19 |
Correct |
49 ms |
11640 KB |
Ok |
20 |
Correct |
25 ms |
11640 KB |
Ok |
21 |
Correct |
61 ms |
12044 KB |
Ok |
22 |
Correct |
33 ms |
12044 KB |
Ok |
23 |
Correct |
9 ms |
12044 KB |
Ok |
24 |
Correct |
8 ms |
12044 KB |
Ok |
25 |
Correct |
9 ms |
12044 KB |
Ok |
26 |
Correct |
9 ms |
12044 KB |
Ok |
27 |
Correct |
9 ms |
12044 KB |
Ok |
28 |
Correct |
9 ms |
12044 KB |
Ok |
29 |
Correct |
9 ms |
12044 KB |
Ok |
30 |
Correct |
9 ms |
12044 KB |
Ok |
31 |
Correct |
10 ms |
12044 KB |
Ok |
32 |
Correct |
9 ms |
12044 KB |
Ok |
33 |
Correct |
9 ms |
12044 KB |
Ok |
34 |
Correct |
20 ms |
35764 KB |
Ok |
35 |
Correct |
14 ms |
35764 KB |
Ok |
36 |
Correct |
15 ms |
35764 KB |
Ok |
37 |
Correct |
14 ms |
35764 KB |
Ok |
38 |
Correct |
13 ms |
35764 KB |
Ok |
39 |
Correct |
14 ms |
35764 KB |
Ok |
40 |
Correct |
13 ms |
35764 KB |
Ok |
41 |
Correct |
14 ms |
35764 KB |
Ok |
42 |
Correct |
15 ms |
35764 KB |
Ok |
43 |
Correct |
13 ms |
35764 KB |
Ok |
44 |
Correct |
23 ms |
35764 KB |
Ok |
45 |
Correct |
25 ms |
35764 KB |
Ok |
46 |
Correct |
24 ms |
35764 KB |
Ok |
47 |
Correct |
26 ms |
35764 KB |
Ok |
48 |
Correct |
24 ms |
35764 KB |
Ok |
49 |
Correct |
23 ms |
35764 KB |
Ok |
50 |
Correct |
26 ms |
35764 KB |
Ok |
51 |
Correct |
25 ms |
35764 KB |
Ok |
52 |
Correct |
27 ms |
35764 KB |
Ok |
53 |
Correct |
31 ms |
35764 KB |
Ok |
54 |
Correct |
292 ms |
35764 KB |
Ok |
55 |
Correct |
335 ms |
35764 KB |
Ok |
56 |
Correct |
339 ms |
35764 KB |
Ok |
57 |
Correct |
205 ms |
35764 KB |
Ok |
58 |
Correct |
353 ms |
35764 KB |
Ok |
59 |
Correct |
358 ms |
35764 KB |
Ok |
60 |
Correct |
269 ms |
35764 KB |
Ok |
61 |
Correct |
253 ms |
35764 KB |
Ok |
62 |
Correct |
462 ms |
35764 KB |
Ok |
63 |
Correct |
312 ms |
35764 KB |
Ok |
64 |
Correct |
383 ms |
35764 KB |
Ok |
65 |
Correct |
337 ms |
35764 KB |
Ok |
66 |
Correct |
244 ms |
35764 KB |
Ok |
67 |
Correct |
230 ms |
35764 KB |
Ok |
68 |
Correct |
332 ms |
35764 KB |
Ok |
69 |
Correct |
1428 ms |
35764 KB |
Ok |
70 |
Correct |
1502 ms |
35764 KB |
Ok |
71 |
Correct |
1255 ms |
35764 KB |
Ok |
72 |
Correct |
1214 ms |
35764 KB |
Ok |
73 |
Correct |
1429 ms |
35764 KB |
Ok |
74 |
Correct |
1214 ms |
35764 KB |
Ok |
75 |
Correct |
1115 ms |
35764 KB |
Ok |
76 |
Correct |
1306 ms |
35764 KB |
Ok |
77 |
Correct |
1210 ms |
35764 KB |
Ok |
78 |
Correct |
1372 ms |
35764 KB |
Ok |
79 |
Correct |
1315 ms |
35764 KB |
Ok |
80 |
Correct |
1225 ms |
35764 KB |
Ok |
81 |
Correct |
1213 ms |
35764 KB |
Ok |
82 |
Correct |
1319 ms |
35764 KB |
Ok |
83 |
Correct |
1282 ms |
35764 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9720 KB |
Ok |
2 |
Correct |
9 ms |
9720 KB |
Ok |
3 |
Correct |
9 ms |
9748 KB |
Ok |
4 |
Correct |
10 ms |
9748 KB |
Ok |
5 |
Correct |
9 ms |
9932 KB |
Ok |
6 |
Correct |
9 ms |
10004 KB |
Ok |
7 |
Correct |
9 ms |
10004 KB |
Ok |
8 |
Correct |
9 ms |
10004 KB |
Ok |
9 |
Correct |
10 ms |
10004 KB |
Ok |
10 |
Correct |
9 ms |
10004 KB |
Ok |
11 |
Correct |
9 ms |
10004 KB |
Ok |
12 |
Correct |
9 ms |
10004 KB |
Ok |
13 |
Correct |
9 ms |
10004 KB |
Ok |
14 |
Correct |
9 ms |
10004 KB |
Ok |
15 |
Correct |
9 ms |
10004 KB |
Ok |
16 |
Correct |
10 ms |
10004 KB |
Ok |
17 |
Correct |
10 ms |
10004 KB |
Ok |
18 |
Correct |
17 ms |
10348 KB |
Ok |
19 |
Correct |
49 ms |
11640 KB |
Ok |
20 |
Correct |
25 ms |
11640 KB |
Ok |
21 |
Correct |
61 ms |
12044 KB |
Ok |
22 |
Correct |
33 ms |
12044 KB |
Ok |
23 |
Correct |
9 ms |
12044 KB |
Ok |
24 |
Correct |
8 ms |
12044 KB |
Ok |
25 |
Correct |
9 ms |
12044 KB |
Ok |
26 |
Correct |
9 ms |
12044 KB |
Ok |
27 |
Correct |
9 ms |
12044 KB |
Ok |
28 |
Correct |
9 ms |
12044 KB |
Ok |
29 |
Correct |
9 ms |
12044 KB |
Ok |
30 |
Correct |
9 ms |
12044 KB |
Ok |
31 |
Correct |
10 ms |
12044 KB |
Ok |
32 |
Correct |
9 ms |
12044 KB |
Ok |
33 |
Correct |
9 ms |
12044 KB |
Ok |
34 |
Correct |
9 ms |
12044 KB |
Ok |
35 |
Correct |
11 ms |
12044 KB |
Ok |
36 |
Correct |
9 ms |
12044 KB |
Ok |
37 |
Correct |
8 ms |
12044 KB |
Ok |
38 |
Correct |
9 ms |
12044 KB |
Ok |
39 |
Correct |
426 ms |
30212 KB |
Ok |
40 |
Correct |
347 ms |
33124 KB |
Ok |
41 |
Correct |
662 ms |
34788 KB |
Ok |
42 |
Correct |
557 ms |
34788 KB |
Ok |
43 |
Correct |
323 ms |
34788 KB |
Ok |
44 |
Correct |
613 ms |
35764 KB |
Ok |
45 |
Correct |
20 ms |
35764 KB |
Ok |
46 |
Correct |
14 ms |
35764 KB |
Ok |
47 |
Correct |
15 ms |
35764 KB |
Ok |
48 |
Correct |
14 ms |
35764 KB |
Ok |
49 |
Correct |
13 ms |
35764 KB |
Ok |
50 |
Correct |
14 ms |
35764 KB |
Ok |
51 |
Correct |
13 ms |
35764 KB |
Ok |
52 |
Correct |
14 ms |
35764 KB |
Ok |
53 |
Correct |
15 ms |
35764 KB |
Ok |
54 |
Correct |
13 ms |
35764 KB |
Ok |
55 |
Correct |
23 ms |
35764 KB |
Ok |
56 |
Correct |
25 ms |
35764 KB |
Ok |
57 |
Correct |
24 ms |
35764 KB |
Ok |
58 |
Correct |
26 ms |
35764 KB |
Ok |
59 |
Correct |
24 ms |
35764 KB |
Ok |
60 |
Correct |
23 ms |
35764 KB |
Ok |
61 |
Correct |
26 ms |
35764 KB |
Ok |
62 |
Correct |
25 ms |
35764 KB |
Ok |
63 |
Correct |
27 ms |
35764 KB |
Ok |
64 |
Correct |
31 ms |
35764 KB |
Ok |
65 |
Correct |
292 ms |
35764 KB |
Ok |
66 |
Correct |
335 ms |
35764 KB |
Ok |
67 |
Correct |
339 ms |
35764 KB |
Ok |
68 |
Correct |
205 ms |
35764 KB |
Ok |
69 |
Correct |
353 ms |
35764 KB |
Ok |
70 |
Correct |
358 ms |
35764 KB |
Ok |
71 |
Correct |
269 ms |
35764 KB |
Ok |
72 |
Correct |
253 ms |
35764 KB |
Ok |
73 |
Correct |
462 ms |
35764 KB |
Ok |
74 |
Correct |
312 ms |
35764 KB |
Ok |
75 |
Correct |
383 ms |
35764 KB |
Ok |
76 |
Correct |
337 ms |
35764 KB |
Ok |
77 |
Correct |
244 ms |
35764 KB |
Ok |
78 |
Correct |
230 ms |
35764 KB |
Ok |
79 |
Correct |
332 ms |
35764 KB |
Ok |
80 |
Correct |
1428 ms |
35764 KB |
Ok |
81 |
Correct |
1502 ms |
35764 KB |
Ok |
82 |
Correct |
1255 ms |
35764 KB |
Ok |
83 |
Correct |
1214 ms |
35764 KB |
Ok |
84 |
Correct |
1429 ms |
35764 KB |
Ok |
85 |
Correct |
1214 ms |
35764 KB |
Ok |
86 |
Correct |
1115 ms |
35764 KB |
Ok |
87 |
Correct |
1306 ms |
35764 KB |
Ok |
88 |
Correct |
1210 ms |
35764 KB |
Ok |
89 |
Correct |
1372 ms |
35764 KB |
Ok |
90 |
Correct |
1315 ms |
35764 KB |
Ok |
91 |
Correct |
1225 ms |
35764 KB |
Ok |
92 |
Correct |
1213 ms |
35764 KB |
Ok |
93 |
Correct |
1319 ms |
35764 KB |
Ok |
94 |
Correct |
1282 ms |
35764 KB |
Ok |
95 |
Correct |
953 ms |
35764 KB |
Ok |
96 |
Execution timed out |
2020 ms |
35764 KB |
Time limit exceeded |
97 |
Halted |
0 ms |
0 KB |
- |