#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 |
9 ms |
9720 KB |
Ok |
2 |
Correct |
10 ms |
9720 KB |
Ok |
3 |
Correct |
10 ms |
9788 KB |
Ok |
4 |
Correct |
10 ms |
9720 KB |
Ok |
5 |
Correct |
10 ms |
9720 KB |
Ok |
6 |
Correct |
11 ms |
9720 KB |
Ok |
7 |
Correct |
10 ms |
9592 KB |
Ok |
8 |
Correct |
9 ms |
9720 KB |
Ok |
9 |
Correct |
10 ms |
9720 KB |
Ok |
10 |
Correct |
11 ms |
9720 KB |
Ok |
11 |
Correct |
10 ms |
9720 KB |
Ok |
12 |
Correct |
10 ms |
9720 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
9720 KB |
Ok |
2 |
Correct |
11 ms |
9720 KB |
Ok |
3 |
Correct |
10 ms |
9676 KB |
Ok |
4 |
Correct |
10 ms |
9720 KB |
Ok |
5 |
Correct |
10 ms |
9724 KB |
Ok |
6 |
Correct |
13 ms |
9976 KB |
Ok |
7 |
Correct |
24 ms |
11100 KB |
Ok |
8 |
Correct |
18 ms |
10332 KB |
Ok |
9 |
Correct |
26 ms |
11384 KB |
Ok |
10 |
Correct |
20 ms |
10616 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
9720 KB |
Ok |
2 |
Correct |
10 ms |
9720 KB |
Ok |
3 |
Correct |
10 ms |
9724 KB |
Ok |
4 |
Correct |
10 ms |
9816 KB |
Ok |
5 |
Correct |
9 ms |
9720 KB |
Ok |
6 |
Correct |
10 ms |
9692 KB |
Ok |
7 |
Correct |
9 ms |
9720 KB |
Ok |
8 |
Correct |
10 ms |
9720 KB |
Ok |
9 |
Correct |
9 ms |
9720 KB |
Ok |
10 |
Correct |
11 ms |
9720 KB |
Ok |
11 |
Correct |
10 ms |
9720 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
9720 KB |
Ok |
2 |
Correct |
10 ms |
9720 KB |
Ok |
3 |
Correct |
10 ms |
9692 KB |
Ok |
4 |
Correct |
10 ms |
9724 KB |
Ok |
5 |
Correct |
8 ms |
9720 KB |
Ok |
6 |
Correct |
279 ms |
28716 KB |
Ok |
7 |
Correct |
261 ms |
29504 KB |
Ok |
8 |
Correct |
481 ms |
33768 KB |
Ok |
9 |
Correct |
343 ms |
31080 KB |
Ok |
10 |
Correct |
181 ms |
20748 KB |
Ok |
11 |
Correct |
346 ms |
31724 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
9720 KB |
Ok |
2 |
Correct |
10 ms |
9720 KB |
Ok |
3 |
Correct |
10 ms |
9788 KB |
Ok |
4 |
Correct |
10 ms |
9720 KB |
Ok |
5 |
Correct |
10 ms |
9720 KB |
Ok |
6 |
Correct |
11 ms |
9720 KB |
Ok |
7 |
Correct |
10 ms |
9592 KB |
Ok |
8 |
Correct |
9 ms |
9720 KB |
Ok |
9 |
Correct |
10 ms |
9720 KB |
Ok |
10 |
Correct |
11 ms |
9720 KB |
Ok |
11 |
Correct |
10 ms |
9720 KB |
Ok |
12 |
Correct |
10 ms |
9720 KB |
Ok |
13 |
Correct |
9 ms |
9720 KB |
Ok |
14 |
Correct |
10 ms |
9720 KB |
Ok |
15 |
Correct |
10 ms |
9724 KB |
Ok |
16 |
Correct |
10 ms |
9816 KB |
Ok |
17 |
Correct |
9 ms |
9720 KB |
Ok |
18 |
Correct |
10 ms |
9692 KB |
Ok |
19 |
Correct |
9 ms |
9720 KB |
Ok |
20 |
Correct |
10 ms |
9720 KB |
Ok |
21 |
Correct |
9 ms |
9720 KB |
Ok |
22 |
Correct |
11 ms |
9720 KB |
Ok |
23 |
Correct |
10 ms |
9720 KB |
Ok |
24 |
Correct |
12 ms |
9976 KB |
Ok |
25 |
Correct |
13 ms |
9848 KB |
Ok |
26 |
Correct |
11 ms |
9848 KB |
Ok |
27 |
Correct |
11 ms |
9976 KB |
Ok |
28 |
Correct |
11 ms |
9848 KB |
Ok |
29 |
Correct |
10 ms |
9848 KB |
Ok |
30 |
Correct |
13 ms |
9848 KB |
Ok |
31 |
Correct |
14 ms |
9848 KB |
Ok |
32 |
Correct |
12 ms |
9848 KB |
Ok |
33 |
Correct |
12 ms |
9976 KB |
Ok |
34 |
Correct |
20 ms |
10360 KB |
Ok |
35 |
Correct |
19 ms |
10364 KB |
Ok |
36 |
Correct |
19 ms |
10360 KB |
Ok |
37 |
Correct |
21 ms |
10360 KB |
Ok |
38 |
Correct |
19 ms |
10360 KB |
Ok |
39 |
Correct |
21 ms |
10232 KB |
Ok |
40 |
Correct |
22 ms |
10232 KB |
Ok |
41 |
Correct |
20 ms |
10360 KB |
Ok |
42 |
Correct |
20 ms |
10332 KB |
Ok |
43 |
Correct |
20 ms |
10360 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
9720 KB |
Ok |
2 |
Correct |
10 ms |
9720 KB |
Ok |
3 |
Correct |
10 ms |
9788 KB |
Ok |
4 |
Correct |
10 ms |
9720 KB |
Ok |
5 |
Correct |
10 ms |
9720 KB |
Ok |
6 |
Correct |
11 ms |
9720 KB |
Ok |
7 |
Correct |
10 ms |
9592 KB |
Ok |
8 |
Correct |
9 ms |
9720 KB |
Ok |
9 |
Correct |
10 ms |
9720 KB |
Ok |
10 |
Correct |
11 ms |
9720 KB |
Ok |
11 |
Correct |
10 ms |
9720 KB |
Ok |
12 |
Correct |
10 ms |
9720 KB |
Ok |
13 |
Correct |
11 ms |
9720 KB |
Ok |
14 |
Correct |
11 ms |
9720 KB |
Ok |
15 |
Correct |
10 ms |
9676 KB |
Ok |
16 |
Correct |
10 ms |
9720 KB |
Ok |
17 |
Correct |
10 ms |
9724 KB |
Ok |
18 |
Correct |
13 ms |
9976 KB |
Ok |
19 |
Correct |
24 ms |
11100 KB |
Ok |
20 |
Correct |
18 ms |
10332 KB |
Ok |
21 |
Correct |
26 ms |
11384 KB |
Ok |
22 |
Correct |
20 ms |
10616 KB |
Ok |
23 |
Correct |
9 ms |
9720 KB |
Ok |
24 |
Correct |
10 ms |
9720 KB |
Ok |
25 |
Correct |
10 ms |
9724 KB |
Ok |
26 |
Correct |
10 ms |
9816 KB |
Ok |
27 |
Correct |
9 ms |
9720 KB |
Ok |
28 |
Correct |
10 ms |
9692 KB |
Ok |
29 |
Correct |
9 ms |
9720 KB |
Ok |
30 |
Correct |
10 ms |
9720 KB |
Ok |
31 |
Correct |
9 ms |
9720 KB |
Ok |
32 |
Correct |
11 ms |
9720 KB |
Ok |
33 |
Correct |
10 ms |
9720 KB |
Ok |
34 |
Correct |
12 ms |
9976 KB |
Ok |
35 |
Correct |
13 ms |
9848 KB |
Ok |
36 |
Correct |
11 ms |
9848 KB |
Ok |
37 |
Correct |
11 ms |
9976 KB |
Ok |
38 |
Correct |
11 ms |
9848 KB |
Ok |
39 |
Correct |
10 ms |
9848 KB |
Ok |
40 |
Correct |
13 ms |
9848 KB |
Ok |
41 |
Correct |
14 ms |
9848 KB |
Ok |
42 |
Correct |
12 ms |
9848 KB |
Ok |
43 |
Correct |
12 ms |
9976 KB |
Ok |
44 |
Correct |
20 ms |
10360 KB |
Ok |
45 |
Correct |
19 ms |
10364 KB |
Ok |
46 |
Correct |
19 ms |
10360 KB |
Ok |
47 |
Correct |
21 ms |
10360 KB |
Ok |
48 |
Correct |
19 ms |
10360 KB |
Ok |
49 |
Correct |
21 ms |
10232 KB |
Ok |
50 |
Correct |
22 ms |
10232 KB |
Ok |
51 |
Correct |
20 ms |
10360 KB |
Ok |
52 |
Correct |
20 ms |
10332 KB |
Ok |
53 |
Correct |
20 ms |
10360 KB |
Ok |
54 |
Correct |
262 ms |
15220 KB |
Ok |
55 |
Correct |
317 ms |
15664 KB |
Ok |
56 |
Correct |
302 ms |
15640 KB |
Ok |
57 |
Correct |
172 ms |
14832 KB |
Ok |
58 |
Correct |
215 ms |
15220 KB |
Ok |
59 |
Correct |
177 ms |
14832 KB |
Ok |
60 |
Correct |
148 ms |
14492 KB |
Ok |
61 |
Correct |
190 ms |
14960 KB |
Ok |
62 |
Correct |
264 ms |
15220 KB |
Ok |
63 |
Correct |
188 ms |
14832 KB |
Ok |
64 |
Correct |
287 ms |
15472 KB |
Ok |
65 |
Correct |
224 ms |
15220 KB |
Ok |
66 |
Correct |
208 ms |
15088 KB |
Ok |
67 |
Correct |
177 ms |
15048 KB |
Ok |
68 |
Correct |
210 ms |
15092 KB |
Ok |
69 |
Correct |
712 ms |
25712 KB |
Ok |
70 |
Correct |
632 ms |
27356 KB |
Ok |
71 |
Correct |
680 ms |
26620 KB |
Ok |
72 |
Correct |
671 ms |
25716 KB |
Ok |
73 |
Correct |
556 ms |
26480 KB |
Ok |
74 |
Correct |
625 ms |
25884 KB |
Ok |
75 |
Correct |
715 ms |
25328 KB |
Ok |
76 |
Correct |
673 ms |
26748 KB |
Ok |
77 |
Correct |
646 ms |
25328 KB |
Ok |
78 |
Correct |
646 ms |
26476 KB |
Ok |
79 |
Correct |
737 ms |
26604 KB |
Ok |
80 |
Correct |
658 ms |
26952 KB |
Ok |
81 |
Correct |
710 ms |
26224 KB |
Ok |
82 |
Correct |
618 ms |
26656 KB |
Ok |
83 |
Correct |
763 ms |
25200 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
9720 KB |
Ok |
2 |
Correct |
10 ms |
9720 KB |
Ok |
3 |
Correct |
10 ms |
9788 KB |
Ok |
4 |
Correct |
10 ms |
9720 KB |
Ok |
5 |
Correct |
10 ms |
9720 KB |
Ok |
6 |
Correct |
11 ms |
9720 KB |
Ok |
7 |
Correct |
10 ms |
9592 KB |
Ok |
8 |
Correct |
9 ms |
9720 KB |
Ok |
9 |
Correct |
10 ms |
9720 KB |
Ok |
10 |
Correct |
11 ms |
9720 KB |
Ok |
11 |
Correct |
10 ms |
9720 KB |
Ok |
12 |
Correct |
10 ms |
9720 KB |
Ok |
13 |
Correct |
11 ms |
9720 KB |
Ok |
14 |
Correct |
11 ms |
9720 KB |
Ok |
15 |
Correct |
10 ms |
9676 KB |
Ok |
16 |
Correct |
10 ms |
9720 KB |
Ok |
17 |
Correct |
10 ms |
9724 KB |
Ok |
18 |
Correct |
13 ms |
9976 KB |
Ok |
19 |
Correct |
24 ms |
11100 KB |
Ok |
20 |
Correct |
18 ms |
10332 KB |
Ok |
21 |
Correct |
26 ms |
11384 KB |
Ok |
22 |
Correct |
20 ms |
10616 KB |
Ok |
23 |
Correct |
9 ms |
9720 KB |
Ok |
24 |
Correct |
10 ms |
9720 KB |
Ok |
25 |
Correct |
10 ms |
9724 KB |
Ok |
26 |
Correct |
10 ms |
9816 KB |
Ok |
27 |
Correct |
9 ms |
9720 KB |
Ok |
28 |
Correct |
10 ms |
9692 KB |
Ok |
29 |
Correct |
9 ms |
9720 KB |
Ok |
30 |
Correct |
10 ms |
9720 KB |
Ok |
31 |
Correct |
9 ms |
9720 KB |
Ok |
32 |
Correct |
11 ms |
9720 KB |
Ok |
33 |
Correct |
10 ms |
9720 KB |
Ok |
34 |
Correct |
9 ms |
9720 KB |
Ok |
35 |
Correct |
10 ms |
9720 KB |
Ok |
36 |
Correct |
10 ms |
9692 KB |
Ok |
37 |
Correct |
10 ms |
9724 KB |
Ok |
38 |
Correct |
8 ms |
9720 KB |
Ok |
39 |
Correct |
279 ms |
28716 KB |
Ok |
40 |
Correct |
261 ms |
29504 KB |
Ok |
41 |
Correct |
481 ms |
33768 KB |
Ok |
42 |
Correct |
343 ms |
31080 KB |
Ok |
43 |
Correct |
181 ms |
20748 KB |
Ok |
44 |
Correct |
346 ms |
31724 KB |
Ok |
45 |
Correct |
12 ms |
9976 KB |
Ok |
46 |
Correct |
13 ms |
9848 KB |
Ok |
47 |
Correct |
11 ms |
9848 KB |
Ok |
48 |
Correct |
11 ms |
9976 KB |
Ok |
49 |
Correct |
11 ms |
9848 KB |
Ok |
50 |
Correct |
10 ms |
9848 KB |
Ok |
51 |
Correct |
13 ms |
9848 KB |
Ok |
52 |
Correct |
14 ms |
9848 KB |
Ok |
53 |
Correct |
12 ms |
9848 KB |
Ok |
54 |
Correct |
12 ms |
9976 KB |
Ok |
55 |
Correct |
20 ms |
10360 KB |
Ok |
56 |
Correct |
19 ms |
10364 KB |
Ok |
57 |
Correct |
19 ms |
10360 KB |
Ok |
58 |
Correct |
21 ms |
10360 KB |
Ok |
59 |
Correct |
19 ms |
10360 KB |
Ok |
60 |
Correct |
21 ms |
10232 KB |
Ok |
61 |
Correct |
22 ms |
10232 KB |
Ok |
62 |
Correct |
20 ms |
10360 KB |
Ok |
63 |
Correct |
20 ms |
10332 KB |
Ok |
64 |
Correct |
20 ms |
10360 KB |
Ok |
65 |
Correct |
262 ms |
15220 KB |
Ok |
66 |
Correct |
317 ms |
15664 KB |
Ok |
67 |
Correct |
302 ms |
15640 KB |
Ok |
68 |
Correct |
172 ms |
14832 KB |
Ok |
69 |
Correct |
215 ms |
15220 KB |
Ok |
70 |
Correct |
177 ms |
14832 KB |
Ok |
71 |
Correct |
148 ms |
14492 KB |
Ok |
72 |
Correct |
190 ms |
14960 KB |
Ok |
73 |
Correct |
264 ms |
15220 KB |
Ok |
74 |
Correct |
188 ms |
14832 KB |
Ok |
75 |
Correct |
287 ms |
15472 KB |
Ok |
76 |
Correct |
224 ms |
15220 KB |
Ok |
77 |
Correct |
208 ms |
15088 KB |
Ok |
78 |
Correct |
177 ms |
15048 KB |
Ok |
79 |
Correct |
210 ms |
15092 KB |
Ok |
80 |
Correct |
712 ms |
25712 KB |
Ok |
81 |
Correct |
632 ms |
27356 KB |
Ok |
82 |
Correct |
680 ms |
26620 KB |
Ok |
83 |
Correct |
671 ms |
25716 KB |
Ok |
84 |
Correct |
556 ms |
26480 KB |
Ok |
85 |
Correct |
625 ms |
25884 KB |
Ok |
86 |
Correct |
715 ms |
25328 KB |
Ok |
87 |
Correct |
673 ms |
26748 KB |
Ok |
88 |
Correct |
646 ms |
25328 KB |
Ok |
89 |
Correct |
646 ms |
26476 KB |
Ok |
90 |
Correct |
737 ms |
26604 KB |
Ok |
91 |
Correct |
658 ms |
26952 KB |
Ok |
92 |
Correct |
710 ms |
26224 KB |
Ok |
93 |
Correct |
618 ms |
26656 KB |
Ok |
94 |
Correct |
763 ms |
25200 KB |
Ok |
95 |
Correct |
572 ms |
24352 KB |
Ok |
96 |
Correct |
1273 ms |
30440 KB |
Ok |
97 |
Correct |
982 ms |
27920 KB |
Ok |
98 |
Correct |
465 ms |
26728 KB |
Ok |
99 |
Correct |
756 ms |
27720 KB |
Ok |
100 |
Correct |
766 ms |
25828 KB |
Ok |
101 |
Correct |
1069 ms |
28260 KB |
Ok |
102 |
Correct |
854 ms |
27108 KB |
Ok |
103 |
Correct |
914 ms |
28100 KB |
Ok |
104 |
Correct |
1387 ms |
29800 KB |
Ok |
105 |
Correct |
1357 ms |
29800 KB |
Ok |
106 |
Correct |
1269 ms |
30308 KB |
Ok |
107 |
Correct |
1335 ms |
29052 KB |
Ok |
108 |
Correct |
1439 ms |
29760 KB |
Ok |
109 |
Correct |
1473 ms |
31212 KB |
Ok |
110 |
Execution timed out |
2056 ms |
44592 KB |
Time limit exceeded |
111 |
Halted |
0 ms |
0 KB |
- |