#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr ll INFLL = numeric_limits<ll>::max() / 2;
template<class T>
istream &operator>>(istream &is, vector<T> &a) {
for (auto &i : a) {
is >> i;
}
return is;
}
int main() {
#ifdef __APPLE__
freopen("input.txt", "r", stdin);
#endif
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
int l = 0, r = 2 * (n + m) + 1;
while (l + 1 < r) {
int mid = (l + r) / 2;
vector<vector<int>> g(mid + 1); // i -> j means pref[i] > pref[j]
for (int i = 0; i + m <= mid; ++i) {
g[i + m].push_back(i);
}
for (int i = 0; i + n <= mid; ++i) {
g[i].push_back(i + n);
}
vector<int> used(mid + 1, -1);
bool cycle = 0;
auto dfs = [&](auto dfs, int v) -> void {
used[v] = 0;
for (auto u : g[v]) {
if (used[u] == -1) {
dfs(dfs, u);
} else if (used[u] == 0) {
cycle = 1;
}
}
used[v] = 1;
};
for (int i = 0; i <= mid; ++i) {
if (used[i] == -1) {
dfs(dfs, i);
}
}
if (!cycle) {
l = mid;
} else {
r = mid;
}
}
vector<vector<int>> g(l + 1); // i -> j means pref[i] > pref[j]
for (int i = 0; i + m <= l; ++i) {
g[i + m].push_back(i);
}
for (int i = 0; i + n <= l; ++i) {
g[i].push_back(i + n);
}
vector<ll> dp(l + 1);
vector<bool> used(l + 1);
auto dfs = [&](auto dfs, int v) -> void {
used[v] = 1;
for (auto u : g[v]) {
if (!used[u]) {
dfs(dfs, u);
}
dp[v] = max(dp[v], dp[u] + 1);
}
dp[v] = max(dp[v], v + 1ll);
};
for (int i = 0; i <= l; ++i) {
if (!used[i]) {
dfs(dfs, i);
}
}
for (int i = 0; i + m <= l; ++i) {
assert(dp[i + m] > dp[i]);
}
for (int i = 0; i + n <= l; ++i) {
assert(dp[i + n] < dp[i]);
}
cout << l << "\n";
for (int i = 1; i <= l; ++i) {
assert(dp[i] != dp[i - 1]);
cout << dp[i] - dp[i - 1] << " ";
}
cout << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Ok |
2 |
Correct |
1 ms |
212 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 |
1 ms |
212 KB |
Ok |
8 |
Correct |
1 ms |
212 KB |
Ok |
9 |
Correct |
1 ms |
212 KB |
Ok |
10 |
Correct |
1 ms |
212 KB |
Ok |
11 |
Correct |
1 ms |
212 KB |
Ok |
12 |
Correct |
1 ms |
212 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Ok |
2 |
Correct |
0 ms |
296 KB |
Ok |
3 |
Correct |
1 ms |
212 KB |
Ok |
4 |
Correct |
1 ms |
212 KB |
Ok |
5 |
Correct |
1 ms |
300 KB |
Ok |
6 |
Correct |
15 ms |
532 KB |
Ok |
7 |
Correct |
80 ms |
1624 KB |
Ok |
8 |
Correct |
36 ms |
892 KB |
Ok |
9 |
Correct |
85 ms |
1708 KB |
Ok |
10 |
Correct |
52 ms |
1120 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Ok |
2 |
Correct |
1 ms |
212 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 |
1 ms |
304 KB |
Ok |
8 |
Correct |
0 ms |
304 KB |
Ok |
9 |
Correct |
0 ms |
212 KB |
Ok |
10 |
Correct |
1 ms |
212 KB |
Ok |
11 |
Correct |
1 ms |
212 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Ok |
2 |
Correct |
1 ms |
296 KB |
Ok |
3 |
Correct |
1 ms |
280 KB |
Ok |
4 |
Correct |
1 ms |
212 KB |
Ok |
5 |
Correct |
1 ms |
304 KB |
Ok |
6 |
Correct |
927 ms |
19756 KB |
Ok |
7 |
Correct |
848 ms |
22680 KB |
Ok |
8 |
Correct |
1516 ms |
25296 KB |
Ok |
9 |
Correct |
1123 ms |
23284 KB |
Ok |
10 |
Correct |
572 ms |
12748 KB |
Ok |
11 |
Correct |
999 ms |
23940 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Ok |
2 |
Correct |
1 ms |
212 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 |
1 ms |
212 KB |
Ok |
8 |
Correct |
1 ms |
212 KB |
Ok |
9 |
Correct |
1 ms |
212 KB |
Ok |
10 |
Correct |
1 ms |
212 KB |
Ok |
11 |
Correct |
1 ms |
212 KB |
Ok |
12 |
Correct |
1 ms |
212 KB |
Ok |
13 |
Correct |
1 ms |
300 KB |
Ok |
14 |
Correct |
1 ms |
212 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 |
1 ms |
212 KB |
Ok |
19 |
Correct |
1 ms |
304 KB |
Ok |
20 |
Correct |
0 ms |
304 KB |
Ok |
21 |
Correct |
0 ms |
212 KB |
Ok |
22 |
Correct |
1 ms |
212 KB |
Ok |
23 |
Correct |
1 ms |
212 KB |
Ok |
24 |
Correct |
15 ms |
544 KB |
Ok |
25 |
Correct |
12 ms |
556 KB |
Ok |
26 |
Correct |
14 ms |
468 KB |
Ok |
27 |
Correct |
12 ms |
468 KB |
Ok |
28 |
Correct |
10 ms |
432 KB |
Ok |
29 |
Correct |
8 ms |
468 KB |
Ok |
30 |
Correct |
9 ms |
468 KB |
Ok |
31 |
Correct |
12 ms |
604 KB |
Ok |
32 |
Correct |
15 ms |
556 KB |
Ok |
33 |
Correct |
12 ms |
424 KB |
Ok |
34 |
Correct |
27 ms |
756 KB |
Ok |
35 |
Correct |
29 ms |
776 KB |
Ok |
36 |
Correct |
35 ms |
812 KB |
Ok |
37 |
Correct |
34 ms |
812 KB |
Ok |
38 |
Correct |
31 ms |
880 KB |
Ok |
39 |
Correct |
26 ms |
844 KB |
Ok |
40 |
Correct |
31 ms |
804 KB |
Ok |
41 |
Correct |
30 ms |
848 KB |
Ok |
42 |
Correct |
28 ms |
844 KB |
Ok |
43 |
Correct |
34 ms |
904 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Ok |
2 |
Correct |
1 ms |
212 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 |
1 ms |
212 KB |
Ok |
8 |
Correct |
1 ms |
212 KB |
Ok |
9 |
Correct |
1 ms |
212 KB |
Ok |
10 |
Correct |
1 ms |
212 KB |
Ok |
11 |
Correct |
1 ms |
212 KB |
Ok |
12 |
Correct |
1 ms |
212 KB |
Ok |
13 |
Correct |
1 ms |
212 KB |
Ok |
14 |
Correct |
0 ms |
296 KB |
Ok |
15 |
Correct |
1 ms |
212 KB |
Ok |
16 |
Correct |
1 ms |
212 KB |
Ok |
17 |
Correct |
1 ms |
300 KB |
Ok |
18 |
Correct |
15 ms |
532 KB |
Ok |
19 |
Correct |
80 ms |
1624 KB |
Ok |
20 |
Correct |
36 ms |
892 KB |
Ok |
21 |
Correct |
85 ms |
1708 KB |
Ok |
22 |
Correct |
52 ms |
1120 KB |
Ok |
23 |
Correct |
1 ms |
300 KB |
Ok |
24 |
Correct |
1 ms |
212 KB |
Ok |
25 |
Correct |
1 ms |
212 KB |
Ok |
26 |
Correct |
1 ms |
212 KB |
Ok |
27 |
Correct |
1 ms |
212 KB |
Ok |
28 |
Correct |
1 ms |
212 KB |
Ok |
29 |
Correct |
1 ms |
304 KB |
Ok |
30 |
Correct |
0 ms |
304 KB |
Ok |
31 |
Correct |
0 ms |
212 KB |
Ok |
32 |
Correct |
1 ms |
212 KB |
Ok |
33 |
Correct |
1 ms |
212 KB |
Ok |
34 |
Correct |
15 ms |
544 KB |
Ok |
35 |
Correct |
12 ms |
556 KB |
Ok |
36 |
Correct |
14 ms |
468 KB |
Ok |
37 |
Correct |
12 ms |
468 KB |
Ok |
38 |
Correct |
10 ms |
432 KB |
Ok |
39 |
Correct |
8 ms |
468 KB |
Ok |
40 |
Correct |
9 ms |
468 KB |
Ok |
41 |
Correct |
12 ms |
604 KB |
Ok |
42 |
Correct |
15 ms |
556 KB |
Ok |
43 |
Correct |
12 ms |
424 KB |
Ok |
44 |
Correct |
27 ms |
756 KB |
Ok |
45 |
Correct |
29 ms |
776 KB |
Ok |
46 |
Correct |
35 ms |
812 KB |
Ok |
47 |
Correct |
34 ms |
812 KB |
Ok |
48 |
Correct |
31 ms |
880 KB |
Ok |
49 |
Correct |
26 ms |
844 KB |
Ok |
50 |
Correct |
31 ms |
804 KB |
Ok |
51 |
Correct |
30 ms |
848 KB |
Ok |
52 |
Correct |
28 ms |
844 KB |
Ok |
53 |
Correct |
34 ms |
904 KB |
Ok |
54 |
Correct |
592 ms |
7396 KB |
Ok |
55 |
Correct |
822 ms |
7368 KB |
Ok |
56 |
Correct |
725 ms |
7944 KB |
Ok |
57 |
Correct |
498 ms |
7504 KB |
Ok |
58 |
Correct |
652 ms |
7204 KB |
Ok |
59 |
Correct |
568 ms |
8272 KB |
Ok |
60 |
Correct |
469 ms |
9028 KB |
Ok |
61 |
Correct |
558 ms |
8156 KB |
Ok |
62 |
Correct |
754 ms |
8488 KB |
Ok |
63 |
Correct |
452 ms |
6620 KB |
Ok |
64 |
Correct |
665 ms |
7960 KB |
Ok |
65 |
Correct |
619 ms |
7384 KB |
Ok |
66 |
Correct |
503 ms |
7488 KB |
Ok |
67 |
Correct |
400 ms |
6840 KB |
Ok |
68 |
Correct |
616 ms |
9532 KB |
Ok |
69 |
Correct |
1544 ms |
17124 KB |
Ok |
70 |
Correct |
1621 ms |
18420 KB |
Ok |
71 |
Correct |
1458 ms |
15536 KB |
Ok |
72 |
Correct |
1383 ms |
16740 KB |
Ok |
73 |
Correct |
1366 ms |
15832 KB |
Ok |
74 |
Correct |
1456 ms |
15508 KB |
Ok |
75 |
Correct |
1445 ms |
14928 KB |
Ok |
76 |
Correct |
1811 ms |
17988 KB |
Ok |
77 |
Correct |
1791 ms |
15004 KB |
Ok |
78 |
Correct |
1463 ms |
17544 KB |
Ok |
79 |
Correct |
1664 ms |
16948 KB |
Ok |
80 |
Correct |
1453 ms |
16016 KB |
Ok |
81 |
Correct |
1588 ms |
17248 KB |
Ok |
82 |
Correct |
1424 ms |
16040 KB |
Ok |
83 |
Correct |
1333 ms |
14944 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Ok |
2 |
Correct |
1 ms |
212 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 |
1 ms |
212 KB |
Ok |
8 |
Correct |
1 ms |
212 KB |
Ok |
9 |
Correct |
1 ms |
212 KB |
Ok |
10 |
Correct |
1 ms |
212 KB |
Ok |
11 |
Correct |
1 ms |
212 KB |
Ok |
12 |
Correct |
1 ms |
212 KB |
Ok |
13 |
Correct |
1 ms |
212 KB |
Ok |
14 |
Correct |
0 ms |
296 KB |
Ok |
15 |
Correct |
1 ms |
212 KB |
Ok |
16 |
Correct |
1 ms |
212 KB |
Ok |
17 |
Correct |
1 ms |
300 KB |
Ok |
18 |
Correct |
15 ms |
532 KB |
Ok |
19 |
Correct |
80 ms |
1624 KB |
Ok |
20 |
Correct |
36 ms |
892 KB |
Ok |
21 |
Correct |
85 ms |
1708 KB |
Ok |
22 |
Correct |
52 ms |
1120 KB |
Ok |
23 |
Correct |
1 ms |
300 KB |
Ok |
24 |
Correct |
1 ms |
212 KB |
Ok |
25 |
Correct |
1 ms |
212 KB |
Ok |
26 |
Correct |
1 ms |
212 KB |
Ok |
27 |
Correct |
1 ms |
212 KB |
Ok |
28 |
Correct |
1 ms |
212 KB |
Ok |
29 |
Correct |
1 ms |
304 KB |
Ok |
30 |
Correct |
0 ms |
304 KB |
Ok |
31 |
Correct |
0 ms |
212 KB |
Ok |
32 |
Correct |
1 ms |
212 KB |
Ok |
33 |
Correct |
1 ms |
212 KB |
Ok |
34 |
Correct |
1 ms |
212 KB |
Ok |
35 |
Correct |
1 ms |
296 KB |
Ok |
36 |
Correct |
1 ms |
280 KB |
Ok |
37 |
Correct |
1 ms |
212 KB |
Ok |
38 |
Correct |
1 ms |
304 KB |
Ok |
39 |
Correct |
927 ms |
19756 KB |
Ok |
40 |
Correct |
848 ms |
22680 KB |
Ok |
41 |
Correct |
1516 ms |
25296 KB |
Ok |
42 |
Correct |
1123 ms |
23284 KB |
Ok |
43 |
Correct |
572 ms |
12748 KB |
Ok |
44 |
Correct |
999 ms |
23940 KB |
Ok |
45 |
Correct |
15 ms |
544 KB |
Ok |
46 |
Correct |
12 ms |
556 KB |
Ok |
47 |
Correct |
14 ms |
468 KB |
Ok |
48 |
Correct |
12 ms |
468 KB |
Ok |
49 |
Correct |
10 ms |
432 KB |
Ok |
50 |
Correct |
8 ms |
468 KB |
Ok |
51 |
Correct |
9 ms |
468 KB |
Ok |
52 |
Correct |
12 ms |
604 KB |
Ok |
53 |
Correct |
15 ms |
556 KB |
Ok |
54 |
Correct |
12 ms |
424 KB |
Ok |
55 |
Correct |
27 ms |
756 KB |
Ok |
56 |
Correct |
29 ms |
776 KB |
Ok |
57 |
Correct |
35 ms |
812 KB |
Ok |
58 |
Correct |
34 ms |
812 KB |
Ok |
59 |
Correct |
31 ms |
880 KB |
Ok |
60 |
Correct |
26 ms |
844 KB |
Ok |
61 |
Correct |
31 ms |
804 KB |
Ok |
62 |
Correct |
30 ms |
848 KB |
Ok |
63 |
Correct |
28 ms |
844 KB |
Ok |
64 |
Correct |
34 ms |
904 KB |
Ok |
65 |
Correct |
592 ms |
7396 KB |
Ok |
66 |
Correct |
822 ms |
7368 KB |
Ok |
67 |
Correct |
725 ms |
7944 KB |
Ok |
68 |
Correct |
498 ms |
7504 KB |
Ok |
69 |
Correct |
652 ms |
7204 KB |
Ok |
70 |
Correct |
568 ms |
8272 KB |
Ok |
71 |
Correct |
469 ms |
9028 KB |
Ok |
72 |
Correct |
558 ms |
8156 KB |
Ok |
73 |
Correct |
754 ms |
8488 KB |
Ok |
74 |
Correct |
452 ms |
6620 KB |
Ok |
75 |
Correct |
665 ms |
7960 KB |
Ok |
76 |
Correct |
619 ms |
7384 KB |
Ok |
77 |
Correct |
503 ms |
7488 KB |
Ok |
78 |
Correct |
400 ms |
6840 KB |
Ok |
79 |
Correct |
616 ms |
9532 KB |
Ok |
80 |
Correct |
1544 ms |
17124 KB |
Ok |
81 |
Correct |
1621 ms |
18420 KB |
Ok |
82 |
Correct |
1458 ms |
15536 KB |
Ok |
83 |
Correct |
1383 ms |
16740 KB |
Ok |
84 |
Correct |
1366 ms |
15832 KB |
Ok |
85 |
Correct |
1456 ms |
15508 KB |
Ok |
86 |
Correct |
1445 ms |
14928 KB |
Ok |
87 |
Correct |
1811 ms |
17988 KB |
Ok |
88 |
Correct |
1791 ms |
15004 KB |
Ok |
89 |
Correct |
1463 ms |
17544 KB |
Ok |
90 |
Correct |
1664 ms |
16948 KB |
Ok |
91 |
Correct |
1453 ms |
16016 KB |
Ok |
92 |
Correct |
1588 ms |
17248 KB |
Ok |
93 |
Correct |
1424 ms |
16040 KB |
Ok |
94 |
Correct |
1333 ms |
14944 KB |
Ok |
95 |
Correct |
1457 ms |
21104 KB |
Ok |
96 |
Execution timed out |
2074 ms |
25968 KB |
Time limit exceeded |
97 |
Halted |
0 ms |
0 KB |
- |