#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(labs(x) >= mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl
const int MAX_N = 1e6 + 10;
vector<int> g[MAX_N];
int used[MAX_N];
int n, m;
int arr[MAX_N], pref[MAX_N];
vector<int> top;
bool eval(int x) {
top.resize(0);
for(int i = 0; i <= x; i ++) {
g[i].resize(0);
used[i] = 0;
}
for(int i = 0; i <= x; i ++) {
if(i + n <= x) {
g[i + n].push_back(i);
used[i] ++;
}
if(i - m >= 0) {
g[i - m].push_back(i);
used[i] ++;
}
}
for(int i = 0; i <= x; i ++) {
if(used[i] == 0) {
top.push_back(i);
}
}
int ind = 0;
while(ind < top.size()) {
auto curr = top[ind]; ind ++;
for(auto it : g[curr]) {
used[it] --;
if(used[it] == 0) {
top.push_back(it);
}
}
}
return top.size() == x + 1;
}
void build(int x) {
for(int i = 0; i <= x; i ++) {
pref[top[i]] = i;
}
for(int i = 0; i < x; i ++) {
arr[i] = pref[i + 1] - pref[i];
}
}
void solve() {
cin >> n >> m;
int l = 0, r = MAX_N - 2;
while(l < r - 1) {
int m = (l + r) / 2ll;
//cout << l << " " << m << " " << r << endl;
if(eval(m)) {
l = m;
} else {
r = m;
}
}
cout << l << endl;
eval(l);
build(l);
for(int i = 0; i < l; i ++) {
cout << arr[i] << " ";
}
cout << endl;
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int t;
cin >> t;
while(t --) {
solve();
}
return 0;
}
Compilation message
sequence.cpp: In function 'bool eval(int)':
sequence.cpp:45:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | while(ind < top.size()) {
| ~~~~^~~~~~~~~~~~
sequence.cpp:54:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
54 | return top.size() == x + 1;
| ~~~~~~~~~~~^~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
291 ms |
41464 KB |
Ok |
2 |
Correct |
300 ms |
41464 KB |
Ok |
3 |
Correct |
303 ms |
41592 KB |
Ok |
4 |
Correct |
300 ms |
41464 KB |
Ok |
5 |
Correct |
294 ms |
41592 KB |
Ok |
6 |
Correct |
304 ms |
41592 KB |
Ok |
7 |
Correct |
292 ms |
41592 KB |
Ok |
8 |
Correct |
300 ms |
41592 KB |
Ok |
9 |
Correct |
300 ms |
41592 KB |
Ok |
10 |
Correct |
300 ms |
41592 KB |
Ok |
11 |
Correct |
299 ms |
41464 KB |
Ok |
12 |
Correct |
304 ms |
41464 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
303 ms |
41464 KB |
Ok |
2 |
Correct |
302 ms |
41464 KB |
Ok |
3 |
Correct |
296 ms |
41464 KB |
Ok |
4 |
Correct |
305 ms |
41464 KB |
Ok |
5 |
Correct |
301 ms |
41592 KB |
Ok |
6 |
Correct |
310 ms |
41592 KB |
Ok |
7 |
Correct |
332 ms |
42012 KB |
Ok |
8 |
Correct |
306 ms |
41720 KB |
Ok |
9 |
Correct |
334 ms |
41976 KB |
Ok |
10 |
Correct |
319 ms |
41720 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
139 ms |
41468 KB |
Ok |
2 |
Correct |
301 ms |
41596 KB |
Ok |
3 |
Correct |
296 ms |
41592 KB |
Ok |
4 |
Correct |
314 ms |
41508 KB |
Ok |
5 |
Correct |
298 ms |
41592 KB |
Ok |
6 |
Correct |
300 ms |
41720 KB |
Ok |
7 |
Correct |
296 ms |
41592 KB |
Ok |
8 |
Correct |
298 ms |
41592 KB |
Ok |
9 |
Correct |
300 ms |
41592 KB |
Ok |
10 |
Correct |
300 ms |
41596 KB |
Ok |
11 |
Correct |
299 ms |
41592 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
299 ms |
41464 KB |
Ok |
2 |
Correct |
297 ms |
41464 KB |
Ok |
3 |
Correct |
296 ms |
41592 KB |
Ok |
4 |
Correct |
301 ms |
41628 KB |
Ok |
5 |
Correct |
300 ms |
41540 KB |
Ok |
6 |
Correct |
635 ms |
46396 KB |
Ok |
7 |
Correct |
553 ms |
46188 KB |
Ok |
8 |
Correct |
899 ms |
48232 KB |
Ok |
9 |
Correct |
690 ms |
48492 KB |
Ok |
10 |
Correct |
521 ms |
44656 KB |
Ok |
11 |
Correct |
682 ms |
47656 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
291 ms |
41464 KB |
Ok |
2 |
Correct |
300 ms |
41464 KB |
Ok |
3 |
Correct |
303 ms |
41592 KB |
Ok |
4 |
Correct |
300 ms |
41464 KB |
Ok |
5 |
Correct |
294 ms |
41592 KB |
Ok |
6 |
Correct |
304 ms |
41592 KB |
Ok |
7 |
Correct |
292 ms |
41592 KB |
Ok |
8 |
Correct |
300 ms |
41592 KB |
Ok |
9 |
Correct |
300 ms |
41592 KB |
Ok |
10 |
Correct |
300 ms |
41592 KB |
Ok |
11 |
Correct |
299 ms |
41464 KB |
Ok |
12 |
Correct |
304 ms |
41464 KB |
Ok |
13 |
Correct |
139 ms |
41468 KB |
Ok |
14 |
Correct |
301 ms |
41596 KB |
Ok |
15 |
Correct |
296 ms |
41592 KB |
Ok |
16 |
Correct |
314 ms |
41508 KB |
Ok |
17 |
Correct |
298 ms |
41592 KB |
Ok |
18 |
Correct |
300 ms |
41720 KB |
Ok |
19 |
Correct |
296 ms |
41592 KB |
Ok |
20 |
Correct |
298 ms |
41592 KB |
Ok |
21 |
Correct |
300 ms |
41592 KB |
Ok |
22 |
Correct |
300 ms |
41596 KB |
Ok |
23 |
Correct |
299 ms |
41592 KB |
Ok |
24 |
Correct |
308 ms |
41724 KB |
Ok |
25 |
Correct |
296 ms |
41592 KB |
Ok |
26 |
Correct |
313 ms |
41596 KB |
Ok |
27 |
Correct |
305 ms |
41592 KB |
Ok |
28 |
Correct |
311 ms |
41592 KB |
Ok |
29 |
Correct |
303 ms |
41464 KB |
Ok |
30 |
Correct |
303 ms |
41464 KB |
Ok |
31 |
Correct |
307 ms |
41592 KB |
Ok |
32 |
Correct |
305 ms |
41592 KB |
Ok |
33 |
Correct |
302 ms |
41592 KB |
Ok |
34 |
Correct |
308 ms |
41716 KB |
Ok |
35 |
Correct |
313 ms |
41848 KB |
Ok |
36 |
Correct |
309 ms |
41592 KB |
Ok |
37 |
Correct |
312 ms |
41720 KB |
Ok |
38 |
Correct |
312 ms |
41592 KB |
Ok |
39 |
Correct |
315 ms |
41592 KB |
Ok |
40 |
Correct |
312 ms |
41592 KB |
Ok |
41 |
Correct |
311 ms |
41720 KB |
Ok |
42 |
Correct |
311 ms |
41592 KB |
Ok |
43 |
Correct |
313 ms |
41720 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
291 ms |
41464 KB |
Ok |
2 |
Correct |
300 ms |
41464 KB |
Ok |
3 |
Correct |
303 ms |
41592 KB |
Ok |
4 |
Correct |
300 ms |
41464 KB |
Ok |
5 |
Correct |
294 ms |
41592 KB |
Ok |
6 |
Correct |
304 ms |
41592 KB |
Ok |
7 |
Correct |
292 ms |
41592 KB |
Ok |
8 |
Correct |
300 ms |
41592 KB |
Ok |
9 |
Correct |
300 ms |
41592 KB |
Ok |
10 |
Correct |
300 ms |
41592 KB |
Ok |
11 |
Correct |
299 ms |
41464 KB |
Ok |
12 |
Correct |
304 ms |
41464 KB |
Ok |
13 |
Correct |
303 ms |
41464 KB |
Ok |
14 |
Correct |
302 ms |
41464 KB |
Ok |
15 |
Correct |
296 ms |
41464 KB |
Ok |
16 |
Correct |
305 ms |
41464 KB |
Ok |
17 |
Correct |
301 ms |
41592 KB |
Ok |
18 |
Correct |
310 ms |
41592 KB |
Ok |
19 |
Correct |
332 ms |
42012 KB |
Ok |
20 |
Correct |
306 ms |
41720 KB |
Ok |
21 |
Correct |
334 ms |
41976 KB |
Ok |
22 |
Correct |
319 ms |
41720 KB |
Ok |
23 |
Correct |
139 ms |
41468 KB |
Ok |
24 |
Correct |
301 ms |
41596 KB |
Ok |
25 |
Correct |
296 ms |
41592 KB |
Ok |
26 |
Correct |
314 ms |
41508 KB |
Ok |
27 |
Correct |
298 ms |
41592 KB |
Ok |
28 |
Correct |
300 ms |
41720 KB |
Ok |
29 |
Correct |
296 ms |
41592 KB |
Ok |
30 |
Correct |
298 ms |
41592 KB |
Ok |
31 |
Correct |
300 ms |
41592 KB |
Ok |
32 |
Correct |
300 ms |
41596 KB |
Ok |
33 |
Correct |
299 ms |
41592 KB |
Ok |
34 |
Correct |
308 ms |
41724 KB |
Ok |
35 |
Correct |
296 ms |
41592 KB |
Ok |
36 |
Correct |
313 ms |
41596 KB |
Ok |
37 |
Correct |
305 ms |
41592 KB |
Ok |
38 |
Correct |
311 ms |
41592 KB |
Ok |
39 |
Correct |
303 ms |
41464 KB |
Ok |
40 |
Correct |
303 ms |
41464 KB |
Ok |
41 |
Correct |
307 ms |
41592 KB |
Ok |
42 |
Correct |
305 ms |
41592 KB |
Ok |
43 |
Correct |
302 ms |
41592 KB |
Ok |
44 |
Correct |
308 ms |
41716 KB |
Ok |
45 |
Correct |
313 ms |
41848 KB |
Ok |
46 |
Correct |
309 ms |
41592 KB |
Ok |
47 |
Correct |
312 ms |
41720 KB |
Ok |
48 |
Correct |
312 ms |
41592 KB |
Ok |
49 |
Correct |
315 ms |
41592 KB |
Ok |
50 |
Correct |
312 ms |
41592 KB |
Ok |
51 |
Correct |
311 ms |
41720 KB |
Ok |
52 |
Correct |
311 ms |
41592 KB |
Ok |
53 |
Correct |
313 ms |
41720 KB |
Ok |
54 |
Correct |
537 ms |
44016 KB |
Ok |
55 |
Correct |
605 ms |
44528 KB |
Ok |
56 |
Correct |
594 ms |
44404 KB |
Ok |
57 |
Correct |
500 ms |
43888 KB |
Ok |
58 |
Correct |
567 ms |
44016 KB |
Ok |
59 |
Correct |
536 ms |
44016 KB |
Ok |
60 |
Correct |
490 ms |
43760 KB |
Ok |
61 |
Correct |
504 ms |
44016 KB |
Ok |
62 |
Correct |
622 ms |
44400 KB |
Ok |
63 |
Correct |
526 ms |
43888 KB |
Ok |
64 |
Correct |
611 ms |
44288 KB |
Ok |
65 |
Correct |
572 ms |
44140 KB |
Ok |
66 |
Correct |
535 ms |
44016 KB |
Ok |
67 |
Correct |
482 ms |
43888 KB |
Ok |
68 |
Correct |
547 ms |
44144 KB |
Ok |
69 |
Correct |
1063 ms |
48112 KB |
Ok |
70 |
Correct |
1150 ms |
49512 KB |
Ok |
71 |
Correct |
973 ms |
47420 KB |
Ok |
72 |
Correct |
1046 ms |
48880 KB |
Ok |
73 |
Correct |
1087 ms |
47852 KB |
Ok |
74 |
Correct |
987 ms |
46868 KB |
Ok |
75 |
Correct |
971 ms |
47016 KB |
Ok |
76 |
Correct |
1052 ms |
49136 KB |
Ok |
77 |
Correct |
920 ms |
46576 KB |
Ok |
78 |
Correct |
1038 ms |
48880 KB |
Ok |
79 |
Correct |
999 ms |
48280 KB |
Ok |
80 |
Correct |
991 ms |
47984 KB |
Ok |
81 |
Correct |
968 ms |
48624 KB |
Ok |
82 |
Correct |
990 ms |
48112 KB |
Ok |
83 |
Correct |
984 ms |
46964 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
291 ms |
41464 KB |
Ok |
2 |
Correct |
300 ms |
41464 KB |
Ok |
3 |
Correct |
303 ms |
41592 KB |
Ok |
4 |
Correct |
300 ms |
41464 KB |
Ok |
5 |
Correct |
294 ms |
41592 KB |
Ok |
6 |
Correct |
304 ms |
41592 KB |
Ok |
7 |
Correct |
292 ms |
41592 KB |
Ok |
8 |
Correct |
300 ms |
41592 KB |
Ok |
9 |
Correct |
300 ms |
41592 KB |
Ok |
10 |
Correct |
300 ms |
41592 KB |
Ok |
11 |
Correct |
299 ms |
41464 KB |
Ok |
12 |
Correct |
304 ms |
41464 KB |
Ok |
13 |
Correct |
303 ms |
41464 KB |
Ok |
14 |
Correct |
302 ms |
41464 KB |
Ok |
15 |
Correct |
296 ms |
41464 KB |
Ok |
16 |
Correct |
305 ms |
41464 KB |
Ok |
17 |
Correct |
301 ms |
41592 KB |
Ok |
18 |
Correct |
310 ms |
41592 KB |
Ok |
19 |
Correct |
332 ms |
42012 KB |
Ok |
20 |
Correct |
306 ms |
41720 KB |
Ok |
21 |
Correct |
334 ms |
41976 KB |
Ok |
22 |
Correct |
319 ms |
41720 KB |
Ok |
23 |
Correct |
139 ms |
41468 KB |
Ok |
24 |
Correct |
301 ms |
41596 KB |
Ok |
25 |
Correct |
296 ms |
41592 KB |
Ok |
26 |
Correct |
314 ms |
41508 KB |
Ok |
27 |
Correct |
298 ms |
41592 KB |
Ok |
28 |
Correct |
300 ms |
41720 KB |
Ok |
29 |
Correct |
296 ms |
41592 KB |
Ok |
30 |
Correct |
298 ms |
41592 KB |
Ok |
31 |
Correct |
300 ms |
41592 KB |
Ok |
32 |
Correct |
300 ms |
41596 KB |
Ok |
33 |
Correct |
299 ms |
41592 KB |
Ok |
34 |
Correct |
299 ms |
41464 KB |
Ok |
35 |
Correct |
297 ms |
41464 KB |
Ok |
36 |
Correct |
296 ms |
41592 KB |
Ok |
37 |
Correct |
301 ms |
41628 KB |
Ok |
38 |
Correct |
300 ms |
41540 KB |
Ok |
39 |
Correct |
635 ms |
46396 KB |
Ok |
40 |
Correct |
553 ms |
46188 KB |
Ok |
41 |
Correct |
899 ms |
48232 KB |
Ok |
42 |
Correct |
690 ms |
48492 KB |
Ok |
43 |
Correct |
521 ms |
44656 KB |
Ok |
44 |
Correct |
682 ms |
47656 KB |
Ok |
45 |
Correct |
308 ms |
41724 KB |
Ok |
46 |
Correct |
296 ms |
41592 KB |
Ok |
47 |
Correct |
313 ms |
41596 KB |
Ok |
48 |
Correct |
305 ms |
41592 KB |
Ok |
49 |
Correct |
311 ms |
41592 KB |
Ok |
50 |
Correct |
303 ms |
41464 KB |
Ok |
51 |
Correct |
303 ms |
41464 KB |
Ok |
52 |
Correct |
307 ms |
41592 KB |
Ok |
53 |
Correct |
305 ms |
41592 KB |
Ok |
54 |
Correct |
302 ms |
41592 KB |
Ok |
55 |
Correct |
308 ms |
41716 KB |
Ok |
56 |
Correct |
313 ms |
41848 KB |
Ok |
57 |
Correct |
309 ms |
41592 KB |
Ok |
58 |
Correct |
312 ms |
41720 KB |
Ok |
59 |
Correct |
312 ms |
41592 KB |
Ok |
60 |
Correct |
315 ms |
41592 KB |
Ok |
61 |
Correct |
312 ms |
41592 KB |
Ok |
62 |
Correct |
311 ms |
41720 KB |
Ok |
63 |
Correct |
311 ms |
41592 KB |
Ok |
64 |
Correct |
313 ms |
41720 KB |
Ok |
65 |
Correct |
537 ms |
44016 KB |
Ok |
66 |
Correct |
605 ms |
44528 KB |
Ok |
67 |
Correct |
594 ms |
44404 KB |
Ok |
68 |
Correct |
500 ms |
43888 KB |
Ok |
69 |
Correct |
567 ms |
44016 KB |
Ok |
70 |
Correct |
536 ms |
44016 KB |
Ok |
71 |
Correct |
490 ms |
43760 KB |
Ok |
72 |
Correct |
504 ms |
44016 KB |
Ok |
73 |
Correct |
622 ms |
44400 KB |
Ok |
74 |
Correct |
526 ms |
43888 KB |
Ok |
75 |
Correct |
611 ms |
44288 KB |
Ok |
76 |
Correct |
572 ms |
44140 KB |
Ok |
77 |
Correct |
535 ms |
44016 KB |
Ok |
78 |
Correct |
482 ms |
43888 KB |
Ok |
79 |
Correct |
547 ms |
44144 KB |
Ok |
80 |
Correct |
1063 ms |
48112 KB |
Ok |
81 |
Correct |
1150 ms |
49512 KB |
Ok |
82 |
Correct |
973 ms |
47420 KB |
Ok |
83 |
Correct |
1046 ms |
48880 KB |
Ok |
84 |
Correct |
1087 ms |
47852 KB |
Ok |
85 |
Correct |
987 ms |
46868 KB |
Ok |
86 |
Correct |
971 ms |
47016 KB |
Ok |
87 |
Correct |
1052 ms |
49136 KB |
Ok |
88 |
Correct |
920 ms |
46576 KB |
Ok |
89 |
Correct |
1038 ms |
48880 KB |
Ok |
90 |
Correct |
999 ms |
48280 KB |
Ok |
91 |
Correct |
991 ms |
47984 KB |
Ok |
92 |
Correct |
968 ms |
48624 KB |
Ok |
93 |
Correct |
990 ms |
48112 KB |
Ok |
94 |
Correct |
984 ms |
46964 KB |
Ok |
95 |
Correct |
969 ms |
48140 KB |
Ok |
96 |
Correct |
1449 ms |
50660 KB |
Ok |
97 |
Correct |
1419 ms |
49968 KB |
Ok |
98 |
Correct |
1028 ms |
49124 KB |
Ok |
99 |
Correct |
1278 ms |
49380 KB |
Ok |
100 |
Correct |
1336 ms |
49252 KB |
Ok |
101 |
Correct |
1289 ms |
50276 KB |
Ok |
102 |
Correct |
1170 ms |
49252 KB |
Ok |
103 |
Correct |
1247 ms |
49764 KB |
Ok |
104 |
Correct |
1464 ms |
50628 KB |
Ok |
105 |
Correct |
1427 ms |
50472 KB |
Ok |
106 |
Correct |
1115 ms |
49924 KB |
Ok |
107 |
Correct |
1294 ms |
50264 KB |
Ok |
108 |
Correct |
1511 ms |
50644 KB |
Ok |
109 |
Correct |
1269 ms |
50660 KB |
Ok |
110 |
Execution timed out |
2094 ms |
53872 KB |
Time limit exceeded |
111 |
Halted |
0 ms |
0 KB |
- |