#include <cstdio>
#include <cstring>
#define PB push_back
using namespace std;
const int N = 4e5 + 500;
int bio[N], L[N], R[N];
void clean(){
memset(bio, 0, sizeof(bio));
memset(L, -1, sizeof(L));
memset(R, -1, sizeof(R));
}
bool ima_ciklus(int x){
bio[x] = 1;
if(L[x] != -1 && bio[L[x]] == 1) return 1;
if(R[x] != -1 && bio[R[x]] == 1) return 1;
if(L[x] != -1 && bio[L[x]] != 2 && ima_ciklus(L[x])) return 1;
if(R[x] != -1 && bio[R[x]] != 2 && ima_ciklus(R[x])) return 1;
bio[x] = 2;
return 0;
}
int P[N], cur = 0;
void topsort(int x){
if(bio[x]) return;
bio[x] = 1;
if(L[x] != -1) topsort(L[x]);
if(R[x] != -1) topsort(R[x]);
P[x] = cur++;
}
bool check(int n, int a, int b, bool napravi = false){
clean();
for(int i = 0;i <= n;i++){
if(i + a <= n) L[i + a] = i;
if(i + b <= n) R[i] = i + b;
}
if(!napravi){
for(int i = 0;i <= n;i++)
if(!bio[i] && ima_ciklus(i)){
return false;
}
return true;
}
cur = 0;
for(int i = 0;i <= n;i++)
topsort(i);
for(int i = 1;i <= n;i++)
P[i] -= P[0];
P[0] = 0;
printf("%d\n", n);
for(int i = 1;i <= n;i++)
printf("%d ", P[i] - P[i - 1]);
printf("\n");
return true;
}
int main(){
int T; scanf("%d", &T);
for(;T--;){
int a, b; scanf("%d%d", &b, &a);
int ans = 0;
for(int i = 18;i >= 0;i--){
if(ans + (1 << i) <= a + b && check(ans + (1 << i), a, b))
ans += (1 << i);
}
check(ans, a, b, 1);
}
return 0;
}
Compilation message
sequence.cpp: In function 'int main()':
sequence.cpp:66:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
66 | int T; scanf("%d", &T);
| ~~~~~^~~~~~~~~~
sequence.cpp:68:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
68 | int a, b; scanf("%d%d", &b, &a);
| ~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
5100 KB |
Ok |
2 |
Correct |
14 ms |
4972 KB |
Ok |
3 |
Correct |
19 ms |
5100 KB |
Ok |
4 |
Correct |
20 ms |
4972 KB |
Ok |
5 |
Correct |
19 ms |
4972 KB |
Ok |
6 |
Correct |
18 ms |
4972 KB |
Ok |
7 |
Correct |
19 ms |
4972 KB |
Ok |
8 |
Correct |
18 ms |
4972 KB |
Ok |
9 |
Correct |
20 ms |
4972 KB |
Ok |
10 |
Correct |
18 ms |
4972 KB |
Ok |
11 |
Correct |
19 ms |
4972 KB |
Ok |
12 |
Correct |
20 ms |
4972 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
4972 KB |
Ok |
2 |
Correct |
12 ms |
4972 KB |
Ok |
3 |
Correct |
14 ms |
4972 KB |
Ok |
4 |
Correct |
14 ms |
4972 KB |
Ok |
5 |
Correct |
15 ms |
4972 KB |
Ok |
6 |
Correct |
23 ms |
5100 KB |
Ok |
7 |
Correct |
36 ms |
5740 KB |
Ok |
8 |
Correct |
32 ms |
5356 KB |
Ok |
9 |
Correct |
40 ms |
5868 KB |
Ok |
10 |
Correct |
31 ms |
5484 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
4972 KB |
Ok |
2 |
Correct |
11 ms |
4972 KB |
Ok |
3 |
Correct |
11 ms |
4972 KB |
Ok |
4 |
Correct |
11 ms |
4972 KB |
Ok |
5 |
Correct |
12 ms |
4972 KB |
Ok |
6 |
Correct |
12 ms |
4972 KB |
Ok |
7 |
Correct |
12 ms |
4972 KB |
Ok |
8 |
Correct |
13 ms |
4972 KB |
Ok |
9 |
Correct |
13 ms |
4972 KB |
Ok |
10 |
Correct |
12 ms |
4972 KB |
Ok |
11 |
Correct |
13 ms |
4972 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
4972 KB |
Ok |
2 |
Correct |
14 ms |
5100 KB |
Ok |
3 |
Correct |
16 ms |
4992 KB |
Ok |
4 |
Correct |
14 ms |
5100 KB |
Ok |
5 |
Correct |
15 ms |
4972 KB |
Ok |
6 |
Correct |
197 ms |
13932 KB |
Ok |
7 |
Correct |
195 ms |
14188 KB |
Ok |
8 |
Correct |
350 ms |
17004 KB |
Ok |
9 |
Correct |
261 ms |
15604 KB |
Ok |
10 |
Correct |
156 ms |
10068 KB |
Ok |
11 |
Correct |
249 ms |
15596 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
5100 KB |
Ok |
2 |
Correct |
14 ms |
4972 KB |
Ok |
3 |
Correct |
19 ms |
5100 KB |
Ok |
4 |
Correct |
20 ms |
4972 KB |
Ok |
5 |
Correct |
19 ms |
4972 KB |
Ok |
6 |
Correct |
18 ms |
4972 KB |
Ok |
7 |
Correct |
19 ms |
4972 KB |
Ok |
8 |
Correct |
18 ms |
4972 KB |
Ok |
9 |
Correct |
20 ms |
4972 KB |
Ok |
10 |
Correct |
18 ms |
4972 KB |
Ok |
11 |
Correct |
19 ms |
4972 KB |
Ok |
12 |
Correct |
20 ms |
4972 KB |
Ok |
13 |
Correct |
6 ms |
4972 KB |
Ok |
14 |
Correct |
11 ms |
4972 KB |
Ok |
15 |
Correct |
11 ms |
4972 KB |
Ok |
16 |
Correct |
11 ms |
4972 KB |
Ok |
17 |
Correct |
12 ms |
4972 KB |
Ok |
18 |
Correct |
12 ms |
4972 KB |
Ok |
19 |
Correct |
12 ms |
4972 KB |
Ok |
20 |
Correct |
13 ms |
4972 KB |
Ok |
21 |
Correct |
13 ms |
4972 KB |
Ok |
22 |
Correct |
12 ms |
4972 KB |
Ok |
23 |
Correct |
13 ms |
4972 KB |
Ok |
24 |
Correct |
30 ms |
5100 KB |
Ok |
25 |
Correct |
29 ms |
5100 KB |
Ok |
26 |
Correct |
29 ms |
5100 KB |
Ok |
27 |
Correct |
29 ms |
5100 KB |
Ok |
28 |
Correct |
27 ms |
5100 KB |
Ok |
29 |
Correct |
28 ms |
5100 KB |
Ok |
30 |
Correct |
27 ms |
5100 KB |
Ok |
31 |
Correct |
29 ms |
5100 KB |
Ok |
32 |
Correct |
29 ms |
5100 KB |
Ok |
33 |
Correct |
28 ms |
5100 KB |
Ok |
34 |
Correct |
34 ms |
5228 KB |
Ok |
35 |
Correct |
27 ms |
5228 KB |
Ok |
36 |
Correct |
28 ms |
5356 KB |
Ok |
37 |
Correct |
32 ms |
5356 KB |
Ok |
38 |
Correct |
33 ms |
5356 KB |
Ok |
39 |
Correct |
30 ms |
5228 KB |
Ok |
40 |
Correct |
29 ms |
5356 KB |
Ok |
41 |
Correct |
28 ms |
5356 KB |
Ok |
42 |
Correct |
28 ms |
5228 KB |
Ok |
43 |
Correct |
32 ms |
5356 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
5100 KB |
Ok |
2 |
Correct |
14 ms |
4972 KB |
Ok |
3 |
Correct |
19 ms |
5100 KB |
Ok |
4 |
Correct |
20 ms |
4972 KB |
Ok |
5 |
Correct |
19 ms |
4972 KB |
Ok |
6 |
Correct |
18 ms |
4972 KB |
Ok |
7 |
Correct |
19 ms |
4972 KB |
Ok |
8 |
Correct |
18 ms |
4972 KB |
Ok |
9 |
Correct |
20 ms |
4972 KB |
Ok |
10 |
Correct |
18 ms |
4972 KB |
Ok |
11 |
Correct |
19 ms |
4972 KB |
Ok |
12 |
Correct |
20 ms |
4972 KB |
Ok |
13 |
Correct |
14 ms |
4972 KB |
Ok |
14 |
Correct |
12 ms |
4972 KB |
Ok |
15 |
Correct |
14 ms |
4972 KB |
Ok |
16 |
Correct |
14 ms |
4972 KB |
Ok |
17 |
Correct |
15 ms |
4972 KB |
Ok |
18 |
Correct |
23 ms |
5100 KB |
Ok |
19 |
Correct |
36 ms |
5740 KB |
Ok |
20 |
Correct |
32 ms |
5356 KB |
Ok |
21 |
Correct |
40 ms |
5868 KB |
Ok |
22 |
Correct |
31 ms |
5484 KB |
Ok |
23 |
Correct |
6 ms |
4972 KB |
Ok |
24 |
Correct |
11 ms |
4972 KB |
Ok |
25 |
Correct |
11 ms |
4972 KB |
Ok |
26 |
Correct |
11 ms |
4972 KB |
Ok |
27 |
Correct |
12 ms |
4972 KB |
Ok |
28 |
Correct |
12 ms |
4972 KB |
Ok |
29 |
Correct |
12 ms |
4972 KB |
Ok |
30 |
Correct |
13 ms |
4972 KB |
Ok |
31 |
Correct |
13 ms |
4972 KB |
Ok |
32 |
Correct |
12 ms |
4972 KB |
Ok |
33 |
Correct |
13 ms |
4972 KB |
Ok |
34 |
Correct |
30 ms |
5100 KB |
Ok |
35 |
Correct |
29 ms |
5100 KB |
Ok |
36 |
Correct |
29 ms |
5100 KB |
Ok |
37 |
Correct |
29 ms |
5100 KB |
Ok |
38 |
Correct |
27 ms |
5100 KB |
Ok |
39 |
Correct |
28 ms |
5100 KB |
Ok |
40 |
Correct |
27 ms |
5100 KB |
Ok |
41 |
Correct |
29 ms |
5100 KB |
Ok |
42 |
Correct |
29 ms |
5100 KB |
Ok |
43 |
Correct |
28 ms |
5100 KB |
Ok |
44 |
Correct |
34 ms |
5228 KB |
Ok |
45 |
Correct |
27 ms |
5228 KB |
Ok |
46 |
Correct |
28 ms |
5356 KB |
Ok |
47 |
Correct |
32 ms |
5356 KB |
Ok |
48 |
Correct |
33 ms |
5356 KB |
Ok |
49 |
Correct |
30 ms |
5228 KB |
Ok |
50 |
Correct |
29 ms |
5356 KB |
Ok |
51 |
Correct |
28 ms |
5356 KB |
Ok |
52 |
Correct |
28 ms |
5228 KB |
Ok |
53 |
Correct |
32 ms |
5356 KB |
Ok |
54 |
Correct |
177 ms |
7020 KB |
Ok |
55 |
Correct |
201 ms |
7532 KB |
Ok |
56 |
Correct |
193 ms |
7404 KB |
Ok |
57 |
Correct |
151 ms |
6636 KB |
Ok |
58 |
Correct |
166 ms |
7020 KB |
Ok |
59 |
Correct |
177 ms |
6840 KB |
Ok |
60 |
Correct |
147 ms |
6636 KB |
Ok |
61 |
Correct |
153 ms |
6764 KB |
Ok |
62 |
Correct |
183 ms |
7148 KB |
Ok |
63 |
Correct |
160 ms |
6764 KB |
Ok |
64 |
Correct |
211 ms |
7532 KB |
Ok |
65 |
Correct |
173 ms |
7020 KB |
Ok |
66 |
Correct |
166 ms |
6892 KB |
Ok |
67 |
Correct |
156 ms |
6764 KB |
Ok |
68 |
Correct |
170 ms |
6892 KB |
Ok |
69 |
Correct |
305 ms |
14572 KB |
Ok |
70 |
Correct |
303 ms |
15212 KB |
Ok |
71 |
Correct |
294 ms |
14572 KB |
Ok |
72 |
Correct |
308 ms |
14700 KB |
Ok |
73 |
Correct |
294 ms |
14700 KB |
Ok |
74 |
Correct |
292 ms |
14444 KB |
Ok |
75 |
Correct |
317 ms |
13932 KB |
Ok |
76 |
Correct |
312 ms |
14956 KB |
Ok |
77 |
Correct |
301 ms |
14060 KB |
Ok |
78 |
Correct |
304 ms |
14700 KB |
Ok |
79 |
Correct |
318 ms |
14828 KB |
Ok |
80 |
Correct |
298 ms |
14828 KB |
Ok |
81 |
Correct |
305 ms |
14700 KB |
Ok |
82 |
Correct |
303 ms |
14828 KB |
Ok |
83 |
Correct |
312 ms |
14188 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
5100 KB |
Ok |
2 |
Correct |
14 ms |
4972 KB |
Ok |
3 |
Correct |
19 ms |
5100 KB |
Ok |
4 |
Correct |
20 ms |
4972 KB |
Ok |
5 |
Correct |
19 ms |
4972 KB |
Ok |
6 |
Correct |
18 ms |
4972 KB |
Ok |
7 |
Correct |
19 ms |
4972 KB |
Ok |
8 |
Correct |
18 ms |
4972 KB |
Ok |
9 |
Correct |
20 ms |
4972 KB |
Ok |
10 |
Correct |
18 ms |
4972 KB |
Ok |
11 |
Correct |
19 ms |
4972 KB |
Ok |
12 |
Correct |
20 ms |
4972 KB |
Ok |
13 |
Correct |
14 ms |
4972 KB |
Ok |
14 |
Correct |
12 ms |
4972 KB |
Ok |
15 |
Correct |
14 ms |
4972 KB |
Ok |
16 |
Correct |
14 ms |
4972 KB |
Ok |
17 |
Correct |
15 ms |
4972 KB |
Ok |
18 |
Correct |
23 ms |
5100 KB |
Ok |
19 |
Correct |
36 ms |
5740 KB |
Ok |
20 |
Correct |
32 ms |
5356 KB |
Ok |
21 |
Correct |
40 ms |
5868 KB |
Ok |
22 |
Correct |
31 ms |
5484 KB |
Ok |
23 |
Correct |
6 ms |
4972 KB |
Ok |
24 |
Correct |
11 ms |
4972 KB |
Ok |
25 |
Correct |
11 ms |
4972 KB |
Ok |
26 |
Correct |
11 ms |
4972 KB |
Ok |
27 |
Correct |
12 ms |
4972 KB |
Ok |
28 |
Correct |
12 ms |
4972 KB |
Ok |
29 |
Correct |
12 ms |
4972 KB |
Ok |
30 |
Correct |
13 ms |
4972 KB |
Ok |
31 |
Correct |
13 ms |
4972 KB |
Ok |
32 |
Correct |
12 ms |
4972 KB |
Ok |
33 |
Correct |
13 ms |
4972 KB |
Ok |
34 |
Correct |
11 ms |
4972 KB |
Ok |
35 |
Correct |
14 ms |
5100 KB |
Ok |
36 |
Correct |
16 ms |
4992 KB |
Ok |
37 |
Correct |
14 ms |
5100 KB |
Ok |
38 |
Correct |
15 ms |
4972 KB |
Ok |
39 |
Correct |
197 ms |
13932 KB |
Ok |
40 |
Correct |
195 ms |
14188 KB |
Ok |
41 |
Correct |
350 ms |
17004 KB |
Ok |
42 |
Correct |
261 ms |
15604 KB |
Ok |
43 |
Correct |
156 ms |
10068 KB |
Ok |
44 |
Correct |
249 ms |
15596 KB |
Ok |
45 |
Correct |
30 ms |
5100 KB |
Ok |
46 |
Correct |
29 ms |
5100 KB |
Ok |
47 |
Correct |
29 ms |
5100 KB |
Ok |
48 |
Correct |
29 ms |
5100 KB |
Ok |
49 |
Correct |
27 ms |
5100 KB |
Ok |
50 |
Correct |
28 ms |
5100 KB |
Ok |
51 |
Correct |
27 ms |
5100 KB |
Ok |
52 |
Correct |
29 ms |
5100 KB |
Ok |
53 |
Correct |
29 ms |
5100 KB |
Ok |
54 |
Correct |
28 ms |
5100 KB |
Ok |
55 |
Correct |
34 ms |
5228 KB |
Ok |
56 |
Correct |
27 ms |
5228 KB |
Ok |
57 |
Correct |
28 ms |
5356 KB |
Ok |
58 |
Correct |
32 ms |
5356 KB |
Ok |
59 |
Correct |
33 ms |
5356 KB |
Ok |
60 |
Correct |
30 ms |
5228 KB |
Ok |
61 |
Correct |
29 ms |
5356 KB |
Ok |
62 |
Correct |
28 ms |
5356 KB |
Ok |
63 |
Correct |
28 ms |
5228 KB |
Ok |
64 |
Correct |
32 ms |
5356 KB |
Ok |
65 |
Correct |
177 ms |
7020 KB |
Ok |
66 |
Correct |
201 ms |
7532 KB |
Ok |
67 |
Correct |
193 ms |
7404 KB |
Ok |
68 |
Correct |
151 ms |
6636 KB |
Ok |
69 |
Correct |
166 ms |
7020 KB |
Ok |
70 |
Correct |
177 ms |
6840 KB |
Ok |
71 |
Correct |
147 ms |
6636 KB |
Ok |
72 |
Correct |
153 ms |
6764 KB |
Ok |
73 |
Correct |
183 ms |
7148 KB |
Ok |
74 |
Correct |
160 ms |
6764 KB |
Ok |
75 |
Correct |
211 ms |
7532 KB |
Ok |
76 |
Correct |
173 ms |
7020 KB |
Ok |
77 |
Correct |
166 ms |
6892 KB |
Ok |
78 |
Correct |
156 ms |
6764 KB |
Ok |
79 |
Correct |
170 ms |
6892 KB |
Ok |
80 |
Correct |
305 ms |
14572 KB |
Ok |
81 |
Correct |
303 ms |
15212 KB |
Ok |
82 |
Correct |
294 ms |
14572 KB |
Ok |
83 |
Correct |
308 ms |
14700 KB |
Ok |
84 |
Correct |
294 ms |
14700 KB |
Ok |
85 |
Correct |
292 ms |
14444 KB |
Ok |
86 |
Correct |
317 ms |
13932 KB |
Ok |
87 |
Correct |
312 ms |
14956 KB |
Ok |
88 |
Correct |
301 ms |
14060 KB |
Ok |
89 |
Correct |
304 ms |
14700 KB |
Ok |
90 |
Correct |
318 ms |
14828 KB |
Ok |
91 |
Correct |
298 ms |
14828 KB |
Ok |
92 |
Correct |
305 ms |
14700 KB |
Ok |
93 |
Correct |
303 ms |
14828 KB |
Ok |
94 |
Correct |
312 ms |
14188 KB |
Ok |
95 |
Correct |
391 ms |
10348 KB |
Ok |
96 |
Correct |
550 ms |
12140 KB |
Ok |
97 |
Correct |
511 ms |
11372 KB |
Ok |
98 |
Correct |
392 ms |
10220 KB |
Ok |
99 |
Correct |
496 ms |
10860 KB |
Ok |
100 |
Correct |
451 ms |
10988 KB |
Ok |
101 |
Correct |
494 ms |
11232 KB |
Ok |
102 |
Correct |
465 ms |
11372 KB |
Ok |
103 |
Correct |
473 ms |
11244 KB |
Ok |
104 |
Correct |
558 ms |
12396 KB |
Ok |
105 |
Correct |
543 ms |
12012 KB |
Ok |
106 |
Correct |
470 ms |
11756 KB |
Ok |
107 |
Correct |
525 ms |
11500 KB |
Ok |
108 |
Correct |
564 ms |
12268 KB |
Ok |
109 |
Correct |
560 ms |
12140 KB |
Ok |
110 |
Correct |
1473 ms |
44396 KB |
Ok |
111 |
Correct |
1646 ms |
47112 KB |
Ok |
112 |
Correct |
1647 ms |
46852 KB |
Ok |
113 |
Correct |
1506 ms |
46316 KB |
Ok |
114 |
Correct |
1383 ms |
48108 KB |
Ok |
115 |
Correct |
1555 ms |
45832 KB |
Ok |
116 |
Correct |
1652 ms |
47232 KB |
Ok |
117 |
Correct |
1564 ms |
45888 KB |
Ok |
118 |
Correct |
1570 ms |
45804 KB |
Ok |
119 |
Correct |
1679 ms |
45876 KB |
Ok |
120 |
Correct |
1571 ms |
45440 KB |
Ok |
121 |
Correct |
1651 ms |
44096 KB |
Ok |
122 |
Correct |
1675 ms |
46584 KB |
Ok |
123 |
Correct |
1749 ms |
46956 KB |
Ok |
124 |
Correct |
1558 ms |
44396 KB |
Ok |
125 |
Correct |
1066 ms |
29176 KB |
Ok |