#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 = 5e5 + 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 = max(n - 1, m - 1), 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;
| ~~~~~~~~~~~^~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
149 ms |
20856 KB |
Ok |
2 |
Correct |
150 ms |
20984 KB |
Ok |
3 |
Correct |
149 ms |
20984 KB |
Ok |
4 |
Correct |
150 ms |
21112 KB |
Ok |
5 |
Correct |
150 ms |
20864 KB |
Ok |
6 |
Correct |
149 ms |
20864 KB |
Ok |
7 |
Correct |
152 ms |
20984 KB |
Ok |
8 |
Correct |
150 ms |
20856 KB |
Ok |
9 |
Correct |
151 ms |
20856 KB |
Ok |
10 |
Correct |
150 ms |
20984 KB |
Ok |
11 |
Correct |
148 ms |
21068 KB |
Ok |
12 |
Correct |
151 ms |
20864 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
151 ms |
20856 KB |
Ok |
2 |
Correct |
150 ms |
20948 KB |
Ok |
3 |
Correct |
147 ms |
20984 KB |
Ok |
4 |
Correct |
144 ms |
20856 KB |
Ok |
5 |
Correct |
138 ms |
20860 KB |
Ok |
6 |
Correct |
157 ms |
21112 KB |
Ok |
7 |
Correct |
175 ms |
21496 KB |
Ok |
8 |
Correct |
164 ms |
21240 KB |
Ok |
9 |
Correct |
176 ms |
21752 KB |
Ok |
10 |
Correct |
171 ms |
21368 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
20856 KB |
Ok |
2 |
Correct |
148 ms |
20944 KB |
Ok |
3 |
Correct |
149 ms |
20864 KB |
Ok |
4 |
Correct |
149 ms |
21056 KB |
Ok |
5 |
Correct |
149 ms |
20984 KB |
Ok |
6 |
Correct |
149 ms |
20944 KB |
Ok |
7 |
Correct |
146 ms |
20948 KB |
Ok |
8 |
Correct |
148 ms |
20856 KB |
Ok |
9 |
Correct |
147 ms |
20856 KB |
Ok |
10 |
Correct |
150 ms |
20856 KB |
Ok |
11 |
Correct |
147 ms |
20948 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
148 ms |
20856 KB |
Ok |
2 |
Correct |
150 ms |
20948 KB |
Ok |
3 |
Correct |
140 ms |
20856 KB |
Ok |
4 |
Correct |
148 ms |
20984 KB |
Ok |
5 |
Correct |
139 ms |
20856 KB |
Ok |
6 |
Correct |
508 ms |
27172 KB |
Ok |
7 |
Correct |
425 ms |
27088 KB |
Ok |
8 |
Correct |
758 ms |
29164 KB |
Ok |
9 |
Correct |
574 ms |
29164 KB |
Ok |
10 |
Correct |
388 ms |
25068 KB |
Ok |
11 |
Correct |
561 ms |
28524 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
149 ms |
20856 KB |
Ok |
2 |
Correct |
150 ms |
20984 KB |
Ok |
3 |
Correct |
149 ms |
20984 KB |
Ok |
4 |
Correct |
150 ms |
21112 KB |
Ok |
5 |
Correct |
150 ms |
20864 KB |
Ok |
6 |
Correct |
149 ms |
20864 KB |
Ok |
7 |
Correct |
152 ms |
20984 KB |
Ok |
8 |
Correct |
150 ms |
20856 KB |
Ok |
9 |
Correct |
151 ms |
20856 KB |
Ok |
10 |
Correct |
150 ms |
20984 KB |
Ok |
11 |
Correct |
148 ms |
21068 KB |
Ok |
12 |
Correct |
151 ms |
20864 KB |
Ok |
13 |
Correct |
69 ms |
20856 KB |
Ok |
14 |
Correct |
148 ms |
20944 KB |
Ok |
15 |
Correct |
149 ms |
20864 KB |
Ok |
16 |
Correct |
149 ms |
21056 KB |
Ok |
17 |
Correct |
149 ms |
20984 KB |
Ok |
18 |
Correct |
149 ms |
20944 KB |
Ok |
19 |
Correct |
146 ms |
20948 KB |
Ok |
20 |
Correct |
148 ms |
20856 KB |
Ok |
21 |
Correct |
147 ms |
20856 KB |
Ok |
22 |
Correct |
150 ms |
20856 KB |
Ok |
23 |
Correct |
147 ms |
20948 KB |
Ok |
24 |
Correct |
157 ms |
20984 KB |
Ok |
25 |
Correct |
156 ms |
20992 KB |
Ok |
26 |
Correct |
157 ms |
20984 KB |
Ok |
27 |
Correct |
145 ms |
20984 KB |
Ok |
28 |
Correct |
153 ms |
20984 KB |
Ok |
29 |
Correct |
154 ms |
20984 KB |
Ok |
30 |
Correct |
154 ms |
21028 KB |
Ok |
31 |
Correct |
154 ms |
21056 KB |
Ok |
32 |
Correct |
155 ms |
21052 KB |
Ok |
33 |
Correct |
151 ms |
20984 KB |
Ok |
34 |
Correct |
164 ms |
21112 KB |
Ok |
35 |
Correct |
162 ms |
21112 KB |
Ok |
36 |
Correct |
152 ms |
21112 KB |
Ok |
37 |
Correct |
155 ms |
21244 KB |
Ok |
38 |
Correct |
161 ms |
21112 KB |
Ok |
39 |
Correct |
163 ms |
21240 KB |
Ok |
40 |
Correct |
153 ms |
21116 KB |
Ok |
41 |
Correct |
164 ms |
21112 KB |
Ok |
42 |
Correct |
155 ms |
21112 KB |
Ok |
43 |
Correct |
165 ms |
21240 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
149 ms |
20856 KB |
Ok |
2 |
Correct |
150 ms |
20984 KB |
Ok |
3 |
Correct |
149 ms |
20984 KB |
Ok |
4 |
Correct |
150 ms |
21112 KB |
Ok |
5 |
Correct |
150 ms |
20864 KB |
Ok |
6 |
Correct |
149 ms |
20864 KB |
Ok |
7 |
Correct |
152 ms |
20984 KB |
Ok |
8 |
Correct |
150 ms |
20856 KB |
Ok |
9 |
Correct |
151 ms |
20856 KB |
Ok |
10 |
Correct |
150 ms |
20984 KB |
Ok |
11 |
Correct |
148 ms |
21068 KB |
Ok |
12 |
Correct |
151 ms |
20864 KB |
Ok |
13 |
Correct |
151 ms |
20856 KB |
Ok |
14 |
Correct |
150 ms |
20948 KB |
Ok |
15 |
Correct |
147 ms |
20984 KB |
Ok |
16 |
Correct |
144 ms |
20856 KB |
Ok |
17 |
Correct |
138 ms |
20860 KB |
Ok |
18 |
Correct |
157 ms |
21112 KB |
Ok |
19 |
Correct |
175 ms |
21496 KB |
Ok |
20 |
Correct |
164 ms |
21240 KB |
Ok |
21 |
Correct |
176 ms |
21752 KB |
Ok |
22 |
Correct |
171 ms |
21368 KB |
Ok |
23 |
Correct |
69 ms |
20856 KB |
Ok |
24 |
Correct |
148 ms |
20944 KB |
Ok |
25 |
Correct |
149 ms |
20864 KB |
Ok |
26 |
Correct |
149 ms |
21056 KB |
Ok |
27 |
Correct |
149 ms |
20984 KB |
Ok |
28 |
Correct |
149 ms |
20944 KB |
Ok |
29 |
Correct |
146 ms |
20948 KB |
Ok |
30 |
Correct |
148 ms |
20856 KB |
Ok |
31 |
Correct |
147 ms |
20856 KB |
Ok |
32 |
Correct |
150 ms |
20856 KB |
Ok |
33 |
Correct |
147 ms |
20948 KB |
Ok |
34 |
Correct |
157 ms |
20984 KB |
Ok |
35 |
Correct |
156 ms |
20992 KB |
Ok |
36 |
Correct |
157 ms |
20984 KB |
Ok |
37 |
Correct |
145 ms |
20984 KB |
Ok |
38 |
Correct |
153 ms |
20984 KB |
Ok |
39 |
Correct |
154 ms |
20984 KB |
Ok |
40 |
Correct |
154 ms |
21028 KB |
Ok |
41 |
Correct |
154 ms |
21056 KB |
Ok |
42 |
Correct |
155 ms |
21052 KB |
Ok |
43 |
Correct |
151 ms |
20984 KB |
Ok |
44 |
Correct |
164 ms |
21112 KB |
Ok |
45 |
Correct |
162 ms |
21112 KB |
Ok |
46 |
Correct |
152 ms |
21112 KB |
Ok |
47 |
Correct |
155 ms |
21244 KB |
Ok |
48 |
Correct |
161 ms |
21112 KB |
Ok |
49 |
Correct |
163 ms |
21240 KB |
Ok |
50 |
Correct |
153 ms |
21116 KB |
Ok |
51 |
Correct |
164 ms |
21112 KB |
Ok |
52 |
Correct |
155 ms |
21112 KB |
Ok |
53 |
Correct |
165 ms |
21240 KB |
Ok |
54 |
Correct |
409 ms |
24336 KB |
Ok |
55 |
Correct |
477 ms |
24436 KB |
Ok |
56 |
Correct |
468 ms |
24564 KB |
Ok |
57 |
Correct |
375 ms |
24224 KB |
Ok |
58 |
Correct |
434 ms |
24308 KB |
Ok |
59 |
Correct |
417 ms |
24364 KB |
Ok |
60 |
Correct |
374 ms |
23884 KB |
Ok |
61 |
Correct |
379 ms |
24052 KB |
Ok |
62 |
Correct |
495 ms |
24560 KB |
Ok |
63 |
Correct |
395 ms |
24172 KB |
Ok |
64 |
Correct |
482 ms |
24556 KB |
Ok |
65 |
Correct |
442 ms |
24564 KB |
Ok |
66 |
Correct |
419 ms |
24308 KB |
Ok |
67 |
Correct |
357 ms |
24152 KB |
Ok |
68 |
Correct |
416 ms |
24304 KB |
Ok |
69 |
Correct |
995 ms |
28616 KB |
Ok |
70 |
Correct |
973 ms |
29684 KB |
Ok |
71 |
Correct |
850 ms |
27764 KB |
Ok |
72 |
Correct |
877 ms |
28788 KB |
Ok |
73 |
Correct |
960 ms |
28152 KB |
Ok |
74 |
Correct |
843 ms |
27508 KB |
Ok |
75 |
Correct |
886 ms |
27248 KB |
Ok |
76 |
Correct |
1030 ms |
29424 KB |
Ok |
77 |
Correct |
807 ms |
26864 KB |
Ok |
78 |
Correct |
896 ms |
29168 KB |
Ok |
79 |
Correct |
982 ms |
28792 KB |
Ok |
80 |
Correct |
841 ms |
28292 KB |
Ok |
81 |
Correct |
940 ms |
28880 KB |
Ok |
82 |
Correct |
888 ms |
28784 KB |
Ok |
83 |
Correct |
827 ms |
27504 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
149 ms |
20856 KB |
Ok |
2 |
Correct |
150 ms |
20984 KB |
Ok |
3 |
Correct |
149 ms |
20984 KB |
Ok |
4 |
Correct |
150 ms |
21112 KB |
Ok |
5 |
Correct |
150 ms |
20864 KB |
Ok |
6 |
Correct |
149 ms |
20864 KB |
Ok |
7 |
Correct |
152 ms |
20984 KB |
Ok |
8 |
Correct |
150 ms |
20856 KB |
Ok |
9 |
Correct |
151 ms |
20856 KB |
Ok |
10 |
Correct |
150 ms |
20984 KB |
Ok |
11 |
Correct |
148 ms |
21068 KB |
Ok |
12 |
Correct |
151 ms |
20864 KB |
Ok |
13 |
Correct |
151 ms |
20856 KB |
Ok |
14 |
Correct |
150 ms |
20948 KB |
Ok |
15 |
Correct |
147 ms |
20984 KB |
Ok |
16 |
Correct |
144 ms |
20856 KB |
Ok |
17 |
Correct |
138 ms |
20860 KB |
Ok |
18 |
Correct |
157 ms |
21112 KB |
Ok |
19 |
Correct |
175 ms |
21496 KB |
Ok |
20 |
Correct |
164 ms |
21240 KB |
Ok |
21 |
Correct |
176 ms |
21752 KB |
Ok |
22 |
Correct |
171 ms |
21368 KB |
Ok |
23 |
Correct |
69 ms |
20856 KB |
Ok |
24 |
Correct |
148 ms |
20944 KB |
Ok |
25 |
Correct |
149 ms |
20864 KB |
Ok |
26 |
Correct |
149 ms |
21056 KB |
Ok |
27 |
Correct |
149 ms |
20984 KB |
Ok |
28 |
Correct |
149 ms |
20944 KB |
Ok |
29 |
Correct |
146 ms |
20948 KB |
Ok |
30 |
Correct |
148 ms |
20856 KB |
Ok |
31 |
Correct |
147 ms |
20856 KB |
Ok |
32 |
Correct |
150 ms |
20856 KB |
Ok |
33 |
Correct |
147 ms |
20948 KB |
Ok |
34 |
Correct |
148 ms |
20856 KB |
Ok |
35 |
Correct |
150 ms |
20948 KB |
Ok |
36 |
Correct |
140 ms |
20856 KB |
Ok |
37 |
Correct |
148 ms |
20984 KB |
Ok |
38 |
Correct |
139 ms |
20856 KB |
Ok |
39 |
Correct |
508 ms |
27172 KB |
Ok |
40 |
Correct |
425 ms |
27088 KB |
Ok |
41 |
Correct |
758 ms |
29164 KB |
Ok |
42 |
Correct |
574 ms |
29164 KB |
Ok |
43 |
Correct |
388 ms |
25068 KB |
Ok |
44 |
Correct |
561 ms |
28524 KB |
Ok |
45 |
Correct |
157 ms |
20984 KB |
Ok |
46 |
Correct |
156 ms |
20992 KB |
Ok |
47 |
Correct |
157 ms |
20984 KB |
Ok |
48 |
Correct |
145 ms |
20984 KB |
Ok |
49 |
Correct |
153 ms |
20984 KB |
Ok |
50 |
Correct |
154 ms |
20984 KB |
Ok |
51 |
Correct |
154 ms |
21028 KB |
Ok |
52 |
Correct |
154 ms |
21056 KB |
Ok |
53 |
Correct |
155 ms |
21052 KB |
Ok |
54 |
Correct |
151 ms |
20984 KB |
Ok |
55 |
Correct |
164 ms |
21112 KB |
Ok |
56 |
Correct |
162 ms |
21112 KB |
Ok |
57 |
Correct |
152 ms |
21112 KB |
Ok |
58 |
Correct |
155 ms |
21244 KB |
Ok |
59 |
Correct |
161 ms |
21112 KB |
Ok |
60 |
Correct |
163 ms |
21240 KB |
Ok |
61 |
Correct |
153 ms |
21116 KB |
Ok |
62 |
Correct |
164 ms |
21112 KB |
Ok |
63 |
Correct |
155 ms |
21112 KB |
Ok |
64 |
Correct |
165 ms |
21240 KB |
Ok |
65 |
Correct |
409 ms |
24336 KB |
Ok |
66 |
Correct |
477 ms |
24436 KB |
Ok |
67 |
Correct |
468 ms |
24564 KB |
Ok |
68 |
Correct |
375 ms |
24224 KB |
Ok |
69 |
Correct |
434 ms |
24308 KB |
Ok |
70 |
Correct |
417 ms |
24364 KB |
Ok |
71 |
Correct |
374 ms |
23884 KB |
Ok |
72 |
Correct |
379 ms |
24052 KB |
Ok |
73 |
Correct |
495 ms |
24560 KB |
Ok |
74 |
Correct |
395 ms |
24172 KB |
Ok |
75 |
Correct |
482 ms |
24556 KB |
Ok |
76 |
Correct |
442 ms |
24564 KB |
Ok |
77 |
Correct |
419 ms |
24308 KB |
Ok |
78 |
Correct |
357 ms |
24152 KB |
Ok |
79 |
Correct |
416 ms |
24304 KB |
Ok |
80 |
Correct |
995 ms |
28616 KB |
Ok |
81 |
Correct |
973 ms |
29684 KB |
Ok |
82 |
Correct |
850 ms |
27764 KB |
Ok |
83 |
Correct |
877 ms |
28788 KB |
Ok |
84 |
Correct |
960 ms |
28152 KB |
Ok |
85 |
Correct |
843 ms |
27508 KB |
Ok |
86 |
Correct |
886 ms |
27248 KB |
Ok |
87 |
Correct |
1030 ms |
29424 KB |
Ok |
88 |
Correct |
807 ms |
26864 KB |
Ok |
89 |
Correct |
896 ms |
29168 KB |
Ok |
90 |
Correct |
982 ms |
28792 KB |
Ok |
91 |
Correct |
841 ms |
28292 KB |
Ok |
92 |
Correct |
940 ms |
28880 KB |
Ok |
93 |
Correct |
888 ms |
28784 KB |
Ok |
94 |
Correct |
827 ms |
27504 KB |
Ok |
95 |
Correct |
860 ms |
30716 KB |
Ok |
96 |
Correct |
1264 ms |
36324 KB |
Ok |
97 |
Correct |
1266 ms |
32484 KB |
Ok |
98 |
Correct |
884 ms |
31720 KB |
Ok |
99 |
Correct |
1147 ms |
31960 KB |
Ok |
100 |
Correct |
1153 ms |
31976 KB |
Ok |
101 |
Correct |
1147 ms |
33000 KB |
Ok |
102 |
Correct |
1064 ms |
32152 KB |
Ok |
103 |
Correct |
1053 ms |
32712 KB |
Ok |
104 |
Correct |
1299 ms |
33380 KB |
Ok |
105 |
Correct |
1314 ms |
35964 KB |
Ok |
106 |
Correct |
977 ms |
35428 KB |
Ok |
107 |
Correct |
1124 ms |
32944 KB |
Ok |
108 |
Correct |
1310 ms |
35944 KB |
Ok |
109 |
Correct |
1137 ms |
36192 KB |
Ok |
110 |
Execution timed out |
2080 ms |
39396 KB |
Time limit exceeded |
111 |
Halted |
0 ms |
0 KB |
- |