#include <bits/stdc++.h>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")
#define ft first
#define sd second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define pll pair<ll, ll>
#define MP make_pair
#define PB push_back
using namespace std;
typedef long long ll;
const int N = 200100;
vector<int> ts;
int n, m, len, mrk[N], pf[N];
bool cyc;
void dfs(int v){
if (cyc) return;
mrk[v] = 1;
if (v >= m){
if (mrk[v - m] == 0)
dfs(v - m);
else if (mrk[v - m] == 1){
cyc = 1;
return;
}
}
if (v + n <= len){
if (mrk[v + n] == 0)
dfs(v + n);
else if (mrk[v + n] == 1){
cyc = 1;
return;
}
}
mrk[v] = 2;
}
bool ok(){
fill(mrk, mrk + len + 1, 0);
cyc = 0;
for (int i = 0; i <= len && !cyc; i++)
if (mrk[i] == 0)
dfs(i);
return !cyc;
}
void DFS(int v){
mrk[v] = 1;
if (v >= m){
if (mrk[v - m] == 0)
DFS(v - m);
}
if (v + n <= len){
if (mrk[v + n] == 0)
DFS(v + n);
}
ts.PB(v);
}
int main(){
#ifdef _LOCAL
freopen("in.txt","r",stdin);
#else
ios_base::sync_with_stdio(0); cin.tie(0);
#endif // _LOCAL
int qq; cin >> qq;
for (; qq; qq--){
cin >> n >> m;
int l = 0, r = (n + m) * 2;
while (l < r){
int md = (l + r + 1) >> 1;
len = md;
if (ok())
l = md;
else r = md - 1;
}
cout << l << '\n';
len = l;
fill(mrk, mrk + len + 1, 0);
fill(pf, pf + len + 1, -1);
ts.clear();
for (int i = 0; i <= len; i++)
if (!mrk[i])
DFS(i);
int it = -len;
for (int v : ts){
int mx = it;
it++;
if (v >= m)
mx = max(mx, pf[v - m]);
if (v + n <= len)
mx = max(mx, pf[v + n]);
pf[v] = mx + 1;
}
for (int i = 1; i <= len; i++)
cout << pf[i] - pf[i - 1] << " ";
cout << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Ok |
2 |
Correct |
4 ms |
384 KB |
Ok |
3 |
Correct |
5 ms |
384 KB |
Ok |
4 |
Correct |
5 ms |
384 KB |
Ok |
5 |
Correct |
5 ms |
384 KB |
Ok |
6 |
Correct |
5 ms |
384 KB |
Ok |
7 |
Correct |
5 ms |
384 KB |
Ok |
8 |
Correct |
5 ms |
384 KB |
Ok |
9 |
Correct |
5 ms |
384 KB |
Ok |
10 |
Correct |
5 ms |
384 KB |
Ok |
11 |
Correct |
5 ms |
384 KB |
Ok |
12 |
Correct |
5 ms |
384 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Ok |
2 |
Correct |
5 ms |
384 KB |
Ok |
3 |
Correct |
5 ms |
384 KB |
Ok |
4 |
Correct |
5 ms |
384 KB |
Ok |
5 |
Correct |
5 ms |
384 KB |
Ok |
6 |
Correct |
7 ms |
512 KB |
Ok |
7 |
Correct |
21 ms |
1280 KB |
Ok |
8 |
Correct |
12 ms |
768 KB |
Ok |
9 |
Correct |
22 ms |
1280 KB |
Ok |
10 |
Correct |
15 ms |
896 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Ok |
2 |
Correct |
4 ms |
384 KB |
Ok |
3 |
Correct |
4 ms |
384 KB |
Ok |
4 |
Correct |
5 ms |
384 KB |
Ok |
5 |
Correct |
4 ms |
384 KB |
Ok |
6 |
Correct |
4 ms |
384 KB |
Ok |
7 |
Correct |
5 ms |
384 KB |
Ok |
8 |
Correct |
5 ms |
384 KB |
Ok |
9 |
Correct |
4 ms |
384 KB |
Ok |
10 |
Correct |
5 ms |
384 KB |
Ok |
11 |
Correct |
4 ms |
384 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Ok |
2 |
Correct |
5 ms |
384 KB |
Ok |
3 |
Correct |
4 ms |
384 KB |
Ok |
4 |
Correct |
4 ms |
384 KB |
Ok |
5 |
Correct |
5 ms |
384 KB |
Ok |
6 |
Correct |
173 ms |
10480 KB |
Ok |
7 |
Correct |
193 ms |
11120 KB |
Ok |
8 |
Correct |
360 ms |
14064 KB |
Ok |
9 |
Correct |
233 ms |
12396 KB |
Ok |
10 |
Correct |
117 ms |
6388 KB |
Ok |
11 |
Correct |
194 ms |
12524 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Ok |
2 |
Correct |
4 ms |
384 KB |
Ok |
3 |
Correct |
5 ms |
384 KB |
Ok |
4 |
Correct |
5 ms |
384 KB |
Ok |
5 |
Correct |
5 ms |
384 KB |
Ok |
6 |
Correct |
5 ms |
384 KB |
Ok |
7 |
Correct |
5 ms |
384 KB |
Ok |
8 |
Correct |
5 ms |
384 KB |
Ok |
9 |
Correct |
5 ms |
384 KB |
Ok |
10 |
Correct |
5 ms |
384 KB |
Ok |
11 |
Correct |
5 ms |
384 KB |
Ok |
12 |
Correct |
5 ms |
384 KB |
Ok |
13 |
Correct |
5 ms |
384 KB |
Ok |
14 |
Correct |
4 ms |
384 KB |
Ok |
15 |
Correct |
4 ms |
384 KB |
Ok |
16 |
Correct |
5 ms |
384 KB |
Ok |
17 |
Correct |
4 ms |
384 KB |
Ok |
18 |
Correct |
4 ms |
384 KB |
Ok |
19 |
Correct |
5 ms |
384 KB |
Ok |
20 |
Correct |
5 ms |
384 KB |
Ok |
21 |
Correct |
4 ms |
384 KB |
Ok |
22 |
Correct |
5 ms |
384 KB |
Ok |
23 |
Correct |
4 ms |
384 KB |
Ok |
24 |
Correct |
7 ms |
384 KB |
Ok |
25 |
Correct |
7 ms |
384 KB |
Ok |
26 |
Correct |
8 ms |
512 KB |
Ok |
27 |
Correct |
6 ms |
384 KB |
Ok |
28 |
Correct |
6 ms |
384 KB |
Ok |
29 |
Correct |
6 ms |
512 KB |
Ok |
30 |
Correct |
6 ms |
384 KB |
Ok |
31 |
Correct |
6 ms |
384 KB |
Ok |
32 |
Correct |
7 ms |
384 KB |
Ok |
33 |
Correct |
6 ms |
384 KB |
Ok |
34 |
Correct |
11 ms |
640 KB |
Ok |
35 |
Correct |
11 ms |
640 KB |
Ok |
36 |
Correct |
11 ms |
896 KB |
Ok |
37 |
Correct |
11 ms |
768 KB |
Ok |
38 |
Correct |
11 ms |
768 KB |
Ok |
39 |
Correct |
10 ms |
640 KB |
Ok |
40 |
Correct |
11 ms |
640 KB |
Ok |
41 |
Correct |
11 ms |
640 KB |
Ok |
42 |
Correct |
11 ms |
640 KB |
Ok |
43 |
Correct |
14 ms |
640 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Ok |
2 |
Correct |
4 ms |
384 KB |
Ok |
3 |
Correct |
5 ms |
384 KB |
Ok |
4 |
Correct |
5 ms |
384 KB |
Ok |
5 |
Correct |
5 ms |
384 KB |
Ok |
6 |
Correct |
5 ms |
384 KB |
Ok |
7 |
Correct |
5 ms |
384 KB |
Ok |
8 |
Correct |
5 ms |
384 KB |
Ok |
9 |
Correct |
5 ms |
384 KB |
Ok |
10 |
Correct |
5 ms |
384 KB |
Ok |
11 |
Correct |
5 ms |
384 KB |
Ok |
12 |
Correct |
5 ms |
384 KB |
Ok |
13 |
Correct |
4 ms |
384 KB |
Ok |
14 |
Correct |
5 ms |
384 KB |
Ok |
15 |
Correct |
5 ms |
384 KB |
Ok |
16 |
Correct |
5 ms |
384 KB |
Ok |
17 |
Correct |
5 ms |
384 KB |
Ok |
18 |
Correct |
7 ms |
512 KB |
Ok |
19 |
Correct |
21 ms |
1280 KB |
Ok |
20 |
Correct |
12 ms |
768 KB |
Ok |
21 |
Correct |
22 ms |
1280 KB |
Ok |
22 |
Correct |
15 ms |
896 KB |
Ok |
23 |
Correct |
5 ms |
384 KB |
Ok |
24 |
Correct |
4 ms |
384 KB |
Ok |
25 |
Correct |
4 ms |
384 KB |
Ok |
26 |
Correct |
5 ms |
384 KB |
Ok |
27 |
Correct |
4 ms |
384 KB |
Ok |
28 |
Correct |
4 ms |
384 KB |
Ok |
29 |
Correct |
5 ms |
384 KB |
Ok |
30 |
Correct |
5 ms |
384 KB |
Ok |
31 |
Correct |
4 ms |
384 KB |
Ok |
32 |
Correct |
5 ms |
384 KB |
Ok |
33 |
Correct |
4 ms |
384 KB |
Ok |
34 |
Correct |
7 ms |
384 KB |
Ok |
35 |
Correct |
7 ms |
384 KB |
Ok |
36 |
Correct |
8 ms |
512 KB |
Ok |
37 |
Correct |
6 ms |
384 KB |
Ok |
38 |
Correct |
6 ms |
384 KB |
Ok |
39 |
Correct |
6 ms |
512 KB |
Ok |
40 |
Correct |
6 ms |
384 KB |
Ok |
41 |
Correct |
6 ms |
384 KB |
Ok |
42 |
Correct |
7 ms |
384 KB |
Ok |
43 |
Correct |
6 ms |
384 KB |
Ok |
44 |
Correct |
11 ms |
640 KB |
Ok |
45 |
Correct |
11 ms |
640 KB |
Ok |
46 |
Correct |
11 ms |
896 KB |
Ok |
47 |
Correct |
11 ms |
768 KB |
Ok |
48 |
Correct |
11 ms |
768 KB |
Ok |
49 |
Correct |
10 ms |
640 KB |
Ok |
50 |
Correct |
11 ms |
640 KB |
Ok |
51 |
Correct |
11 ms |
640 KB |
Ok |
52 |
Correct |
11 ms |
640 KB |
Ok |
53 |
Correct |
14 ms |
640 KB |
Ok |
54 |
Correct |
109 ms |
3420 KB |
Ok |
55 |
Correct |
124 ms |
3568 KB |
Ok |
56 |
Correct |
121 ms |
3572 KB |
Ok |
57 |
Correct |
89 ms |
2804 KB |
Ok |
58 |
Correct |
108 ms |
3060 KB |
Ok |
59 |
Correct |
91 ms |
2932 KB |
Ok |
60 |
Correct |
85 ms |
2676 KB |
Ok |
61 |
Correct |
90 ms |
2872 KB |
Ok |
62 |
Correct |
112 ms |
3316 KB |
Ok |
63 |
Correct |
94 ms |
2932 KB |
Ok |
64 |
Correct |
117 ms |
3572 KB |
Ok |
65 |
Correct |
104 ms |
3192 KB |
Ok |
66 |
Correct |
100 ms |
3060 KB |
Ok |
67 |
Correct |
111 ms |
2932 KB |
Ok |
68 |
Correct |
98 ms |
3060 KB |
Ok |
69 |
Correct |
259 ms |
10740 KB |
Ok |
70 |
Correct |
261 ms |
11340 KB |
Ok |
71 |
Correct |
246 ms |
11124 KB |
Ok |
72 |
Correct |
261 ms |
10736 KB |
Ok |
73 |
Correct |
231 ms |
10860 KB |
Ok |
74 |
Correct |
236 ms |
10608 KB |
Ok |
75 |
Correct |
263 ms |
10228 KB |
Ok |
76 |
Correct |
274 ms |
11056 KB |
Ok |
77 |
Correct |
220 ms |
10408 KB |
Ok |
78 |
Correct |
258 ms |
10836 KB |
Ok |
79 |
Correct |
247 ms |
11000 KB |
Ok |
80 |
Correct |
275 ms |
10996 KB |
Ok |
81 |
Correct |
276 ms |
11152 KB |
Ok |
82 |
Correct |
240 ms |
10868 KB |
Ok |
83 |
Correct |
228 ms |
10352 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Ok |
2 |
Correct |
4 ms |
384 KB |
Ok |
3 |
Correct |
5 ms |
384 KB |
Ok |
4 |
Correct |
5 ms |
384 KB |
Ok |
5 |
Correct |
5 ms |
384 KB |
Ok |
6 |
Correct |
5 ms |
384 KB |
Ok |
7 |
Correct |
5 ms |
384 KB |
Ok |
8 |
Correct |
5 ms |
384 KB |
Ok |
9 |
Correct |
5 ms |
384 KB |
Ok |
10 |
Correct |
5 ms |
384 KB |
Ok |
11 |
Correct |
5 ms |
384 KB |
Ok |
12 |
Correct |
5 ms |
384 KB |
Ok |
13 |
Correct |
4 ms |
384 KB |
Ok |
14 |
Correct |
5 ms |
384 KB |
Ok |
15 |
Correct |
5 ms |
384 KB |
Ok |
16 |
Correct |
5 ms |
384 KB |
Ok |
17 |
Correct |
5 ms |
384 KB |
Ok |
18 |
Correct |
7 ms |
512 KB |
Ok |
19 |
Correct |
21 ms |
1280 KB |
Ok |
20 |
Correct |
12 ms |
768 KB |
Ok |
21 |
Correct |
22 ms |
1280 KB |
Ok |
22 |
Correct |
15 ms |
896 KB |
Ok |
23 |
Correct |
5 ms |
384 KB |
Ok |
24 |
Correct |
4 ms |
384 KB |
Ok |
25 |
Correct |
4 ms |
384 KB |
Ok |
26 |
Correct |
5 ms |
384 KB |
Ok |
27 |
Correct |
4 ms |
384 KB |
Ok |
28 |
Correct |
4 ms |
384 KB |
Ok |
29 |
Correct |
5 ms |
384 KB |
Ok |
30 |
Correct |
5 ms |
384 KB |
Ok |
31 |
Correct |
4 ms |
384 KB |
Ok |
32 |
Correct |
5 ms |
384 KB |
Ok |
33 |
Correct |
4 ms |
384 KB |
Ok |
34 |
Correct |
5 ms |
384 KB |
Ok |
35 |
Correct |
5 ms |
384 KB |
Ok |
36 |
Correct |
4 ms |
384 KB |
Ok |
37 |
Correct |
4 ms |
384 KB |
Ok |
38 |
Correct |
5 ms |
384 KB |
Ok |
39 |
Correct |
173 ms |
10480 KB |
Ok |
40 |
Correct |
193 ms |
11120 KB |
Ok |
41 |
Correct |
360 ms |
14064 KB |
Ok |
42 |
Correct |
233 ms |
12396 KB |
Ok |
43 |
Correct |
117 ms |
6388 KB |
Ok |
44 |
Correct |
194 ms |
12524 KB |
Ok |
45 |
Correct |
7 ms |
384 KB |
Ok |
46 |
Correct |
7 ms |
384 KB |
Ok |
47 |
Correct |
8 ms |
512 KB |
Ok |
48 |
Correct |
6 ms |
384 KB |
Ok |
49 |
Correct |
6 ms |
384 KB |
Ok |
50 |
Correct |
6 ms |
512 KB |
Ok |
51 |
Correct |
6 ms |
384 KB |
Ok |
52 |
Correct |
6 ms |
384 KB |
Ok |
53 |
Correct |
7 ms |
384 KB |
Ok |
54 |
Correct |
6 ms |
384 KB |
Ok |
55 |
Correct |
11 ms |
640 KB |
Ok |
56 |
Correct |
11 ms |
640 KB |
Ok |
57 |
Correct |
11 ms |
896 KB |
Ok |
58 |
Correct |
11 ms |
768 KB |
Ok |
59 |
Correct |
11 ms |
768 KB |
Ok |
60 |
Correct |
10 ms |
640 KB |
Ok |
61 |
Correct |
11 ms |
640 KB |
Ok |
62 |
Correct |
11 ms |
640 KB |
Ok |
63 |
Correct |
11 ms |
640 KB |
Ok |
64 |
Correct |
14 ms |
640 KB |
Ok |
65 |
Correct |
109 ms |
3420 KB |
Ok |
66 |
Correct |
124 ms |
3568 KB |
Ok |
67 |
Correct |
121 ms |
3572 KB |
Ok |
68 |
Correct |
89 ms |
2804 KB |
Ok |
69 |
Correct |
108 ms |
3060 KB |
Ok |
70 |
Correct |
91 ms |
2932 KB |
Ok |
71 |
Correct |
85 ms |
2676 KB |
Ok |
72 |
Correct |
90 ms |
2872 KB |
Ok |
73 |
Correct |
112 ms |
3316 KB |
Ok |
74 |
Correct |
94 ms |
2932 KB |
Ok |
75 |
Correct |
117 ms |
3572 KB |
Ok |
76 |
Correct |
104 ms |
3192 KB |
Ok |
77 |
Correct |
100 ms |
3060 KB |
Ok |
78 |
Correct |
111 ms |
2932 KB |
Ok |
79 |
Correct |
98 ms |
3060 KB |
Ok |
80 |
Correct |
259 ms |
10740 KB |
Ok |
81 |
Correct |
261 ms |
11340 KB |
Ok |
82 |
Correct |
246 ms |
11124 KB |
Ok |
83 |
Correct |
261 ms |
10736 KB |
Ok |
84 |
Correct |
231 ms |
10860 KB |
Ok |
85 |
Correct |
236 ms |
10608 KB |
Ok |
86 |
Correct |
263 ms |
10228 KB |
Ok |
87 |
Correct |
274 ms |
11056 KB |
Ok |
88 |
Correct |
220 ms |
10408 KB |
Ok |
89 |
Correct |
258 ms |
10836 KB |
Ok |
90 |
Correct |
247 ms |
11000 KB |
Ok |
91 |
Correct |
275 ms |
10996 KB |
Ok |
92 |
Correct |
276 ms |
11152 KB |
Ok |
93 |
Correct |
240 ms |
10868 KB |
Ok |
94 |
Correct |
228 ms |
10352 KB |
Ok |
95 |
Runtime error |
51 ms |
5872 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
96 |
Halted |
0 ms |
0 KB |
- |