#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define ld long double
// 217
// 44
using namespace std;
const int INF = 5e8;
const int MAXN = (int) 2e5;
vector <int> g[2 * MAXN + 1];
char vis[2 * MAXN + 1];
void dfs(int nod, bool &ok) {
vis[nod] = 1;
for(auto it : g[nod]) {
if(vis[it] == 0) {
dfs(it, ok);
}
else if(vis[it] == 1) {
ok = 0;
}
if(ok == 0) {
return ;
}
}
vis[nod] = 2;
}
inline bool check(int len, int n, int m) {
int i;
for(i = 0; i <= len; i++) {
g[i].clear();
vis[i] = 0;
}
for(i = 1; i <= len; i++) {
if(i >= n) {
g[i - n].push_back(i);
}
if(i >= m) {
g[i].push_back(i - m);
}
}
bool ok = 1;
for(i = 0; i <= len && ok; i++) {
if(vis[i] == 0) {
dfs(i, ok);
}
}
return ok;
}
inline int get(int n, int m) {
int res = 0;
for(int step = 1 << 18; step; step >>= 1) {
if(res + step <= n + m && check(res + step, n, m)) {
res += step;
}
}
return res;
}
vector <int> ord;
int sp[2 * MAXN + 1];
void dfs1(int nod) {
vis[nod] = 1;
for(auto it : g[nod]) {
if(vis[it] == 0) {
dfs1(it);
}
}
ord.push_back(nod);
}
inline void solve(int sz, int n, int m) {
int i;
for(i = 0; i <= sz; i++) {
g[i].clear();
vis[i] = 0;
if(i - n >= 0) {
g[i - n].push_back(i);
}
if(i - m >= 0) {
g[i].push_back(i - m);
}
}
ord.clear();
for(i = 0; i <= sz; i++) {
if(vis[i] == 0) {
dfs1(i);
}
}
int val = -INF;
for(auto it : ord) {
if(it == 0) {
val = max(val, 0);
sp[it] = 0;
val++;
continue;
}
for(auto itr : g[it]) {
val = max(val, sp[itr] + 1);
}
sp[it] = val;
val++;
}
}
int main() {
//ifstream cin("A.in");
//ofstream cout("A.out");
int t, i, j;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> t;
while(t > 0) {
t--;
int n, m;
cin >> n >> m;
int mn = min(n, m), mx = max(n, m);
if(mx % mn == 0) {
cout << mx - 1 << "\n";
int sign = 1;
if(mn == n) {
sign = -1;
}
for(i = 1; i < mx; i++) {
cout << sign << " ";
}
if(mx > 1) {
cout << "\n";
}
continue;
}
int sz = get(n, m);
solve(sz, n, m);
cout << sz << "\n";
for(i = 1; i <= sz; i++) {
cout << sp[i] - sp[i - 1] << " ";
}
cout << "\n";
}
//cin.close();
//cout.close();
return 0;
}
Compilation message
sequence.cpp: In function 'int main()':
sequence.cpp:116:15: warning: unused variable 'j' [-Wunused-variable]
int t, i, j;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9720 KB |
Ok |
2 |
Correct |
10 ms |
9720 KB |
Ok |
3 |
Correct |
9 ms |
9720 KB |
Ok |
4 |
Correct |
10 ms |
9720 KB |
Ok |
5 |
Correct |
10 ms |
9724 KB |
Ok |
6 |
Correct |
10 ms |
9720 KB |
Ok |
7 |
Correct |
10 ms |
9720 KB |
Ok |
8 |
Correct |
9 ms |
9720 KB |
Ok |
9 |
Correct |
10 ms |
9720 KB |
Ok |
10 |
Correct |
10 ms |
9720 KB |
Ok |
11 |
Correct |
12 ms |
9848 KB |
Ok |
12 |
Correct |
11 ms |
9848 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
9720 KB |
Ok |
2 |
Correct |
9 ms |
9720 KB |
Ok |
3 |
Correct |
10 ms |
9780 KB |
Ok |
4 |
Correct |
9 ms |
9720 KB |
Ok |
5 |
Correct |
9 ms |
9720 KB |
Ok |
6 |
Correct |
13 ms |
9976 KB |
Ok |
7 |
Correct |
25 ms |
11128 KB |
Ok |
8 |
Correct |
17 ms |
10360 KB |
Ok |
9 |
Correct |
25 ms |
11384 KB |
Ok |
10 |
Correct |
20 ms |
10616 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9768 KB |
Ok |
2 |
Correct |
9 ms |
9720 KB |
Ok |
3 |
Correct |
9 ms |
9720 KB |
Ok |
4 |
Correct |
10 ms |
9720 KB |
Ok |
5 |
Correct |
10 ms |
9720 KB |
Ok |
6 |
Correct |
10 ms |
9720 KB |
Ok |
7 |
Correct |
9 ms |
9720 KB |
Ok |
8 |
Correct |
9 ms |
9724 KB |
Ok |
9 |
Correct |
10 ms |
9720 KB |
Ok |
10 |
Correct |
11 ms |
9692 KB |
Ok |
11 |
Correct |
9 ms |
9720 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
9692 KB |
Ok |
2 |
Correct |
9 ms |
9720 KB |
Ok |
3 |
Correct |
9 ms |
9720 KB |
Ok |
4 |
Correct |
10 ms |
9720 KB |
Ok |
5 |
Correct |
10 ms |
9720 KB |
Ok |
6 |
Correct |
272 ms |
28668 KB |
Ok |
7 |
Correct |
263 ms |
29420 KB |
Ok |
8 |
Correct |
484 ms |
33824 KB |
Ok |
9 |
Correct |
332 ms |
31080 KB |
Ok |
10 |
Correct |
183 ms |
20592 KB |
Ok |
11 |
Correct |
354 ms |
31692 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9720 KB |
Ok |
2 |
Correct |
10 ms |
9720 KB |
Ok |
3 |
Correct |
9 ms |
9720 KB |
Ok |
4 |
Correct |
10 ms |
9720 KB |
Ok |
5 |
Correct |
10 ms |
9724 KB |
Ok |
6 |
Correct |
10 ms |
9720 KB |
Ok |
7 |
Correct |
10 ms |
9720 KB |
Ok |
8 |
Correct |
9 ms |
9720 KB |
Ok |
9 |
Correct |
10 ms |
9720 KB |
Ok |
10 |
Correct |
10 ms |
9720 KB |
Ok |
11 |
Correct |
12 ms |
9848 KB |
Ok |
12 |
Correct |
11 ms |
9848 KB |
Ok |
13 |
Correct |
10 ms |
9768 KB |
Ok |
14 |
Correct |
9 ms |
9720 KB |
Ok |
15 |
Correct |
9 ms |
9720 KB |
Ok |
16 |
Correct |
10 ms |
9720 KB |
Ok |
17 |
Correct |
10 ms |
9720 KB |
Ok |
18 |
Correct |
10 ms |
9720 KB |
Ok |
19 |
Correct |
9 ms |
9720 KB |
Ok |
20 |
Correct |
9 ms |
9724 KB |
Ok |
21 |
Correct |
10 ms |
9720 KB |
Ok |
22 |
Correct |
11 ms |
9692 KB |
Ok |
23 |
Correct |
9 ms |
9720 KB |
Ok |
24 |
Correct |
11 ms |
9848 KB |
Ok |
25 |
Correct |
12 ms |
9976 KB |
Ok |
26 |
Correct |
13 ms |
9848 KB |
Ok |
27 |
Correct |
13 ms |
9976 KB |
Ok |
28 |
Correct |
13 ms |
9848 KB |
Ok |
29 |
Correct |
11 ms |
9868 KB |
Ok |
30 |
Correct |
12 ms |
9848 KB |
Ok |
31 |
Correct |
13 ms |
9976 KB |
Ok |
32 |
Correct |
13 ms |
9844 KB |
Ok |
33 |
Correct |
12 ms |
9848 KB |
Ok |
34 |
Correct |
20 ms |
10360 KB |
Ok |
35 |
Correct |
21 ms |
10312 KB |
Ok |
36 |
Correct |
20 ms |
10360 KB |
Ok |
37 |
Correct |
18 ms |
10332 KB |
Ok |
38 |
Correct |
18 ms |
10232 KB |
Ok |
39 |
Correct |
18 ms |
10232 KB |
Ok |
40 |
Correct |
20 ms |
10232 KB |
Ok |
41 |
Correct |
18 ms |
10360 KB |
Ok |
42 |
Correct |
19 ms |
10232 KB |
Ok |
43 |
Correct |
18 ms |
10232 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9720 KB |
Ok |
2 |
Correct |
10 ms |
9720 KB |
Ok |
3 |
Correct |
9 ms |
9720 KB |
Ok |
4 |
Correct |
10 ms |
9720 KB |
Ok |
5 |
Correct |
10 ms |
9724 KB |
Ok |
6 |
Correct |
10 ms |
9720 KB |
Ok |
7 |
Correct |
10 ms |
9720 KB |
Ok |
8 |
Correct |
9 ms |
9720 KB |
Ok |
9 |
Correct |
10 ms |
9720 KB |
Ok |
10 |
Correct |
10 ms |
9720 KB |
Ok |
11 |
Correct |
12 ms |
9848 KB |
Ok |
12 |
Correct |
11 ms |
9848 KB |
Ok |
13 |
Correct |
9 ms |
9720 KB |
Ok |
14 |
Correct |
9 ms |
9720 KB |
Ok |
15 |
Correct |
10 ms |
9780 KB |
Ok |
16 |
Correct |
9 ms |
9720 KB |
Ok |
17 |
Correct |
9 ms |
9720 KB |
Ok |
18 |
Correct |
13 ms |
9976 KB |
Ok |
19 |
Correct |
25 ms |
11128 KB |
Ok |
20 |
Correct |
17 ms |
10360 KB |
Ok |
21 |
Correct |
25 ms |
11384 KB |
Ok |
22 |
Correct |
20 ms |
10616 KB |
Ok |
23 |
Correct |
10 ms |
9768 KB |
Ok |
24 |
Correct |
9 ms |
9720 KB |
Ok |
25 |
Correct |
9 ms |
9720 KB |
Ok |
26 |
Correct |
10 ms |
9720 KB |
Ok |
27 |
Correct |
10 ms |
9720 KB |
Ok |
28 |
Correct |
10 ms |
9720 KB |
Ok |
29 |
Correct |
9 ms |
9720 KB |
Ok |
30 |
Correct |
9 ms |
9724 KB |
Ok |
31 |
Correct |
10 ms |
9720 KB |
Ok |
32 |
Correct |
11 ms |
9692 KB |
Ok |
33 |
Correct |
9 ms |
9720 KB |
Ok |
34 |
Correct |
11 ms |
9848 KB |
Ok |
35 |
Correct |
12 ms |
9976 KB |
Ok |
36 |
Correct |
13 ms |
9848 KB |
Ok |
37 |
Correct |
13 ms |
9976 KB |
Ok |
38 |
Correct |
13 ms |
9848 KB |
Ok |
39 |
Correct |
11 ms |
9868 KB |
Ok |
40 |
Correct |
12 ms |
9848 KB |
Ok |
41 |
Correct |
13 ms |
9976 KB |
Ok |
42 |
Correct |
13 ms |
9844 KB |
Ok |
43 |
Correct |
12 ms |
9848 KB |
Ok |
44 |
Correct |
20 ms |
10360 KB |
Ok |
45 |
Correct |
21 ms |
10312 KB |
Ok |
46 |
Correct |
20 ms |
10360 KB |
Ok |
47 |
Correct |
18 ms |
10332 KB |
Ok |
48 |
Correct |
18 ms |
10232 KB |
Ok |
49 |
Correct |
18 ms |
10232 KB |
Ok |
50 |
Correct |
20 ms |
10232 KB |
Ok |
51 |
Correct |
18 ms |
10360 KB |
Ok |
52 |
Correct |
19 ms |
10232 KB |
Ok |
53 |
Correct |
18 ms |
10232 KB |
Ok |
54 |
Correct |
244 ms |
15272 KB |
Ok |
55 |
Correct |
312 ms |
15600 KB |
Ok |
56 |
Correct |
292 ms |
15708 KB |
Ok |
57 |
Correct |
169 ms |
14580 KB |
Ok |
58 |
Correct |
222 ms |
15088 KB |
Ok |
59 |
Correct |
184 ms |
14804 KB |
Ok |
60 |
Correct |
146 ms |
14448 KB |
Ok |
61 |
Correct |
186 ms |
14832 KB |
Ok |
62 |
Correct |
262 ms |
15220 KB |
Ok |
63 |
Correct |
197 ms |
14832 KB |
Ok |
64 |
Correct |
290 ms |
15604 KB |
Ok |
65 |
Correct |
234 ms |
15392 KB |
Ok |
66 |
Correct |
210 ms |
15088 KB |
Ok |
67 |
Correct |
176 ms |
14832 KB |
Ok |
68 |
Correct |
223 ms |
15092 KB |
Ok |
69 |
Correct |
735 ms |
25780 KB |
Ok |
70 |
Correct |
563 ms |
27120 KB |
Ok |
71 |
Correct |
634 ms |
26576 KB |
Ok |
72 |
Correct |
640 ms |
25856 KB |
Ok |
73 |
Correct |
511 ms |
26480 KB |
Ok |
74 |
Correct |
626 ms |
25840 KB |
Ok |
75 |
Correct |
661 ms |
25036 KB |
Ok |
76 |
Correct |
636 ms |
26480 KB |
Ok |
77 |
Correct |
626 ms |
25076 KB |
Ok |
78 |
Correct |
621 ms |
26216 KB |
Ok |
79 |
Correct |
735 ms |
26608 KB |
Ok |
80 |
Correct |
671 ms |
26860 KB |
Ok |
81 |
Correct |
1066 ms |
26380 KB |
Ok |
82 |
Correct |
608 ms |
26608 KB |
Ok |
83 |
Correct |
730 ms |
25200 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9720 KB |
Ok |
2 |
Correct |
10 ms |
9720 KB |
Ok |
3 |
Correct |
9 ms |
9720 KB |
Ok |
4 |
Correct |
10 ms |
9720 KB |
Ok |
5 |
Correct |
10 ms |
9724 KB |
Ok |
6 |
Correct |
10 ms |
9720 KB |
Ok |
7 |
Correct |
10 ms |
9720 KB |
Ok |
8 |
Correct |
9 ms |
9720 KB |
Ok |
9 |
Correct |
10 ms |
9720 KB |
Ok |
10 |
Correct |
10 ms |
9720 KB |
Ok |
11 |
Correct |
12 ms |
9848 KB |
Ok |
12 |
Correct |
11 ms |
9848 KB |
Ok |
13 |
Correct |
9 ms |
9720 KB |
Ok |
14 |
Correct |
9 ms |
9720 KB |
Ok |
15 |
Correct |
10 ms |
9780 KB |
Ok |
16 |
Correct |
9 ms |
9720 KB |
Ok |
17 |
Correct |
9 ms |
9720 KB |
Ok |
18 |
Correct |
13 ms |
9976 KB |
Ok |
19 |
Correct |
25 ms |
11128 KB |
Ok |
20 |
Correct |
17 ms |
10360 KB |
Ok |
21 |
Correct |
25 ms |
11384 KB |
Ok |
22 |
Correct |
20 ms |
10616 KB |
Ok |
23 |
Correct |
10 ms |
9768 KB |
Ok |
24 |
Correct |
9 ms |
9720 KB |
Ok |
25 |
Correct |
9 ms |
9720 KB |
Ok |
26 |
Correct |
10 ms |
9720 KB |
Ok |
27 |
Correct |
10 ms |
9720 KB |
Ok |
28 |
Correct |
10 ms |
9720 KB |
Ok |
29 |
Correct |
9 ms |
9720 KB |
Ok |
30 |
Correct |
9 ms |
9724 KB |
Ok |
31 |
Correct |
10 ms |
9720 KB |
Ok |
32 |
Correct |
11 ms |
9692 KB |
Ok |
33 |
Correct |
9 ms |
9720 KB |
Ok |
34 |
Correct |
9 ms |
9692 KB |
Ok |
35 |
Correct |
9 ms |
9720 KB |
Ok |
36 |
Correct |
9 ms |
9720 KB |
Ok |
37 |
Correct |
10 ms |
9720 KB |
Ok |
38 |
Correct |
10 ms |
9720 KB |
Ok |
39 |
Correct |
272 ms |
28668 KB |
Ok |
40 |
Correct |
263 ms |
29420 KB |
Ok |
41 |
Correct |
484 ms |
33824 KB |
Ok |
42 |
Correct |
332 ms |
31080 KB |
Ok |
43 |
Correct |
183 ms |
20592 KB |
Ok |
44 |
Correct |
354 ms |
31692 KB |
Ok |
45 |
Correct |
11 ms |
9848 KB |
Ok |
46 |
Correct |
12 ms |
9976 KB |
Ok |
47 |
Correct |
13 ms |
9848 KB |
Ok |
48 |
Correct |
13 ms |
9976 KB |
Ok |
49 |
Correct |
13 ms |
9848 KB |
Ok |
50 |
Correct |
11 ms |
9868 KB |
Ok |
51 |
Correct |
12 ms |
9848 KB |
Ok |
52 |
Correct |
13 ms |
9976 KB |
Ok |
53 |
Correct |
13 ms |
9844 KB |
Ok |
54 |
Correct |
12 ms |
9848 KB |
Ok |
55 |
Correct |
20 ms |
10360 KB |
Ok |
56 |
Correct |
21 ms |
10312 KB |
Ok |
57 |
Correct |
20 ms |
10360 KB |
Ok |
58 |
Correct |
18 ms |
10332 KB |
Ok |
59 |
Correct |
18 ms |
10232 KB |
Ok |
60 |
Correct |
18 ms |
10232 KB |
Ok |
61 |
Correct |
20 ms |
10232 KB |
Ok |
62 |
Correct |
18 ms |
10360 KB |
Ok |
63 |
Correct |
19 ms |
10232 KB |
Ok |
64 |
Correct |
18 ms |
10232 KB |
Ok |
65 |
Correct |
244 ms |
15272 KB |
Ok |
66 |
Correct |
312 ms |
15600 KB |
Ok |
67 |
Correct |
292 ms |
15708 KB |
Ok |
68 |
Correct |
169 ms |
14580 KB |
Ok |
69 |
Correct |
222 ms |
15088 KB |
Ok |
70 |
Correct |
184 ms |
14804 KB |
Ok |
71 |
Correct |
146 ms |
14448 KB |
Ok |
72 |
Correct |
186 ms |
14832 KB |
Ok |
73 |
Correct |
262 ms |
15220 KB |
Ok |
74 |
Correct |
197 ms |
14832 KB |
Ok |
75 |
Correct |
290 ms |
15604 KB |
Ok |
76 |
Correct |
234 ms |
15392 KB |
Ok |
77 |
Correct |
210 ms |
15088 KB |
Ok |
78 |
Correct |
176 ms |
14832 KB |
Ok |
79 |
Correct |
223 ms |
15092 KB |
Ok |
80 |
Correct |
735 ms |
25780 KB |
Ok |
81 |
Correct |
563 ms |
27120 KB |
Ok |
82 |
Correct |
634 ms |
26576 KB |
Ok |
83 |
Correct |
640 ms |
25856 KB |
Ok |
84 |
Correct |
511 ms |
26480 KB |
Ok |
85 |
Correct |
626 ms |
25840 KB |
Ok |
86 |
Correct |
661 ms |
25036 KB |
Ok |
87 |
Correct |
636 ms |
26480 KB |
Ok |
88 |
Correct |
626 ms |
25076 KB |
Ok |
89 |
Correct |
621 ms |
26216 KB |
Ok |
90 |
Correct |
735 ms |
26608 KB |
Ok |
91 |
Correct |
671 ms |
26860 KB |
Ok |
92 |
Correct |
1066 ms |
26380 KB |
Ok |
93 |
Correct |
608 ms |
26608 KB |
Ok |
94 |
Correct |
730 ms |
25200 KB |
Ok |
95 |
Correct |
617 ms |
24176 KB |
Ok |
96 |
Correct |
1659 ms |
30184 KB |
Ok |
97 |
Correct |
1096 ms |
27844 KB |
Ok |
98 |
Correct |
598 ms |
26600 KB |
Ok |
99 |
Correct |
1022 ms |
27620 KB |
Ok |
100 |
Correct |
888 ms |
25828 KB |
Ok |
101 |
Correct |
1261 ms |
28412 KB |
Ok |
102 |
Correct |
1193 ms |
27272 KB |
Ok |
103 |
Correct |
951 ms |
27976 KB |
Ok |
104 |
Correct |
1499 ms |
29748 KB |
Ok |
105 |
Correct |
1382 ms |
29792 KB |
Ok |
106 |
Correct |
1356 ms |
30428 KB |
Ok |
107 |
Correct |
1117 ms |
29028 KB |
Ok |
108 |
Correct |
1459 ms |
29756 KB |
Ok |
109 |
Correct |
1572 ms |
31208 KB |
Ok |
110 |
Execution timed out |
2073 ms |
40936 KB |
Time limit exceeded |
111 |
Halted |
0 ms |
0 KB |
- |