#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define pb push_back
#define FIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;
ll nxt() {ll num; cin >> num; return num;}
const int maxn = 4e5 + 7;
int n, m;
bool ndag;
vector <int> v;
vector <int> adj[maxn];
int val[maxn], bio[maxn];
void dfs(int x) {
bio[x] = 1;
for (auto it : adj[x]) {
if (bio[it] == 2) continue;
if (bio[it] == 1) {
ndag = 1;
continue;
}
dfs(it);
}
bio[x] = 2;
v.pb(x);
}
bool stask(int ma) {
for (int i = 0; i <= ma; i++) adj[i].clear();
v.clear();
for (int i = 0; i <= ma; i++) bio[i] = 0;
ndag = 0;
for (int i = 0; i <= ma; i++) if (i + m <= ma) adj[i].pb(i+m);
for (int i = 0; i <= ma; i++) if (i + n <= ma) adj[i+n].pb(i);
for (int i = 0; i <= ma; i++) {
if (!bio[i]) dfs(i);
}
if (ndag) return 1;
int cc = 0;
reverse(all(v));
for (auto it : v) {
val[it] = cc++;
}
vector <int> ps (ma+1, 0);
for (int i = 1; i <= ma; i++) {
ps[i] = ps[i-1] + val[i] - val[i-1];
}
for (int i = 1; i <= ma; i++) {
if (i - m >= 0) {
if (ps[i] - ps[i-m] <= 0) return 1;
}
if (i - n >= 0) {
if (ps[i] - ps[i-n] >= 0) return 1;
}
}
return 0;
}
void task() {
cin >> n >> m;
ll lo = max(n, m) - 1, hi = max(n, m) * 2;
if (n == m) {
cout << lo << "\n";
for (int i = 1; i <= lo; i++) cout << "1 ";
cout << "\n";
return;
}
while (lo < hi) {
int mid = (lo + hi + 1) / 2;
if (stask(mid)) hi = mid - 1;
else lo = mid;
}
stask(hi);
cout << hi << "\n";
for (int i = 1; i <= hi; i++) {
cout << val[i] - val[i-1] << " ";
}
cout << "\n";
}
int main () {
FIO;
int t;
cin >> t;
while (t--) task();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Ok |
2 |
Correct |
5 ms |
9676 KB |
Ok |
3 |
Correct |
5 ms |
9684 KB |
Ok |
4 |
Correct |
5 ms |
9684 KB |
Ok |
5 |
Correct |
5 ms |
9664 KB |
Ok |
6 |
Correct |
5 ms |
9684 KB |
Ok |
7 |
Correct |
6 ms |
9684 KB |
Ok |
8 |
Correct |
6 ms |
9684 KB |
Ok |
9 |
Correct |
7 ms |
9684 KB |
Ok |
10 |
Correct |
7 ms |
9644 KB |
Ok |
11 |
Correct |
5 ms |
9720 KB |
Ok |
12 |
Correct |
5 ms |
9608 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
9724 KB |
Ok |
2 |
Correct |
5 ms |
9812 KB |
Ok |
3 |
Correct |
5 ms |
9684 KB |
Ok |
4 |
Correct |
5 ms |
9616 KB |
Ok |
5 |
Correct |
5 ms |
9684 KB |
Ok |
6 |
Correct |
10 ms |
9940 KB |
Ok |
7 |
Correct |
37 ms |
11120 KB |
Ok |
8 |
Correct |
18 ms |
10392 KB |
Ok |
9 |
Correct |
38 ms |
11392 KB |
Ok |
10 |
Correct |
24 ms |
10656 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Ok |
2 |
Correct |
6 ms |
9728 KB |
Ok |
3 |
Correct |
6 ms |
9724 KB |
Ok |
4 |
Correct |
5 ms |
9684 KB |
Ok |
5 |
Correct |
5 ms |
9716 KB |
Ok |
6 |
Correct |
5 ms |
9640 KB |
Ok |
7 |
Correct |
5 ms |
9724 KB |
Ok |
8 |
Correct |
5 ms |
9684 KB |
Ok |
9 |
Correct |
6 ms |
9684 KB |
Ok |
10 |
Correct |
7 ms |
9684 KB |
Ok |
11 |
Correct |
5 ms |
9684 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Ok |
2 |
Correct |
7 ms |
9732 KB |
Ok |
3 |
Correct |
6 ms |
9636 KB |
Ok |
4 |
Correct |
6 ms |
9728 KB |
Ok |
5 |
Correct |
7 ms |
9720 KB |
Ok |
6 |
Correct |
454 ms |
28092 KB |
Ok |
7 |
Correct |
349 ms |
30280 KB |
Ok |
8 |
Correct |
765 ms |
32332 KB |
Ok |
9 |
Correct |
582 ms |
31160 KB |
Ok |
10 |
Correct |
337 ms |
22496 KB |
Ok |
11 |
Correct |
635 ms |
33060 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Ok |
2 |
Correct |
5 ms |
9676 KB |
Ok |
3 |
Correct |
5 ms |
9684 KB |
Ok |
4 |
Correct |
5 ms |
9684 KB |
Ok |
5 |
Correct |
5 ms |
9664 KB |
Ok |
6 |
Correct |
5 ms |
9684 KB |
Ok |
7 |
Correct |
6 ms |
9684 KB |
Ok |
8 |
Correct |
6 ms |
9684 KB |
Ok |
9 |
Correct |
7 ms |
9684 KB |
Ok |
10 |
Correct |
7 ms |
9644 KB |
Ok |
11 |
Correct |
5 ms |
9720 KB |
Ok |
12 |
Correct |
5 ms |
9608 KB |
Ok |
13 |
Correct |
5 ms |
9684 KB |
Ok |
14 |
Correct |
6 ms |
9728 KB |
Ok |
15 |
Correct |
6 ms |
9724 KB |
Ok |
16 |
Correct |
5 ms |
9684 KB |
Ok |
17 |
Correct |
5 ms |
9716 KB |
Ok |
18 |
Correct |
5 ms |
9640 KB |
Ok |
19 |
Correct |
5 ms |
9724 KB |
Ok |
20 |
Correct |
5 ms |
9684 KB |
Ok |
21 |
Correct |
6 ms |
9684 KB |
Ok |
22 |
Correct |
7 ms |
9684 KB |
Ok |
23 |
Correct |
5 ms |
9684 KB |
Ok |
24 |
Correct |
9 ms |
9812 KB |
Ok |
25 |
Correct |
10 ms |
9940 KB |
Ok |
26 |
Correct |
10 ms |
9928 KB |
Ok |
27 |
Correct |
10 ms |
9812 KB |
Ok |
28 |
Correct |
10 ms |
9812 KB |
Ok |
29 |
Correct |
9 ms |
9840 KB |
Ok |
30 |
Correct |
10 ms |
9872 KB |
Ok |
31 |
Correct |
11 ms |
9940 KB |
Ok |
32 |
Correct |
10 ms |
9848 KB |
Ok |
33 |
Correct |
9 ms |
9852 KB |
Ok |
34 |
Correct |
18 ms |
10240 KB |
Ok |
35 |
Correct |
22 ms |
10220 KB |
Ok |
36 |
Correct |
18 ms |
10196 KB |
Ok |
37 |
Correct |
17 ms |
10196 KB |
Ok |
38 |
Correct |
18 ms |
10228 KB |
Ok |
39 |
Correct |
19 ms |
10196 KB |
Ok |
40 |
Correct |
21 ms |
10140 KB |
Ok |
41 |
Correct |
18 ms |
10196 KB |
Ok |
42 |
Correct |
18 ms |
10232 KB |
Ok |
43 |
Correct |
18 ms |
10196 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Ok |
2 |
Correct |
5 ms |
9676 KB |
Ok |
3 |
Correct |
5 ms |
9684 KB |
Ok |
4 |
Correct |
5 ms |
9684 KB |
Ok |
5 |
Correct |
5 ms |
9664 KB |
Ok |
6 |
Correct |
5 ms |
9684 KB |
Ok |
7 |
Correct |
6 ms |
9684 KB |
Ok |
8 |
Correct |
6 ms |
9684 KB |
Ok |
9 |
Correct |
7 ms |
9684 KB |
Ok |
10 |
Correct |
7 ms |
9644 KB |
Ok |
11 |
Correct |
5 ms |
9720 KB |
Ok |
12 |
Correct |
5 ms |
9608 KB |
Ok |
13 |
Correct |
7 ms |
9724 KB |
Ok |
14 |
Correct |
5 ms |
9812 KB |
Ok |
15 |
Correct |
5 ms |
9684 KB |
Ok |
16 |
Correct |
5 ms |
9616 KB |
Ok |
17 |
Correct |
5 ms |
9684 KB |
Ok |
18 |
Correct |
10 ms |
9940 KB |
Ok |
19 |
Correct |
37 ms |
11120 KB |
Ok |
20 |
Correct |
18 ms |
10392 KB |
Ok |
21 |
Correct |
38 ms |
11392 KB |
Ok |
22 |
Correct |
24 ms |
10656 KB |
Ok |
23 |
Correct |
5 ms |
9684 KB |
Ok |
24 |
Correct |
6 ms |
9728 KB |
Ok |
25 |
Correct |
6 ms |
9724 KB |
Ok |
26 |
Correct |
5 ms |
9684 KB |
Ok |
27 |
Correct |
5 ms |
9716 KB |
Ok |
28 |
Correct |
5 ms |
9640 KB |
Ok |
29 |
Correct |
5 ms |
9724 KB |
Ok |
30 |
Correct |
5 ms |
9684 KB |
Ok |
31 |
Correct |
6 ms |
9684 KB |
Ok |
32 |
Correct |
7 ms |
9684 KB |
Ok |
33 |
Correct |
5 ms |
9684 KB |
Ok |
34 |
Correct |
9 ms |
9812 KB |
Ok |
35 |
Correct |
10 ms |
9940 KB |
Ok |
36 |
Correct |
10 ms |
9928 KB |
Ok |
37 |
Correct |
10 ms |
9812 KB |
Ok |
38 |
Correct |
10 ms |
9812 KB |
Ok |
39 |
Correct |
9 ms |
9840 KB |
Ok |
40 |
Correct |
10 ms |
9872 KB |
Ok |
41 |
Correct |
11 ms |
9940 KB |
Ok |
42 |
Correct |
10 ms |
9848 KB |
Ok |
43 |
Correct |
9 ms |
9852 KB |
Ok |
44 |
Correct |
18 ms |
10240 KB |
Ok |
45 |
Correct |
22 ms |
10220 KB |
Ok |
46 |
Correct |
18 ms |
10196 KB |
Ok |
47 |
Correct |
17 ms |
10196 KB |
Ok |
48 |
Correct |
18 ms |
10228 KB |
Ok |
49 |
Correct |
19 ms |
10196 KB |
Ok |
50 |
Correct |
21 ms |
10140 KB |
Ok |
51 |
Correct |
18 ms |
10196 KB |
Ok |
52 |
Correct |
18 ms |
10232 KB |
Ok |
53 |
Correct |
18 ms |
10196 KB |
Ok |
54 |
Correct |
247 ms |
16220 KB |
Ok |
55 |
Correct |
329 ms |
16588 KB |
Ok |
56 |
Correct |
290 ms |
16504 KB |
Ok |
57 |
Correct |
181 ms |
15440 KB |
Ok |
58 |
Correct |
305 ms |
16348 KB |
Ok |
59 |
Correct |
240 ms |
15944 KB |
Ok |
60 |
Correct |
215 ms |
15580 KB |
Ok |
61 |
Correct |
203 ms |
15764 KB |
Ok |
62 |
Correct |
379 ms |
16936 KB |
Ok |
63 |
Correct |
225 ms |
15744 KB |
Ok |
64 |
Correct |
330 ms |
16524 KB |
Ok |
65 |
Correct |
311 ms |
16276 KB |
Ok |
66 |
Correct |
236 ms |
15892 KB |
Ok |
67 |
Correct |
215 ms |
15508 KB |
Ok |
68 |
Correct |
287 ms |
16292 KB |
Ok |
69 |
Correct |
1079 ms |
25344 KB |
Ok |
70 |
Correct |
1132 ms |
25624 KB |
Ok |
71 |
Correct |
1167 ms |
25200 KB |
Ok |
72 |
Correct |
948 ms |
25096 KB |
Ok |
73 |
Correct |
1222 ms |
25572 KB |
Ok |
74 |
Correct |
1029 ms |
25152 KB |
Ok |
75 |
Correct |
964 ms |
25192 KB |
Ok |
76 |
Correct |
1036 ms |
25356 KB |
Ok |
77 |
Correct |
1061 ms |
25192 KB |
Ok |
78 |
Correct |
1046 ms |
25116 KB |
Ok |
79 |
Correct |
1048 ms |
25560 KB |
Ok |
80 |
Correct |
1036 ms |
25232 KB |
Ok |
81 |
Correct |
1116 ms |
25560 KB |
Ok |
82 |
Correct |
1066 ms |
25308 KB |
Ok |
83 |
Correct |
1088 ms |
25280 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Ok |
2 |
Correct |
5 ms |
9676 KB |
Ok |
3 |
Correct |
5 ms |
9684 KB |
Ok |
4 |
Correct |
5 ms |
9684 KB |
Ok |
5 |
Correct |
5 ms |
9664 KB |
Ok |
6 |
Correct |
5 ms |
9684 KB |
Ok |
7 |
Correct |
6 ms |
9684 KB |
Ok |
8 |
Correct |
6 ms |
9684 KB |
Ok |
9 |
Correct |
7 ms |
9684 KB |
Ok |
10 |
Correct |
7 ms |
9644 KB |
Ok |
11 |
Correct |
5 ms |
9720 KB |
Ok |
12 |
Correct |
5 ms |
9608 KB |
Ok |
13 |
Correct |
7 ms |
9724 KB |
Ok |
14 |
Correct |
5 ms |
9812 KB |
Ok |
15 |
Correct |
5 ms |
9684 KB |
Ok |
16 |
Correct |
5 ms |
9616 KB |
Ok |
17 |
Correct |
5 ms |
9684 KB |
Ok |
18 |
Correct |
10 ms |
9940 KB |
Ok |
19 |
Correct |
37 ms |
11120 KB |
Ok |
20 |
Correct |
18 ms |
10392 KB |
Ok |
21 |
Correct |
38 ms |
11392 KB |
Ok |
22 |
Correct |
24 ms |
10656 KB |
Ok |
23 |
Correct |
5 ms |
9684 KB |
Ok |
24 |
Correct |
6 ms |
9728 KB |
Ok |
25 |
Correct |
6 ms |
9724 KB |
Ok |
26 |
Correct |
5 ms |
9684 KB |
Ok |
27 |
Correct |
5 ms |
9716 KB |
Ok |
28 |
Correct |
5 ms |
9640 KB |
Ok |
29 |
Correct |
5 ms |
9724 KB |
Ok |
30 |
Correct |
5 ms |
9684 KB |
Ok |
31 |
Correct |
6 ms |
9684 KB |
Ok |
32 |
Correct |
7 ms |
9684 KB |
Ok |
33 |
Correct |
5 ms |
9684 KB |
Ok |
34 |
Correct |
6 ms |
9684 KB |
Ok |
35 |
Correct |
7 ms |
9732 KB |
Ok |
36 |
Correct |
6 ms |
9636 KB |
Ok |
37 |
Correct |
6 ms |
9728 KB |
Ok |
38 |
Correct |
7 ms |
9720 KB |
Ok |
39 |
Correct |
454 ms |
28092 KB |
Ok |
40 |
Correct |
349 ms |
30280 KB |
Ok |
41 |
Correct |
765 ms |
32332 KB |
Ok |
42 |
Correct |
582 ms |
31160 KB |
Ok |
43 |
Correct |
337 ms |
22496 KB |
Ok |
44 |
Correct |
635 ms |
33060 KB |
Ok |
45 |
Correct |
9 ms |
9812 KB |
Ok |
46 |
Correct |
10 ms |
9940 KB |
Ok |
47 |
Correct |
10 ms |
9928 KB |
Ok |
48 |
Correct |
10 ms |
9812 KB |
Ok |
49 |
Correct |
10 ms |
9812 KB |
Ok |
50 |
Correct |
9 ms |
9840 KB |
Ok |
51 |
Correct |
10 ms |
9872 KB |
Ok |
52 |
Correct |
11 ms |
9940 KB |
Ok |
53 |
Correct |
10 ms |
9848 KB |
Ok |
54 |
Correct |
9 ms |
9852 KB |
Ok |
55 |
Correct |
18 ms |
10240 KB |
Ok |
56 |
Correct |
22 ms |
10220 KB |
Ok |
57 |
Correct |
18 ms |
10196 KB |
Ok |
58 |
Correct |
17 ms |
10196 KB |
Ok |
59 |
Correct |
18 ms |
10228 KB |
Ok |
60 |
Correct |
19 ms |
10196 KB |
Ok |
61 |
Correct |
21 ms |
10140 KB |
Ok |
62 |
Correct |
18 ms |
10196 KB |
Ok |
63 |
Correct |
18 ms |
10232 KB |
Ok |
64 |
Correct |
18 ms |
10196 KB |
Ok |
65 |
Correct |
247 ms |
16220 KB |
Ok |
66 |
Correct |
329 ms |
16588 KB |
Ok |
67 |
Correct |
290 ms |
16504 KB |
Ok |
68 |
Correct |
181 ms |
15440 KB |
Ok |
69 |
Correct |
305 ms |
16348 KB |
Ok |
70 |
Correct |
240 ms |
15944 KB |
Ok |
71 |
Correct |
215 ms |
15580 KB |
Ok |
72 |
Correct |
203 ms |
15764 KB |
Ok |
73 |
Correct |
379 ms |
16936 KB |
Ok |
74 |
Correct |
225 ms |
15744 KB |
Ok |
75 |
Correct |
330 ms |
16524 KB |
Ok |
76 |
Correct |
311 ms |
16276 KB |
Ok |
77 |
Correct |
236 ms |
15892 KB |
Ok |
78 |
Correct |
215 ms |
15508 KB |
Ok |
79 |
Correct |
287 ms |
16292 KB |
Ok |
80 |
Correct |
1079 ms |
25344 KB |
Ok |
81 |
Correct |
1132 ms |
25624 KB |
Ok |
82 |
Correct |
1167 ms |
25200 KB |
Ok |
83 |
Correct |
948 ms |
25096 KB |
Ok |
84 |
Correct |
1222 ms |
25572 KB |
Ok |
85 |
Correct |
1029 ms |
25152 KB |
Ok |
86 |
Correct |
964 ms |
25192 KB |
Ok |
87 |
Correct |
1036 ms |
25356 KB |
Ok |
88 |
Correct |
1061 ms |
25192 KB |
Ok |
89 |
Correct |
1046 ms |
25116 KB |
Ok |
90 |
Correct |
1048 ms |
25560 KB |
Ok |
91 |
Correct |
1036 ms |
25232 KB |
Ok |
92 |
Correct |
1116 ms |
25560 KB |
Ok |
93 |
Correct |
1066 ms |
25308 KB |
Ok |
94 |
Correct |
1088 ms |
25280 KB |
Ok |
95 |
Correct |
734 ms |
28320 KB |
Ok |
96 |
Correct |
1239 ms |
35124 KB |
Ok |
97 |
Correct |
1251 ms |
31144 KB |
Ok |
98 |
Correct |
702 ms |
30968 KB |
Ok |
99 |
Correct |
1033 ms |
29760 KB |
Ok |
100 |
Correct |
1093 ms |
31164 KB |
Ok |
101 |
Correct |
1065 ms |
32176 KB |
Ok |
102 |
Correct |
899 ms |
30532 KB |
Ok |
103 |
Correct |
1124 ms |
32828 KB |
Ok |
104 |
Correct |
1191 ms |
34036 KB |
Ok |
105 |
Correct |
1293 ms |
34876 KB |
Ok |
106 |
Correct |
858 ms |
33048 KB |
Ok |
107 |
Correct |
1061 ms |
32904 KB |
Ok |
108 |
Correct |
1465 ms |
35120 KB |
Ok |
109 |
Correct |
1067 ms |
34880 KB |
Ok |
110 |
Execution timed out |
2068 ms |
42756 KB |
Time limit exceeded |
111 |
Halted |
0 ms |
0 KB |
- |