#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 = n + m;
while(!check(res, n, m)) {
res--;
}
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:114: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 |
9 ms |
9720 KB |
Ok |
4 |
Correct |
9 ms |
9720 KB |
Ok |
5 |
Correct |
11 ms |
9720 KB |
Ok |
6 |
Correct |
10 ms |
9720 KB |
Ok |
7 |
Correct |
9 ms |
9692 KB |
Ok |
8 |
Correct |
9 ms |
9724 KB |
Ok |
9 |
Correct |
10 ms |
9720 KB |
Ok |
10 |
Correct |
10 ms |
9692 KB |
Ok |
11 |
Correct |
10 ms |
9720 KB |
Ok |
12 |
Correct |
10 ms |
9720 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
9692 KB |
Ok |
2 |
Correct |
10 ms |
9692 KB |
Ok |
3 |
Correct |
10 ms |
9720 KB |
Ok |
4 |
Correct |
10 ms |
9720 KB |
Ok |
5 |
Correct |
9 ms |
9720 KB |
Ok |
6 |
Correct |
12 ms |
9976 KB |
Ok |
7 |
Correct |
20 ms |
11128 KB |
Ok |
8 |
Correct |
15 ms |
10360 KB |
Ok |
9 |
Correct |
22 ms |
11384 KB |
Ok |
10 |
Correct |
17 ms |
10616 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
9720 KB |
Ok |
2 |
Correct |
10 ms |
9720 KB |
Ok |
3 |
Correct |
9 ms |
9720 KB |
Ok |
4 |
Correct |
9 ms |
9720 KB |
Ok |
5 |
Correct |
9 ms |
9720 KB |
Ok |
6 |
Correct |
9 ms |
9720 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 |
10 ms |
9720 KB |
Ok |
11 |
Correct |
10 ms |
9720 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
9768 KB |
Ok |
2 |
Correct |
10 ms |
9812 KB |
Ok |
3 |
Correct |
9 ms |
9720 KB |
Ok |
4 |
Correct |
10 ms |
9784 KB |
Ok |
5 |
Correct |
10 ms |
9720 KB |
Ok |
6 |
Correct |
175 ms |
28648 KB |
Ok |
7 |
Correct |
152 ms |
29320 KB |
Ok |
8 |
Correct |
290 ms |
33748 KB |
Ok |
9 |
Correct |
215 ms |
31084 KB |
Ok |
10 |
Correct |
108 ms |
20592 KB |
Ok |
11 |
Correct |
182 ms |
31608 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
9720 KB |
Ok |
2 |
Correct |
10 ms |
9720 KB |
Ok |
3 |
Correct |
9 ms |
9720 KB |
Ok |
4 |
Correct |
9 ms |
9720 KB |
Ok |
5 |
Correct |
11 ms |
9720 KB |
Ok |
6 |
Correct |
10 ms |
9720 KB |
Ok |
7 |
Correct |
9 ms |
9692 KB |
Ok |
8 |
Correct |
9 ms |
9724 KB |
Ok |
9 |
Correct |
10 ms |
9720 KB |
Ok |
10 |
Correct |
10 ms |
9692 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 |
9 ms |
9720 KB |
Ok |
16 |
Correct |
9 ms |
9720 KB |
Ok |
17 |
Correct |
9 ms |
9720 KB |
Ok |
18 |
Correct |
9 ms |
9720 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 |
10 ms |
9720 KB |
Ok |
23 |
Correct |
10 ms |
9720 KB |
Ok |
24 |
Correct |
43 ms |
9884 KB |
Ok |
25 |
Correct |
28 ms |
9960 KB |
Ok |
26 |
Correct |
23 ms |
9848 KB |
Ok |
27 |
Correct |
33 ms |
9976 KB |
Ok |
28 |
Correct |
24 ms |
9848 KB |
Ok |
29 |
Correct |
15 ms |
9848 KB |
Ok |
30 |
Correct |
23 ms |
9848 KB |
Ok |
31 |
Correct |
40 ms |
9976 KB |
Ok |
32 |
Correct |
38 ms |
9944 KB |
Ok |
33 |
Correct |
32 ms |
9976 KB |
Ok |
34 |
Correct |
18 ms |
10232 KB |
Ok |
35 |
Correct |
17 ms |
10232 KB |
Ok |
36 |
Correct |
16 ms |
10232 KB |
Ok |
37 |
Correct |
15 ms |
10232 KB |
Ok |
38 |
Correct |
17 ms |
10308 KB |
Ok |
39 |
Correct |
20 ms |
10232 KB |
Ok |
40 |
Correct |
17 ms |
10360 KB |
Ok |
41 |
Correct |
17 ms |
10360 KB |
Ok |
42 |
Correct |
18 ms |
10232 KB |
Ok |
43 |
Correct |
17 ms |
10232 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
9720 KB |
Ok |
2 |
Correct |
10 ms |
9720 KB |
Ok |
3 |
Correct |
9 ms |
9720 KB |
Ok |
4 |
Correct |
9 ms |
9720 KB |
Ok |
5 |
Correct |
11 ms |
9720 KB |
Ok |
6 |
Correct |
10 ms |
9720 KB |
Ok |
7 |
Correct |
9 ms |
9692 KB |
Ok |
8 |
Correct |
9 ms |
9724 KB |
Ok |
9 |
Correct |
10 ms |
9720 KB |
Ok |
10 |
Correct |
10 ms |
9692 KB |
Ok |
11 |
Correct |
10 ms |
9720 KB |
Ok |
12 |
Correct |
10 ms |
9720 KB |
Ok |
13 |
Correct |
10 ms |
9692 KB |
Ok |
14 |
Correct |
10 ms |
9692 KB |
Ok |
15 |
Correct |
10 ms |
9720 KB |
Ok |
16 |
Correct |
10 ms |
9720 KB |
Ok |
17 |
Correct |
9 ms |
9720 KB |
Ok |
18 |
Correct |
12 ms |
9976 KB |
Ok |
19 |
Correct |
20 ms |
11128 KB |
Ok |
20 |
Correct |
15 ms |
10360 KB |
Ok |
21 |
Correct |
22 ms |
11384 KB |
Ok |
22 |
Correct |
17 ms |
10616 KB |
Ok |
23 |
Correct |
9 ms |
9720 KB |
Ok |
24 |
Correct |
10 ms |
9720 KB |
Ok |
25 |
Correct |
9 ms |
9720 KB |
Ok |
26 |
Correct |
9 ms |
9720 KB |
Ok |
27 |
Correct |
9 ms |
9720 KB |
Ok |
28 |
Correct |
9 ms |
9720 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 |
10 ms |
9720 KB |
Ok |
33 |
Correct |
10 ms |
9720 KB |
Ok |
34 |
Correct |
43 ms |
9884 KB |
Ok |
35 |
Correct |
28 ms |
9960 KB |
Ok |
36 |
Correct |
23 ms |
9848 KB |
Ok |
37 |
Correct |
33 ms |
9976 KB |
Ok |
38 |
Correct |
24 ms |
9848 KB |
Ok |
39 |
Correct |
15 ms |
9848 KB |
Ok |
40 |
Correct |
23 ms |
9848 KB |
Ok |
41 |
Correct |
40 ms |
9976 KB |
Ok |
42 |
Correct |
38 ms |
9944 KB |
Ok |
43 |
Correct |
32 ms |
9976 KB |
Ok |
44 |
Correct |
18 ms |
10232 KB |
Ok |
45 |
Correct |
17 ms |
10232 KB |
Ok |
46 |
Correct |
16 ms |
10232 KB |
Ok |
47 |
Correct |
15 ms |
10232 KB |
Ok |
48 |
Correct |
17 ms |
10308 KB |
Ok |
49 |
Correct |
20 ms |
10232 KB |
Ok |
50 |
Correct |
17 ms |
10360 KB |
Ok |
51 |
Correct |
17 ms |
10360 KB |
Ok |
52 |
Correct |
18 ms |
10232 KB |
Ok |
53 |
Correct |
17 ms |
10232 KB |
Ok |
54 |
Execution timed out |
2043 ms |
12540 KB |
Time limit exceeded |
55 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
9720 KB |
Ok |
2 |
Correct |
10 ms |
9720 KB |
Ok |
3 |
Correct |
9 ms |
9720 KB |
Ok |
4 |
Correct |
9 ms |
9720 KB |
Ok |
5 |
Correct |
11 ms |
9720 KB |
Ok |
6 |
Correct |
10 ms |
9720 KB |
Ok |
7 |
Correct |
9 ms |
9692 KB |
Ok |
8 |
Correct |
9 ms |
9724 KB |
Ok |
9 |
Correct |
10 ms |
9720 KB |
Ok |
10 |
Correct |
10 ms |
9692 KB |
Ok |
11 |
Correct |
10 ms |
9720 KB |
Ok |
12 |
Correct |
10 ms |
9720 KB |
Ok |
13 |
Correct |
10 ms |
9692 KB |
Ok |
14 |
Correct |
10 ms |
9692 KB |
Ok |
15 |
Correct |
10 ms |
9720 KB |
Ok |
16 |
Correct |
10 ms |
9720 KB |
Ok |
17 |
Correct |
9 ms |
9720 KB |
Ok |
18 |
Correct |
12 ms |
9976 KB |
Ok |
19 |
Correct |
20 ms |
11128 KB |
Ok |
20 |
Correct |
15 ms |
10360 KB |
Ok |
21 |
Correct |
22 ms |
11384 KB |
Ok |
22 |
Correct |
17 ms |
10616 KB |
Ok |
23 |
Correct |
9 ms |
9720 KB |
Ok |
24 |
Correct |
10 ms |
9720 KB |
Ok |
25 |
Correct |
9 ms |
9720 KB |
Ok |
26 |
Correct |
9 ms |
9720 KB |
Ok |
27 |
Correct |
9 ms |
9720 KB |
Ok |
28 |
Correct |
9 ms |
9720 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 |
10 ms |
9720 KB |
Ok |
33 |
Correct |
10 ms |
9720 KB |
Ok |
34 |
Correct |
10 ms |
9768 KB |
Ok |
35 |
Correct |
10 ms |
9812 KB |
Ok |
36 |
Correct |
9 ms |
9720 KB |
Ok |
37 |
Correct |
10 ms |
9784 KB |
Ok |
38 |
Correct |
10 ms |
9720 KB |
Ok |
39 |
Correct |
175 ms |
28648 KB |
Ok |
40 |
Correct |
152 ms |
29320 KB |
Ok |
41 |
Correct |
290 ms |
33748 KB |
Ok |
42 |
Correct |
215 ms |
31084 KB |
Ok |
43 |
Correct |
108 ms |
20592 KB |
Ok |
44 |
Correct |
182 ms |
31608 KB |
Ok |
45 |
Correct |
43 ms |
9884 KB |
Ok |
46 |
Correct |
28 ms |
9960 KB |
Ok |
47 |
Correct |
23 ms |
9848 KB |
Ok |
48 |
Correct |
33 ms |
9976 KB |
Ok |
49 |
Correct |
24 ms |
9848 KB |
Ok |
50 |
Correct |
15 ms |
9848 KB |
Ok |
51 |
Correct |
23 ms |
9848 KB |
Ok |
52 |
Correct |
40 ms |
9976 KB |
Ok |
53 |
Correct |
38 ms |
9944 KB |
Ok |
54 |
Correct |
32 ms |
9976 KB |
Ok |
55 |
Correct |
18 ms |
10232 KB |
Ok |
56 |
Correct |
17 ms |
10232 KB |
Ok |
57 |
Correct |
16 ms |
10232 KB |
Ok |
58 |
Correct |
15 ms |
10232 KB |
Ok |
59 |
Correct |
17 ms |
10308 KB |
Ok |
60 |
Correct |
20 ms |
10232 KB |
Ok |
61 |
Correct |
17 ms |
10360 KB |
Ok |
62 |
Correct |
17 ms |
10360 KB |
Ok |
63 |
Correct |
18 ms |
10232 KB |
Ok |
64 |
Correct |
17 ms |
10232 KB |
Ok |
65 |
Execution timed out |
2043 ms |
12540 KB |
Time limit exceeded |
66 |
Halted |
0 ms |
0 KB |
- |