#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; i++) {
if(vis[i] == 0) {
dfs(i, ok);
}
}
return ok;
}
inline int get(int n, int m) {
int res = 0;
for(int step = 1 << 17; step; step >>= 1) {
if(res + step <= n + m && check(res + step, n, m)) {
res += step;
}
}
return res;
}
vector <int> aux[2 * MAXN + 1];
vector <int> ord;
int sp[2 * MAXN + 1];
void dfs1(int nod) {
vis[nod] = 1;
for(auto it : aux[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++) {
aux[i].clear();
vis[i] = 0;
if(i - n >= 0) {
aux[i - n].push_back(i);
}
if(i - m >= 0) {
aux[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 : aux[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:117:15: warning: unused variable 'j' [-Wunused-variable]
int t, i, j;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
19192 KB |
Ok |
2 |
Correct |
15 ms |
19192 KB |
Ok |
3 |
Correct |
18 ms |
19064 KB |
Ok |
4 |
Correct |
15 ms |
19064 KB |
Ok |
5 |
Correct |
15 ms |
19192 KB |
Ok |
6 |
Correct |
17 ms |
19320 KB |
Ok |
7 |
Correct |
19 ms |
19192 KB |
Ok |
8 |
Correct |
15 ms |
19064 KB |
Ok |
9 |
Correct |
19 ms |
19192 KB |
Ok |
10 |
Correct |
15 ms |
19192 KB |
Ok |
11 |
Correct |
18 ms |
19064 KB |
Ok |
12 |
Correct |
18 ms |
19192 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
19064 KB |
Ok |
2 |
Correct |
19 ms |
19192 KB |
Ok |
3 |
Correct |
19 ms |
19116 KB |
Ok |
4 |
Correct |
17 ms |
19192 KB |
Ok |
5 |
Correct |
18 ms |
19192 KB |
Ok |
6 |
Correct |
23 ms |
19448 KB |
Ok |
7 |
Correct |
32 ms |
20728 KB |
Ok |
8 |
Correct |
25 ms |
19832 KB |
Ok |
9 |
Correct |
36 ms |
20984 KB |
Ok |
10 |
Correct |
28 ms |
20216 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
19064 KB |
Ok |
2 |
Correct |
19 ms |
19192 KB |
Ok |
3 |
Correct |
19 ms |
19064 KB |
Ok |
4 |
Correct |
18 ms |
19192 KB |
Ok |
5 |
Correct |
18 ms |
19064 KB |
Ok |
6 |
Correct |
18 ms |
19192 KB |
Ok |
7 |
Correct |
18 ms |
19192 KB |
Ok |
8 |
Correct |
18 ms |
19064 KB |
Ok |
9 |
Correct |
18 ms |
19164 KB |
Ok |
10 |
Correct |
18 ms |
19064 KB |
Ok |
11 |
Correct |
19 ms |
19064 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
19064 KB |
Ok |
2 |
Correct |
18 ms |
19064 KB |
Ok |
3 |
Correct |
18 ms |
19192 KB |
Ok |
4 |
Correct |
18 ms |
19064 KB |
Ok |
5 |
Correct |
17 ms |
19192 KB |
Ok |
6 |
Correct |
304 ms |
43372 KB |
Ok |
7 |
Correct |
289 ms |
45168 KB |
Ok |
8 |
Correct |
540 ms |
49396 KB |
Ok |
9 |
Correct |
396 ms |
45804 KB |
Ok |
10 |
Correct |
192 ms |
33708 KB |
Ok |
11 |
Correct |
366 ms |
47336 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
19192 KB |
Ok |
2 |
Correct |
15 ms |
19192 KB |
Ok |
3 |
Correct |
18 ms |
19064 KB |
Ok |
4 |
Correct |
15 ms |
19064 KB |
Ok |
5 |
Correct |
15 ms |
19192 KB |
Ok |
6 |
Correct |
17 ms |
19320 KB |
Ok |
7 |
Correct |
19 ms |
19192 KB |
Ok |
8 |
Correct |
15 ms |
19064 KB |
Ok |
9 |
Correct |
19 ms |
19192 KB |
Ok |
10 |
Correct |
15 ms |
19192 KB |
Ok |
11 |
Correct |
18 ms |
19064 KB |
Ok |
12 |
Correct |
18 ms |
19192 KB |
Ok |
13 |
Correct |
18 ms |
19064 KB |
Ok |
14 |
Correct |
19 ms |
19192 KB |
Ok |
15 |
Correct |
19 ms |
19064 KB |
Ok |
16 |
Correct |
18 ms |
19192 KB |
Ok |
17 |
Correct |
18 ms |
19064 KB |
Ok |
18 |
Correct |
18 ms |
19192 KB |
Ok |
19 |
Correct |
18 ms |
19192 KB |
Ok |
20 |
Correct |
18 ms |
19064 KB |
Ok |
21 |
Correct |
18 ms |
19164 KB |
Ok |
22 |
Correct |
18 ms |
19064 KB |
Ok |
23 |
Correct |
19 ms |
19064 KB |
Ok |
24 |
Correct |
18 ms |
19320 KB |
Ok |
25 |
Correct |
19 ms |
19448 KB |
Ok |
26 |
Correct |
21 ms |
19476 KB |
Ok |
27 |
Correct |
19 ms |
19420 KB |
Ok |
28 |
Correct |
18 ms |
19292 KB |
Ok |
29 |
Correct |
18 ms |
19320 KB |
Ok |
30 |
Correct |
18 ms |
19320 KB |
Ok |
31 |
Correct |
20 ms |
19448 KB |
Ok |
32 |
Correct |
19 ms |
19320 KB |
Ok |
33 |
Correct |
19 ms |
19320 KB |
Ok |
34 |
Correct |
25 ms |
19704 KB |
Ok |
35 |
Correct |
26 ms |
19832 KB |
Ok |
36 |
Correct |
29 ms |
19832 KB |
Ok |
37 |
Correct |
26 ms |
19832 KB |
Ok |
38 |
Correct |
25 ms |
19792 KB |
Ok |
39 |
Correct |
25 ms |
19832 KB |
Ok |
40 |
Correct |
27 ms |
19832 KB |
Ok |
41 |
Correct |
29 ms |
19832 KB |
Ok |
42 |
Correct |
29 ms |
19832 KB |
Ok |
43 |
Correct |
30 ms |
19832 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
19192 KB |
Ok |
2 |
Correct |
15 ms |
19192 KB |
Ok |
3 |
Correct |
18 ms |
19064 KB |
Ok |
4 |
Correct |
15 ms |
19064 KB |
Ok |
5 |
Correct |
15 ms |
19192 KB |
Ok |
6 |
Correct |
17 ms |
19320 KB |
Ok |
7 |
Correct |
19 ms |
19192 KB |
Ok |
8 |
Correct |
15 ms |
19064 KB |
Ok |
9 |
Correct |
19 ms |
19192 KB |
Ok |
10 |
Correct |
15 ms |
19192 KB |
Ok |
11 |
Correct |
18 ms |
19064 KB |
Ok |
12 |
Correct |
18 ms |
19192 KB |
Ok |
13 |
Correct |
18 ms |
19064 KB |
Ok |
14 |
Correct |
19 ms |
19192 KB |
Ok |
15 |
Correct |
19 ms |
19116 KB |
Ok |
16 |
Correct |
17 ms |
19192 KB |
Ok |
17 |
Correct |
18 ms |
19192 KB |
Ok |
18 |
Correct |
23 ms |
19448 KB |
Ok |
19 |
Correct |
32 ms |
20728 KB |
Ok |
20 |
Correct |
25 ms |
19832 KB |
Ok |
21 |
Correct |
36 ms |
20984 KB |
Ok |
22 |
Correct |
28 ms |
20216 KB |
Ok |
23 |
Correct |
18 ms |
19064 KB |
Ok |
24 |
Correct |
19 ms |
19192 KB |
Ok |
25 |
Correct |
19 ms |
19064 KB |
Ok |
26 |
Correct |
18 ms |
19192 KB |
Ok |
27 |
Correct |
18 ms |
19064 KB |
Ok |
28 |
Correct |
18 ms |
19192 KB |
Ok |
29 |
Correct |
18 ms |
19192 KB |
Ok |
30 |
Correct |
18 ms |
19064 KB |
Ok |
31 |
Correct |
18 ms |
19164 KB |
Ok |
32 |
Correct |
18 ms |
19064 KB |
Ok |
33 |
Correct |
19 ms |
19064 KB |
Ok |
34 |
Correct |
18 ms |
19320 KB |
Ok |
35 |
Correct |
19 ms |
19448 KB |
Ok |
36 |
Correct |
21 ms |
19476 KB |
Ok |
37 |
Correct |
19 ms |
19420 KB |
Ok |
38 |
Correct |
18 ms |
19292 KB |
Ok |
39 |
Correct |
18 ms |
19320 KB |
Ok |
40 |
Correct |
18 ms |
19320 KB |
Ok |
41 |
Correct |
20 ms |
19448 KB |
Ok |
42 |
Correct |
19 ms |
19320 KB |
Ok |
43 |
Correct |
19 ms |
19320 KB |
Ok |
44 |
Correct |
25 ms |
19704 KB |
Ok |
45 |
Correct |
26 ms |
19832 KB |
Ok |
46 |
Correct |
29 ms |
19832 KB |
Ok |
47 |
Correct |
26 ms |
19832 KB |
Ok |
48 |
Correct |
25 ms |
19792 KB |
Ok |
49 |
Correct |
25 ms |
19832 KB |
Ok |
50 |
Correct |
27 ms |
19832 KB |
Ok |
51 |
Correct |
29 ms |
19832 KB |
Ok |
52 |
Correct |
29 ms |
19832 KB |
Ok |
53 |
Correct |
30 ms |
19832 KB |
Ok |
54 |
Correct |
338 ms |
27504 KB |
Ok |
55 |
Correct |
458 ms |
27900 KB |
Ok |
56 |
Correct |
465 ms |
27964 KB |
Ok |
57 |
Correct |
234 ms |
26664 KB |
Ok |
58 |
Correct |
305 ms |
27292 KB |
Ok |
59 |
Correct |
391 ms |
26816 KB |
Ok |
60 |
Correct |
184 ms |
26336 KB |
Ok |
61 |
Correct |
223 ms |
27176 KB |
Ok |
62 |
Correct |
332 ms |
27560 KB |
Ok |
63 |
Correct |
253 ms |
26704 KB |
Ok |
64 |
Correct |
390 ms |
27704 KB |
Ok |
65 |
Correct |
307 ms |
27380 KB |
Ok |
66 |
Correct |
262 ms |
27216 KB |
Ok |
67 |
Correct |
223 ms |
26996 KB |
Ok |
68 |
Correct |
271 ms |
27364 KB |
Ok |
69 |
Correct |
695 ms |
38388 KB |
Ok |
70 |
Correct |
604 ms |
39540 KB |
Ok |
71 |
Correct |
942 ms |
39104 KB |
Ok |
72 |
Correct |
760 ms |
38424 KB |
Ok |
73 |
Correct |
554 ms |
39028 KB |
Ok |
74 |
Correct |
819 ms |
38472 KB |
Ok |
75 |
Correct |
886 ms |
37752 KB |
Ok |
76 |
Correct |
581 ms |
39004 KB |
Ok |
77 |
Correct |
685 ms |
37628 KB |
Ok |
78 |
Correct |
625 ms |
38900 KB |
Ok |
79 |
Correct |
684 ms |
39028 KB |
Ok |
80 |
Correct |
658 ms |
39412 KB |
Ok |
81 |
Correct |
750 ms |
38784 KB |
Ok |
82 |
Correct |
705 ms |
39180 KB |
Ok |
83 |
Correct |
779 ms |
37688 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
19192 KB |
Ok |
2 |
Correct |
15 ms |
19192 KB |
Ok |
3 |
Correct |
18 ms |
19064 KB |
Ok |
4 |
Correct |
15 ms |
19064 KB |
Ok |
5 |
Correct |
15 ms |
19192 KB |
Ok |
6 |
Correct |
17 ms |
19320 KB |
Ok |
7 |
Correct |
19 ms |
19192 KB |
Ok |
8 |
Correct |
15 ms |
19064 KB |
Ok |
9 |
Correct |
19 ms |
19192 KB |
Ok |
10 |
Correct |
15 ms |
19192 KB |
Ok |
11 |
Correct |
18 ms |
19064 KB |
Ok |
12 |
Correct |
18 ms |
19192 KB |
Ok |
13 |
Correct |
18 ms |
19064 KB |
Ok |
14 |
Correct |
19 ms |
19192 KB |
Ok |
15 |
Correct |
19 ms |
19116 KB |
Ok |
16 |
Correct |
17 ms |
19192 KB |
Ok |
17 |
Correct |
18 ms |
19192 KB |
Ok |
18 |
Correct |
23 ms |
19448 KB |
Ok |
19 |
Correct |
32 ms |
20728 KB |
Ok |
20 |
Correct |
25 ms |
19832 KB |
Ok |
21 |
Correct |
36 ms |
20984 KB |
Ok |
22 |
Correct |
28 ms |
20216 KB |
Ok |
23 |
Correct |
18 ms |
19064 KB |
Ok |
24 |
Correct |
19 ms |
19192 KB |
Ok |
25 |
Correct |
19 ms |
19064 KB |
Ok |
26 |
Correct |
18 ms |
19192 KB |
Ok |
27 |
Correct |
18 ms |
19064 KB |
Ok |
28 |
Correct |
18 ms |
19192 KB |
Ok |
29 |
Correct |
18 ms |
19192 KB |
Ok |
30 |
Correct |
18 ms |
19064 KB |
Ok |
31 |
Correct |
18 ms |
19164 KB |
Ok |
32 |
Correct |
18 ms |
19064 KB |
Ok |
33 |
Correct |
19 ms |
19064 KB |
Ok |
34 |
Correct |
18 ms |
19064 KB |
Ok |
35 |
Correct |
18 ms |
19064 KB |
Ok |
36 |
Correct |
18 ms |
19192 KB |
Ok |
37 |
Correct |
18 ms |
19064 KB |
Ok |
38 |
Correct |
17 ms |
19192 KB |
Ok |
39 |
Correct |
304 ms |
43372 KB |
Ok |
40 |
Correct |
289 ms |
45168 KB |
Ok |
41 |
Correct |
540 ms |
49396 KB |
Ok |
42 |
Correct |
396 ms |
45804 KB |
Ok |
43 |
Correct |
192 ms |
33708 KB |
Ok |
44 |
Correct |
366 ms |
47336 KB |
Ok |
45 |
Correct |
18 ms |
19320 KB |
Ok |
46 |
Correct |
19 ms |
19448 KB |
Ok |
47 |
Correct |
21 ms |
19476 KB |
Ok |
48 |
Correct |
19 ms |
19420 KB |
Ok |
49 |
Correct |
18 ms |
19292 KB |
Ok |
50 |
Correct |
18 ms |
19320 KB |
Ok |
51 |
Correct |
18 ms |
19320 KB |
Ok |
52 |
Correct |
20 ms |
19448 KB |
Ok |
53 |
Correct |
19 ms |
19320 KB |
Ok |
54 |
Correct |
19 ms |
19320 KB |
Ok |
55 |
Correct |
25 ms |
19704 KB |
Ok |
56 |
Correct |
26 ms |
19832 KB |
Ok |
57 |
Correct |
29 ms |
19832 KB |
Ok |
58 |
Correct |
26 ms |
19832 KB |
Ok |
59 |
Correct |
25 ms |
19792 KB |
Ok |
60 |
Correct |
25 ms |
19832 KB |
Ok |
61 |
Correct |
27 ms |
19832 KB |
Ok |
62 |
Correct |
29 ms |
19832 KB |
Ok |
63 |
Correct |
29 ms |
19832 KB |
Ok |
64 |
Correct |
30 ms |
19832 KB |
Ok |
65 |
Correct |
338 ms |
27504 KB |
Ok |
66 |
Correct |
458 ms |
27900 KB |
Ok |
67 |
Correct |
465 ms |
27964 KB |
Ok |
68 |
Correct |
234 ms |
26664 KB |
Ok |
69 |
Correct |
305 ms |
27292 KB |
Ok |
70 |
Correct |
391 ms |
26816 KB |
Ok |
71 |
Correct |
184 ms |
26336 KB |
Ok |
72 |
Correct |
223 ms |
27176 KB |
Ok |
73 |
Correct |
332 ms |
27560 KB |
Ok |
74 |
Correct |
253 ms |
26704 KB |
Ok |
75 |
Correct |
390 ms |
27704 KB |
Ok |
76 |
Correct |
307 ms |
27380 KB |
Ok |
77 |
Correct |
262 ms |
27216 KB |
Ok |
78 |
Correct |
223 ms |
26996 KB |
Ok |
79 |
Correct |
271 ms |
27364 KB |
Ok |
80 |
Correct |
695 ms |
38388 KB |
Ok |
81 |
Correct |
604 ms |
39540 KB |
Ok |
82 |
Correct |
942 ms |
39104 KB |
Ok |
83 |
Correct |
760 ms |
38424 KB |
Ok |
84 |
Correct |
554 ms |
39028 KB |
Ok |
85 |
Correct |
819 ms |
38472 KB |
Ok |
86 |
Correct |
886 ms |
37752 KB |
Ok |
87 |
Correct |
581 ms |
39004 KB |
Ok |
88 |
Correct |
685 ms |
37628 KB |
Ok |
89 |
Correct |
625 ms |
38900 KB |
Ok |
90 |
Correct |
684 ms |
39028 KB |
Ok |
91 |
Correct |
658 ms |
39412 KB |
Ok |
92 |
Correct |
750 ms |
38784 KB |
Ok |
93 |
Correct |
705 ms |
39180 KB |
Ok |
94 |
Correct |
779 ms |
37688 KB |
Ok |
95 |
Correct |
773 ms |
41072 KB |
Ok |
96 |
Incorrect |
796 ms |
43116 KB |
Jury has the better answer : jans = 280751, pans = 262143 |
97 |
Halted |
0 ms |
0 KB |
- |