#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() { cerr << endl; }
template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l)==r], ++l; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
const int MAX_N = 300010;
bool valid(int n, int m, int len, bool output = false) {
vector<int> indeg(len + 1);
for (int i = 1;i <= len;++i) {
if (i >= n) {
++indeg[i];
}
if (i >= m) {
++indeg[i - m];
}
}
vector<int> q;
for (int i = 0;i <= len;++i) if (indeg[i] == 0)
q.pb(i);
if (q.empty()) return false;
for (int i = 0;i < q.size();++i) {
int x = q[i];
if (x >= m) {
if (--indeg[x - m] == 0)
q.pb(x - m);
}
if (x + n <= len) {
if (--indeg[x + n] == 0)
q.pb(x + n);
}
}
if (q.size() != len + 1) return false;
if (output) {
cout << len << '\n';
vector<int> res(len + 1);
int lst = len + 10;
for (int i = 0;i <= len;++i) {
int x = q[i];
res[x] = --lst;
if (x == 0) res[x] = 0;
lst = res[x];
}
for (int i = 1;i <= len;++i)
cout << res[i] - res[i-1] << " \n"[i==len];
}
return true;
};
void solve() {
int n, m;
cin >> n >> m;
int U = 4;
while (valid(n, m, U<<1)) U <<= 1;
int res = 0;
while (U) {
if (valid(n, m, res | U))
res |= U;
U >>= 1;
}
valid(n, m, res, true);
}
int32_t main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int T;
cin >> T;
while (T--)
solve();
}
Compilation message
sequence.cpp: In function 'bool valid(int, int, int, bool)':
sequence.cpp:37:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for (int i = 0;i < q.size();++i) {
| ~~^~~~~~~~~~
sequence.cpp:50:15: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
50 | if (q.size() != len + 1) return false;
| ~~~~~~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Ok |
2 |
Correct |
1 ms |
364 KB |
Ok |
3 |
Correct |
1 ms |
364 KB |
Ok |
4 |
Correct |
1 ms |
512 KB |
Ok |
5 |
Correct |
1 ms |
364 KB |
Ok |
6 |
Correct |
1 ms |
364 KB |
Ok |
7 |
Correct |
1 ms |
364 KB |
Ok |
8 |
Correct |
1 ms |
364 KB |
Ok |
9 |
Correct |
1 ms |
364 KB |
Ok |
10 |
Correct |
1 ms |
364 KB |
Ok |
11 |
Correct |
1 ms |
364 KB |
Ok |
12 |
Correct |
1 ms |
364 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Ok |
2 |
Correct |
1 ms |
364 KB |
Ok |
3 |
Correct |
1 ms |
364 KB |
Ok |
4 |
Correct |
1 ms |
364 KB |
Ok |
5 |
Correct |
1 ms |
364 KB |
Ok |
6 |
Correct |
5 ms |
492 KB |
Ok |
7 |
Correct |
26 ms |
860 KB |
Ok |
8 |
Correct |
13 ms |
620 KB |
Ok |
9 |
Correct |
29 ms |
1012 KB |
Ok |
10 |
Correct |
18 ms |
620 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Ok |
2 |
Correct |
1 ms |
364 KB |
Ok |
3 |
Correct |
1 ms |
364 KB |
Ok |
4 |
Correct |
1 ms |
364 KB |
Ok |
5 |
Correct |
1 ms |
364 KB |
Ok |
6 |
Correct |
1 ms |
364 KB |
Ok |
7 |
Correct |
1 ms |
364 KB |
Ok |
8 |
Correct |
1 ms |
364 KB |
Ok |
9 |
Correct |
1 ms |
364 KB |
Ok |
10 |
Correct |
1 ms |
364 KB |
Ok |
11 |
Correct |
1 ms |
384 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Ok |
2 |
Correct |
1 ms |
364 KB |
Ok |
3 |
Correct |
1 ms |
364 KB |
Ok |
4 |
Correct |
1 ms |
364 KB |
Ok |
5 |
Correct |
1 ms |
364 KB |
Ok |
6 |
Correct |
258 ms |
4984 KB |
Ok |
7 |
Correct |
246 ms |
3964 KB |
Ok |
8 |
Correct |
471 ms |
7124 KB |
Ok |
9 |
Correct |
349 ms |
7956 KB |
Ok |
10 |
Correct |
197 ms |
3088 KB |
Ok |
11 |
Correct |
360 ms |
6888 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Ok |
2 |
Correct |
1 ms |
364 KB |
Ok |
3 |
Correct |
1 ms |
364 KB |
Ok |
4 |
Correct |
1 ms |
512 KB |
Ok |
5 |
Correct |
1 ms |
364 KB |
Ok |
6 |
Correct |
1 ms |
364 KB |
Ok |
7 |
Correct |
1 ms |
364 KB |
Ok |
8 |
Correct |
1 ms |
364 KB |
Ok |
9 |
Correct |
1 ms |
364 KB |
Ok |
10 |
Correct |
1 ms |
364 KB |
Ok |
11 |
Correct |
1 ms |
364 KB |
Ok |
12 |
Correct |
1 ms |
364 KB |
Ok |
13 |
Correct |
1 ms |
364 KB |
Ok |
14 |
Correct |
1 ms |
364 KB |
Ok |
15 |
Correct |
1 ms |
364 KB |
Ok |
16 |
Correct |
1 ms |
364 KB |
Ok |
17 |
Correct |
1 ms |
364 KB |
Ok |
18 |
Correct |
1 ms |
364 KB |
Ok |
19 |
Correct |
1 ms |
364 KB |
Ok |
20 |
Correct |
1 ms |
364 KB |
Ok |
21 |
Correct |
1 ms |
364 KB |
Ok |
22 |
Correct |
1 ms |
364 KB |
Ok |
23 |
Correct |
1 ms |
384 KB |
Ok |
24 |
Correct |
5 ms |
492 KB |
Ok |
25 |
Correct |
5 ms |
492 KB |
Ok |
26 |
Correct |
6 ms |
492 KB |
Ok |
27 |
Correct |
6 ms |
492 KB |
Ok |
28 |
Correct |
5 ms |
364 KB |
Ok |
29 |
Correct |
4 ms |
364 KB |
Ok |
30 |
Correct |
4 ms |
364 KB |
Ok |
31 |
Correct |
5 ms |
492 KB |
Ok |
32 |
Correct |
5 ms |
492 KB |
Ok |
33 |
Correct |
5 ms |
364 KB |
Ok |
34 |
Correct |
9 ms |
492 KB |
Ok |
35 |
Correct |
8 ms |
620 KB |
Ok |
36 |
Correct |
9 ms |
492 KB |
Ok |
37 |
Correct |
10 ms |
492 KB |
Ok |
38 |
Correct |
10 ms |
492 KB |
Ok |
39 |
Correct |
9 ms |
492 KB |
Ok |
40 |
Correct |
9 ms |
492 KB |
Ok |
41 |
Correct |
8 ms |
492 KB |
Ok |
42 |
Correct |
9 ms |
492 KB |
Ok |
43 |
Correct |
9 ms |
492 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Ok |
2 |
Correct |
1 ms |
364 KB |
Ok |
3 |
Correct |
1 ms |
364 KB |
Ok |
4 |
Correct |
1 ms |
512 KB |
Ok |
5 |
Correct |
1 ms |
364 KB |
Ok |
6 |
Correct |
1 ms |
364 KB |
Ok |
7 |
Correct |
1 ms |
364 KB |
Ok |
8 |
Correct |
1 ms |
364 KB |
Ok |
9 |
Correct |
1 ms |
364 KB |
Ok |
10 |
Correct |
1 ms |
364 KB |
Ok |
11 |
Correct |
1 ms |
364 KB |
Ok |
12 |
Correct |
1 ms |
364 KB |
Ok |
13 |
Correct |
1 ms |
364 KB |
Ok |
14 |
Correct |
1 ms |
364 KB |
Ok |
15 |
Correct |
1 ms |
364 KB |
Ok |
16 |
Correct |
1 ms |
364 KB |
Ok |
17 |
Correct |
1 ms |
364 KB |
Ok |
18 |
Correct |
5 ms |
492 KB |
Ok |
19 |
Correct |
26 ms |
860 KB |
Ok |
20 |
Correct |
13 ms |
620 KB |
Ok |
21 |
Correct |
29 ms |
1012 KB |
Ok |
22 |
Correct |
18 ms |
620 KB |
Ok |
23 |
Correct |
1 ms |
364 KB |
Ok |
24 |
Correct |
1 ms |
364 KB |
Ok |
25 |
Correct |
1 ms |
364 KB |
Ok |
26 |
Correct |
1 ms |
364 KB |
Ok |
27 |
Correct |
1 ms |
364 KB |
Ok |
28 |
Correct |
1 ms |
364 KB |
Ok |
29 |
Correct |
1 ms |
364 KB |
Ok |
30 |
Correct |
1 ms |
364 KB |
Ok |
31 |
Correct |
1 ms |
364 KB |
Ok |
32 |
Correct |
1 ms |
364 KB |
Ok |
33 |
Correct |
1 ms |
384 KB |
Ok |
34 |
Correct |
5 ms |
492 KB |
Ok |
35 |
Correct |
5 ms |
492 KB |
Ok |
36 |
Correct |
6 ms |
492 KB |
Ok |
37 |
Correct |
6 ms |
492 KB |
Ok |
38 |
Correct |
5 ms |
364 KB |
Ok |
39 |
Correct |
4 ms |
364 KB |
Ok |
40 |
Correct |
4 ms |
364 KB |
Ok |
41 |
Correct |
5 ms |
492 KB |
Ok |
42 |
Correct |
5 ms |
492 KB |
Ok |
43 |
Correct |
5 ms |
364 KB |
Ok |
44 |
Correct |
9 ms |
492 KB |
Ok |
45 |
Correct |
8 ms |
620 KB |
Ok |
46 |
Correct |
9 ms |
492 KB |
Ok |
47 |
Correct |
10 ms |
492 KB |
Ok |
48 |
Correct |
10 ms |
492 KB |
Ok |
49 |
Correct |
9 ms |
492 KB |
Ok |
50 |
Correct |
9 ms |
492 KB |
Ok |
51 |
Correct |
8 ms |
492 KB |
Ok |
52 |
Correct |
9 ms |
492 KB |
Ok |
53 |
Correct |
9 ms |
492 KB |
Ok |
54 |
Correct |
236 ms |
3568 KB |
Ok |
55 |
Correct |
298 ms |
3816 KB |
Ok |
56 |
Correct |
292 ms |
3616 KB |
Ok |
57 |
Correct |
206 ms |
3060 KB |
Ok |
58 |
Correct |
257 ms |
3540 KB |
Ok |
59 |
Correct |
250 ms |
3336 KB |
Ok |
60 |
Correct |
229 ms |
3212 KB |
Ok |
61 |
Correct |
208 ms |
3240 KB |
Ok |
62 |
Correct |
313 ms |
3692 KB |
Ok |
63 |
Correct |
230 ms |
3124 KB |
Ok |
64 |
Correct |
308 ms |
3836 KB |
Ok |
65 |
Correct |
285 ms |
3824 KB |
Ok |
66 |
Correct |
254 ms |
3496 KB |
Ok |
67 |
Correct |
209 ms |
3376 KB |
Ok |
68 |
Correct |
250 ms |
3252 KB |
Ok |
69 |
Correct |
346 ms |
7288 KB |
Ok |
70 |
Correct |
308 ms |
8404 KB |
Ok |
71 |
Correct |
326 ms |
6780 KB |
Ok |
72 |
Correct |
362 ms |
7488 KB |
Ok |
73 |
Correct |
327 ms |
7320 KB |
Ok |
74 |
Correct |
321 ms |
6384 KB |
Ok |
75 |
Correct |
334 ms |
6456 KB |
Ok |
76 |
Correct |
318 ms |
7976 KB |
Ok |
77 |
Correct |
331 ms |
6072 KB |
Ok |
78 |
Correct |
315 ms |
7720 KB |
Ok |
79 |
Correct |
333 ms |
7356 KB |
Ok |
80 |
Correct |
323 ms |
7200 KB |
Ok |
81 |
Correct |
328 ms |
7680 KB |
Ok |
82 |
Correct |
329 ms |
7488 KB |
Ok |
83 |
Correct |
343 ms |
6412 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Ok |
2 |
Correct |
1 ms |
364 KB |
Ok |
3 |
Correct |
1 ms |
364 KB |
Ok |
4 |
Correct |
1 ms |
512 KB |
Ok |
5 |
Correct |
1 ms |
364 KB |
Ok |
6 |
Correct |
1 ms |
364 KB |
Ok |
7 |
Correct |
1 ms |
364 KB |
Ok |
8 |
Correct |
1 ms |
364 KB |
Ok |
9 |
Correct |
1 ms |
364 KB |
Ok |
10 |
Correct |
1 ms |
364 KB |
Ok |
11 |
Correct |
1 ms |
364 KB |
Ok |
12 |
Correct |
1 ms |
364 KB |
Ok |
13 |
Correct |
1 ms |
364 KB |
Ok |
14 |
Correct |
1 ms |
364 KB |
Ok |
15 |
Correct |
1 ms |
364 KB |
Ok |
16 |
Correct |
1 ms |
364 KB |
Ok |
17 |
Correct |
1 ms |
364 KB |
Ok |
18 |
Correct |
5 ms |
492 KB |
Ok |
19 |
Correct |
26 ms |
860 KB |
Ok |
20 |
Correct |
13 ms |
620 KB |
Ok |
21 |
Correct |
29 ms |
1012 KB |
Ok |
22 |
Correct |
18 ms |
620 KB |
Ok |
23 |
Correct |
1 ms |
364 KB |
Ok |
24 |
Correct |
1 ms |
364 KB |
Ok |
25 |
Correct |
1 ms |
364 KB |
Ok |
26 |
Correct |
1 ms |
364 KB |
Ok |
27 |
Correct |
1 ms |
364 KB |
Ok |
28 |
Correct |
1 ms |
364 KB |
Ok |
29 |
Correct |
1 ms |
364 KB |
Ok |
30 |
Correct |
1 ms |
364 KB |
Ok |
31 |
Correct |
1 ms |
364 KB |
Ok |
32 |
Correct |
1 ms |
364 KB |
Ok |
33 |
Correct |
1 ms |
384 KB |
Ok |
34 |
Correct |
1 ms |
512 KB |
Ok |
35 |
Correct |
1 ms |
364 KB |
Ok |
36 |
Correct |
1 ms |
364 KB |
Ok |
37 |
Correct |
1 ms |
364 KB |
Ok |
38 |
Correct |
1 ms |
364 KB |
Ok |
39 |
Correct |
258 ms |
4984 KB |
Ok |
40 |
Correct |
246 ms |
3964 KB |
Ok |
41 |
Correct |
471 ms |
7124 KB |
Ok |
42 |
Correct |
349 ms |
7956 KB |
Ok |
43 |
Correct |
197 ms |
3088 KB |
Ok |
44 |
Correct |
360 ms |
6888 KB |
Ok |
45 |
Correct |
5 ms |
492 KB |
Ok |
46 |
Correct |
5 ms |
492 KB |
Ok |
47 |
Correct |
6 ms |
492 KB |
Ok |
48 |
Correct |
6 ms |
492 KB |
Ok |
49 |
Correct |
5 ms |
364 KB |
Ok |
50 |
Correct |
4 ms |
364 KB |
Ok |
51 |
Correct |
4 ms |
364 KB |
Ok |
52 |
Correct |
5 ms |
492 KB |
Ok |
53 |
Correct |
5 ms |
492 KB |
Ok |
54 |
Correct |
5 ms |
364 KB |
Ok |
55 |
Correct |
9 ms |
492 KB |
Ok |
56 |
Correct |
8 ms |
620 KB |
Ok |
57 |
Correct |
9 ms |
492 KB |
Ok |
58 |
Correct |
10 ms |
492 KB |
Ok |
59 |
Correct |
10 ms |
492 KB |
Ok |
60 |
Correct |
9 ms |
492 KB |
Ok |
61 |
Correct |
9 ms |
492 KB |
Ok |
62 |
Correct |
8 ms |
492 KB |
Ok |
63 |
Correct |
9 ms |
492 KB |
Ok |
64 |
Correct |
9 ms |
492 KB |
Ok |
65 |
Correct |
236 ms |
3568 KB |
Ok |
66 |
Correct |
298 ms |
3816 KB |
Ok |
67 |
Correct |
292 ms |
3616 KB |
Ok |
68 |
Correct |
206 ms |
3060 KB |
Ok |
69 |
Correct |
257 ms |
3540 KB |
Ok |
70 |
Correct |
250 ms |
3336 KB |
Ok |
71 |
Correct |
229 ms |
3212 KB |
Ok |
72 |
Correct |
208 ms |
3240 KB |
Ok |
73 |
Correct |
313 ms |
3692 KB |
Ok |
74 |
Correct |
230 ms |
3124 KB |
Ok |
75 |
Correct |
308 ms |
3836 KB |
Ok |
76 |
Correct |
285 ms |
3824 KB |
Ok |
77 |
Correct |
254 ms |
3496 KB |
Ok |
78 |
Correct |
209 ms |
3376 KB |
Ok |
79 |
Correct |
250 ms |
3252 KB |
Ok |
80 |
Correct |
346 ms |
7288 KB |
Ok |
81 |
Correct |
308 ms |
8404 KB |
Ok |
82 |
Correct |
326 ms |
6780 KB |
Ok |
83 |
Correct |
362 ms |
7488 KB |
Ok |
84 |
Correct |
327 ms |
7320 KB |
Ok |
85 |
Correct |
321 ms |
6384 KB |
Ok |
86 |
Correct |
334 ms |
6456 KB |
Ok |
87 |
Correct |
318 ms |
7976 KB |
Ok |
88 |
Correct |
331 ms |
6072 KB |
Ok |
89 |
Correct |
315 ms |
7720 KB |
Ok |
90 |
Correct |
333 ms |
7356 KB |
Ok |
91 |
Correct |
323 ms |
7200 KB |
Ok |
92 |
Correct |
328 ms |
7680 KB |
Ok |
93 |
Correct |
329 ms |
7488 KB |
Ok |
94 |
Correct |
343 ms |
6412 KB |
Ok |
95 |
Correct |
676 ms |
8224 KB |
Ok |
96 |
Correct |
934 ms |
12084 KB |
Ok |
97 |
Correct |
927 ms |
10768 KB |
Ok |
98 |
Correct |
670 ms |
8680 KB |
Ok |
99 |
Correct |
804 ms |
10220 KB |
Ok |
100 |
Correct |
792 ms |
10000 KB |
Ok |
101 |
Correct |
911 ms |
11396 KB |
Ok |
102 |
Correct |
863 ms |
11168 KB |
Ok |
103 |
Correct |
805 ms |
9780 KB |
Ok |
104 |
Correct |
1044 ms |
11224 KB |
Ok |
105 |
Correct |
1002 ms |
12452 KB |
Ok |
106 |
Correct |
732 ms |
9556 KB |
Ok |
107 |
Correct |
903 ms |
11288 KB |
Ok |
108 |
Correct |
982 ms |
12284 KB |
Ok |
109 |
Correct |
799 ms |
10564 KB |
Ok |
110 |
Correct |
1415 ms |
25680 KB |
Ok |
111 |
Correct |
1439 ms |
33472 KB |
Ok |
112 |
Correct |
1522 ms |
27516 KB |
Ok |
113 |
Correct |
1447 ms |
30460 KB |
Ok |
114 |
Correct |
1454 ms |
31732 KB |
Ok |
115 |
Correct |
1421 ms |
31208 KB |
Ok |
116 |
Correct |
1433 ms |
31184 KB |
Ok |
117 |
Correct |
1404 ms |
31640 KB |
Ok |
118 |
Correct |
1519 ms |
28168 KB |
Ok |
119 |
Correct |
1471 ms |
32160 KB |
Ok |
120 |
Correct |
1481 ms |
28252 KB |
Ok |
121 |
Correct |
1516 ms |
27216 KB |
Ok |
122 |
Correct |
1571 ms |
29948 KB |
Ok |
123 |
Correct |
1483 ms |
34240 KB |
Ok |
124 |
Correct |
1453 ms |
24924 KB |
Ok |
125 |
Correct |
1515 ms |
15816 KB |
Ok |