#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) {
return n + m - __gcd(n, m) - 1;
}
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:110:15: warning: unused variable 'j' [-Wunused-variable]
int t, i, j;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
9720 KB |
Ok |
2 |
Correct |
10 ms |
9720 KB |
Ok |
3 |
Correct |
10 ms |
9720 KB |
Ok |
4 |
Correct |
10 ms |
9720 KB |
Ok |
5 |
Correct |
9 ms |
9592 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 |
9 ms |
9720 KB |
Ok |
10 |
Correct |
9 ms |
9720 KB |
Ok |
11 |
Correct |
10 ms |
9720 KB |
Ok |
12 |
Correct |
10 ms |
9720 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
9720 KB |
Ok |
2 |
Correct |
10 ms |
9720 KB |
Ok |
3 |
Correct |
10 ms |
9720 KB |
Ok |
4 |
Correct |
10 ms |
9720 KB |
Ok |
5 |
Correct |
10 ms |
9720 KB |
Ok |
6 |
Correct |
10 ms |
9980 KB |
Ok |
7 |
Correct |
16 ms |
10872 KB |
Ok |
8 |
Correct |
12 ms |
10232 KB |
Ok |
9 |
Correct |
19 ms |
11128 KB |
Ok |
10 |
Correct |
15 ms |
10488 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
9720 KB |
Ok |
2 |
Correct |
10 ms |
9720 KB |
Ok |
3 |
Correct |
10 ms |
9748 KB |
Ok |
4 |
Correct |
9 ms |
9720 KB |
Ok |
5 |
Correct |
10 ms |
9720 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 |
9 ms |
9724 KB |
Ok |
11 |
Correct |
10 ms |
9720 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
9720 KB |
Ok |
2 |
Correct |
10 ms |
9720 KB |
Ok |
3 |
Correct |
10 ms |
9848 KB |
Ok |
4 |
Correct |
9 ms |
9720 KB |
Ok |
5 |
Correct |
10 ms |
9724 KB |
Ok |
6 |
Correct |
102 ms |
24300 KB |
Ok |
7 |
Correct |
88 ms |
29288 KB |
Ok |
8 |
Correct |
169 ms |
33772 KB |
Ok |
9 |
Correct |
126 ms |
31084 KB |
Ok |
10 |
Correct |
74 ms |
19952 KB |
Ok |
11 |
Correct |
107 ms |
26860 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
9720 KB |
Ok |
2 |
Correct |
10 ms |
9720 KB |
Ok |
3 |
Correct |
10 ms |
9720 KB |
Ok |
4 |
Correct |
10 ms |
9720 KB |
Ok |
5 |
Correct |
9 ms |
9592 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 |
9 ms |
9720 KB |
Ok |
10 |
Correct |
9 ms |
9720 KB |
Ok |
11 |
Correct |
10 ms |
9720 KB |
Ok |
12 |
Correct |
10 ms |
9720 KB |
Ok |
13 |
Correct |
10 ms |
9720 KB |
Ok |
14 |
Correct |
10 ms |
9720 KB |
Ok |
15 |
Correct |
10 ms |
9748 KB |
Ok |
16 |
Correct |
9 ms |
9720 KB |
Ok |
17 |
Correct |
10 ms |
9720 KB |
Ok |
18 |
Correct |
10 ms |
9720 KB |
Ok |
19 |
Correct |
10 ms |
9720 KB |
Ok |
20 |
Correct |
9 ms |
9720 KB |
Ok |
21 |
Correct |
10 ms |
9720 KB |
Ok |
22 |
Correct |
9 ms |
9724 KB |
Ok |
23 |
Correct |
10 ms |
9720 KB |
Ok |
24 |
Correct |
11 ms |
9976 KB |
Ok |
25 |
Correct |
11 ms |
9956 KB |
Ok |
26 |
Correct |
13 ms |
9948 KB |
Ok |
27 |
Correct |
11 ms |
9848 KB |
Ok |
28 |
Correct |
12 ms |
9848 KB |
Ok |
29 |
Correct |
12 ms |
9848 KB |
Ok |
30 |
Correct |
12 ms |
9848 KB |
Ok |
31 |
Correct |
11 ms |
9848 KB |
Ok |
32 |
Correct |
11 ms |
9848 KB |
Ok |
33 |
Correct |
11 ms |
9848 KB |
Ok |
34 |
Correct |
13 ms |
10104 KB |
Ok |
35 |
Correct |
13 ms |
10232 KB |
Ok |
36 |
Correct |
14 ms |
10360 KB |
Ok |
37 |
Correct |
13 ms |
10232 KB |
Ok |
38 |
Correct |
15 ms |
10232 KB |
Ok |
39 |
Correct |
14 ms |
10104 KB |
Ok |
40 |
Correct |
15 ms |
10232 KB |
Ok |
41 |
Correct |
14 ms |
10232 KB |
Ok |
42 |
Correct |
14 ms |
10232 KB |
Ok |
43 |
Correct |
15 ms |
10360 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
9720 KB |
Ok |
2 |
Correct |
10 ms |
9720 KB |
Ok |
3 |
Correct |
10 ms |
9720 KB |
Ok |
4 |
Correct |
10 ms |
9720 KB |
Ok |
5 |
Correct |
9 ms |
9592 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 |
9 ms |
9720 KB |
Ok |
10 |
Correct |
9 ms |
9720 KB |
Ok |
11 |
Correct |
10 ms |
9720 KB |
Ok |
12 |
Correct |
10 ms |
9720 KB |
Ok |
13 |
Correct |
10 ms |
9720 KB |
Ok |
14 |
Correct |
10 ms |
9720 KB |
Ok |
15 |
Correct |
10 ms |
9720 KB |
Ok |
16 |
Correct |
10 ms |
9720 KB |
Ok |
17 |
Correct |
10 ms |
9720 KB |
Ok |
18 |
Correct |
10 ms |
9980 KB |
Ok |
19 |
Correct |
16 ms |
10872 KB |
Ok |
20 |
Correct |
12 ms |
10232 KB |
Ok |
21 |
Correct |
19 ms |
11128 KB |
Ok |
22 |
Correct |
15 ms |
10488 KB |
Ok |
23 |
Correct |
10 ms |
9720 KB |
Ok |
24 |
Correct |
10 ms |
9720 KB |
Ok |
25 |
Correct |
10 ms |
9748 KB |
Ok |
26 |
Correct |
9 ms |
9720 KB |
Ok |
27 |
Correct |
10 ms |
9720 KB |
Ok |
28 |
Correct |
10 ms |
9720 KB |
Ok |
29 |
Correct |
10 ms |
9720 KB |
Ok |
30 |
Correct |
9 ms |
9720 KB |
Ok |
31 |
Correct |
10 ms |
9720 KB |
Ok |
32 |
Correct |
9 ms |
9724 KB |
Ok |
33 |
Correct |
10 ms |
9720 KB |
Ok |
34 |
Correct |
11 ms |
9976 KB |
Ok |
35 |
Correct |
11 ms |
9956 KB |
Ok |
36 |
Correct |
13 ms |
9948 KB |
Ok |
37 |
Correct |
11 ms |
9848 KB |
Ok |
38 |
Correct |
12 ms |
9848 KB |
Ok |
39 |
Correct |
12 ms |
9848 KB |
Ok |
40 |
Correct |
12 ms |
9848 KB |
Ok |
41 |
Correct |
11 ms |
9848 KB |
Ok |
42 |
Correct |
11 ms |
9848 KB |
Ok |
43 |
Correct |
11 ms |
9848 KB |
Ok |
44 |
Correct |
13 ms |
10104 KB |
Ok |
45 |
Correct |
13 ms |
10232 KB |
Ok |
46 |
Correct |
14 ms |
10360 KB |
Ok |
47 |
Correct |
13 ms |
10232 KB |
Ok |
48 |
Correct |
15 ms |
10232 KB |
Ok |
49 |
Correct |
14 ms |
10104 KB |
Ok |
50 |
Correct |
15 ms |
10232 KB |
Ok |
51 |
Correct |
14 ms |
10232 KB |
Ok |
52 |
Correct |
14 ms |
10232 KB |
Ok |
53 |
Correct |
15 ms |
10360 KB |
Ok |
54 |
Correct |
84 ms |
15260 KB |
Ok |
55 |
Correct |
91 ms |
15392 KB |
Ok |
56 |
Correct |
84 ms |
15600 KB |
Ok |
57 |
Correct |
61 ms |
14580 KB |
Ok |
58 |
Correct |
72 ms |
14964 KB |
Ok |
59 |
Correct |
65 ms |
14604 KB |
Ok |
60 |
Correct |
61 ms |
14384 KB |
Ok |
61 |
Correct |
64 ms |
14836 KB |
Ok |
62 |
Correct |
79 ms |
15200 KB |
Ok |
63 |
Correct |
69 ms |
14748 KB |
Ok |
64 |
Correct |
85 ms |
15456 KB |
Ok |
65 |
Correct |
78 ms |
15088 KB |
Ok |
66 |
Correct |
65 ms |
15048 KB |
Ok |
67 |
Correct |
59 ms |
14900 KB |
Ok |
68 |
Correct |
65 ms |
14956 KB |
Ok |
69 |
Correct |
208 ms |
25520 KB |
Ok |
70 |
Correct |
278 ms |
26992 KB |
Ok |
71 |
Correct |
204 ms |
26224 KB |
Ok |
72 |
Correct |
206 ms |
25712 KB |
Ok |
73 |
Correct |
228 ms |
25580 KB |
Ok |
74 |
Correct |
187 ms |
24788 KB |
Ok |
75 |
Correct |
202 ms |
24692 KB |
Ok |
76 |
Correct |
208 ms |
26252 KB |
Ok |
77 |
Correct |
204 ms |
24044 KB |
Ok |
78 |
Correct |
192 ms |
24968 KB |
Ok |
79 |
Correct |
193 ms |
25968 KB |
Ok |
80 |
Correct |
192 ms |
26352 KB |
Ok |
81 |
Correct |
215 ms |
25200 KB |
Ok |
82 |
Correct |
198 ms |
25940 KB |
Ok |
83 |
Correct |
182 ms |
24560 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
9720 KB |
Ok |
2 |
Correct |
10 ms |
9720 KB |
Ok |
3 |
Correct |
10 ms |
9720 KB |
Ok |
4 |
Correct |
10 ms |
9720 KB |
Ok |
5 |
Correct |
9 ms |
9592 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 |
9 ms |
9720 KB |
Ok |
10 |
Correct |
9 ms |
9720 KB |
Ok |
11 |
Correct |
10 ms |
9720 KB |
Ok |
12 |
Correct |
10 ms |
9720 KB |
Ok |
13 |
Correct |
10 ms |
9720 KB |
Ok |
14 |
Correct |
10 ms |
9720 KB |
Ok |
15 |
Correct |
10 ms |
9720 KB |
Ok |
16 |
Correct |
10 ms |
9720 KB |
Ok |
17 |
Correct |
10 ms |
9720 KB |
Ok |
18 |
Correct |
10 ms |
9980 KB |
Ok |
19 |
Correct |
16 ms |
10872 KB |
Ok |
20 |
Correct |
12 ms |
10232 KB |
Ok |
21 |
Correct |
19 ms |
11128 KB |
Ok |
22 |
Correct |
15 ms |
10488 KB |
Ok |
23 |
Correct |
10 ms |
9720 KB |
Ok |
24 |
Correct |
10 ms |
9720 KB |
Ok |
25 |
Correct |
10 ms |
9748 KB |
Ok |
26 |
Correct |
9 ms |
9720 KB |
Ok |
27 |
Correct |
10 ms |
9720 KB |
Ok |
28 |
Correct |
10 ms |
9720 KB |
Ok |
29 |
Correct |
10 ms |
9720 KB |
Ok |
30 |
Correct |
9 ms |
9720 KB |
Ok |
31 |
Correct |
10 ms |
9720 KB |
Ok |
32 |
Correct |
9 ms |
9724 KB |
Ok |
33 |
Correct |
10 ms |
9720 KB |
Ok |
34 |
Correct |
10 ms |
9720 KB |
Ok |
35 |
Correct |
10 ms |
9720 KB |
Ok |
36 |
Correct |
10 ms |
9848 KB |
Ok |
37 |
Correct |
9 ms |
9720 KB |
Ok |
38 |
Correct |
10 ms |
9724 KB |
Ok |
39 |
Correct |
102 ms |
24300 KB |
Ok |
40 |
Correct |
88 ms |
29288 KB |
Ok |
41 |
Correct |
169 ms |
33772 KB |
Ok |
42 |
Correct |
126 ms |
31084 KB |
Ok |
43 |
Correct |
74 ms |
19952 KB |
Ok |
44 |
Correct |
107 ms |
26860 KB |
Ok |
45 |
Correct |
11 ms |
9976 KB |
Ok |
46 |
Correct |
11 ms |
9956 KB |
Ok |
47 |
Correct |
13 ms |
9948 KB |
Ok |
48 |
Correct |
11 ms |
9848 KB |
Ok |
49 |
Correct |
12 ms |
9848 KB |
Ok |
50 |
Correct |
12 ms |
9848 KB |
Ok |
51 |
Correct |
12 ms |
9848 KB |
Ok |
52 |
Correct |
11 ms |
9848 KB |
Ok |
53 |
Correct |
11 ms |
9848 KB |
Ok |
54 |
Correct |
11 ms |
9848 KB |
Ok |
55 |
Correct |
13 ms |
10104 KB |
Ok |
56 |
Correct |
13 ms |
10232 KB |
Ok |
57 |
Correct |
14 ms |
10360 KB |
Ok |
58 |
Correct |
13 ms |
10232 KB |
Ok |
59 |
Correct |
15 ms |
10232 KB |
Ok |
60 |
Correct |
14 ms |
10104 KB |
Ok |
61 |
Correct |
15 ms |
10232 KB |
Ok |
62 |
Correct |
14 ms |
10232 KB |
Ok |
63 |
Correct |
14 ms |
10232 KB |
Ok |
64 |
Correct |
15 ms |
10360 KB |
Ok |
65 |
Correct |
84 ms |
15260 KB |
Ok |
66 |
Correct |
91 ms |
15392 KB |
Ok |
67 |
Correct |
84 ms |
15600 KB |
Ok |
68 |
Correct |
61 ms |
14580 KB |
Ok |
69 |
Correct |
72 ms |
14964 KB |
Ok |
70 |
Correct |
65 ms |
14604 KB |
Ok |
71 |
Correct |
61 ms |
14384 KB |
Ok |
72 |
Correct |
64 ms |
14836 KB |
Ok |
73 |
Correct |
79 ms |
15200 KB |
Ok |
74 |
Correct |
69 ms |
14748 KB |
Ok |
75 |
Correct |
85 ms |
15456 KB |
Ok |
76 |
Correct |
78 ms |
15088 KB |
Ok |
77 |
Correct |
65 ms |
15048 KB |
Ok |
78 |
Correct |
59 ms |
14900 KB |
Ok |
79 |
Correct |
65 ms |
14956 KB |
Ok |
80 |
Correct |
208 ms |
25520 KB |
Ok |
81 |
Correct |
278 ms |
26992 KB |
Ok |
82 |
Correct |
204 ms |
26224 KB |
Ok |
83 |
Correct |
206 ms |
25712 KB |
Ok |
84 |
Correct |
228 ms |
25580 KB |
Ok |
85 |
Correct |
187 ms |
24788 KB |
Ok |
86 |
Correct |
202 ms |
24692 KB |
Ok |
87 |
Correct |
208 ms |
26252 KB |
Ok |
88 |
Correct |
204 ms |
24044 KB |
Ok |
89 |
Correct |
192 ms |
24968 KB |
Ok |
90 |
Correct |
193 ms |
25968 KB |
Ok |
91 |
Correct |
192 ms |
26352 KB |
Ok |
92 |
Correct |
215 ms |
25200 KB |
Ok |
93 |
Correct |
198 ms |
25940 KB |
Ok |
94 |
Correct |
182 ms |
24560 KB |
Ok |
95 |
Correct |
185 ms |
23884 KB |
Ok |
96 |
Correct |
323 ms |
30044 KB |
Ok |
97 |
Correct |
237 ms |
26212 KB |
Ok |
98 |
Correct |
186 ms |
26468 KB |
Ok |
99 |
Correct |
223 ms |
26212 KB |
Ok |
100 |
Correct |
256 ms |
25320 KB |
Ok |
101 |
Correct |
254 ms |
28264 KB |
Ok |
102 |
Correct |
248 ms |
26856 KB |
Ok |
103 |
Correct |
242 ms |
27472 KB |
Ok |
104 |
Correct |
334 ms |
29288 KB |
Ok |
105 |
Correct |
351 ms |
29412 KB |
Ok |
106 |
Correct |
310 ms |
30316 KB |
Ok |
107 |
Correct |
323 ms |
28948 KB |
Ok |
108 |
Correct |
346 ms |
29544 KB |
Ok |
109 |
Correct |
298 ms |
31204 KB |
Ok |
110 |
Correct |
1254 ms |
71968 KB |
Ok |
111 |
Correct |
1504 ms |
76140 KB |
Ok |
112 |
Correct |
1356 ms |
72808 KB |
Ok |
113 |
Correct |
1282 ms |
74852 KB |
Ok |
114 |
Correct |
1447 ms |
76920 KB |
Ok |
115 |
Correct |
1720 ms |
72608 KB |
Ok |
116 |
Correct |
1147 ms |
77196 KB |
Ok |
117 |
Correct |
1192 ms |
73344 KB |
Ok |
118 |
Correct |
1302 ms |
75092 KB |
Ok |
119 |
Correct |
1653 ms |
73032 KB |
Ok |
120 |
Correct |
1676 ms |
72708 KB |
Ok |
121 |
Correct |
1495 ms |
72332 KB |
Ok |
122 |
Correct |
1284 ms |
74376 KB |
Ok |
123 |
Correct |
1797 ms |
75800 KB |
Ok |
124 |
Correct |
1563 ms |
68328 KB |
Ok |
125 |
Correct |
425 ms |
54588 KB |
Ok |