#include <bits/stdc++.h>
//#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
using namespace std;
typedef pair < long long, long long > pll;
typedef pair < int, int > pii;
typedef unsigned long long ull;
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;
typedef long long ll;
typedef double db;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const int inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 4e5 + 11;
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;
int T, n, m, timer, t[N], c[N];
bool cycle;
vi g[N];
void dfs (int v) {
c[v] = 1;
for (auto to : g[v]) {
if (!c[to])
dfs(to);
if (c[to] == 1)
cycle = 1;
}
t[v] = ++timer;
c[v] = 2;
}
bool check (int k) {
for (int i = 0; i <= k; ++i)
g[i].clear();
for (int i = 0; i <= k; ++i) {
t[i] = 0;
c[i] = 0;
if (i - n >= 0)
g[i - n].pb(i);
if (i - m >= 0)
g[i].pb(i - m);
}
timer = 0;
cycle = 0;
for (int i = 0; i <= k; ++i)
if (!c[i])
dfs(i);
return cycle ^ 1;
}
main () {
cin >> T;
while (T--) {
cin >> n >> m;
int l = 1, r = n + m, res = 0;
while (l <= r) {
int mid = (l + r) >> 1;
if (check(mid)) {
l = mid + 1;
res = mid;
} else
r = mid - 1;
}
check(res);
printf("%d\n", res);
for (int i = 1; i <= res; ++i)
printf("%d ", t[i] - t[i - 1]);
printf("\n");
}
}
Compilation message
sequence.cpp: In function 'bool check(int)':
sequence.cpp:60:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for (int i = 0; i <= k; ++i)
^~~
sequence.cpp:64:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
for (int i = 0; i <= k; ++i) {
^~~
sequence.cpp: At global scope:
sequence.cpp:86:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main () {
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9728 KB |
Ok |
2 |
Correct |
10 ms |
9728 KB |
Ok |
3 |
Correct |
10 ms |
9728 KB |
Ok |
4 |
Correct |
10 ms |
9728 KB |
Ok |
5 |
Correct |
10 ms |
9728 KB |
Ok |
6 |
Correct |
11 ms |
9600 KB |
Ok |
7 |
Correct |
10 ms |
9728 KB |
Ok |
8 |
Correct |
10 ms |
9728 KB |
Ok |
9 |
Correct |
10 ms |
9728 KB |
Ok |
10 |
Correct |
10 ms |
9728 KB |
Ok |
11 |
Correct |
10 ms |
9728 KB |
Ok |
12 |
Correct |
10 ms |
9728 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9728 KB |
Ok |
2 |
Correct |
12 ms |
9728 KB |
Ok |
3 |
Correct |
10 ms |
9728 KB |
Ok |
4 |
Correct |
10 ms |
9728 KB |
Ok |
5 |
Correct |
10 ms |
9728 KB |
Ok |
6 |
Correct |
14 ms |
9984 KB |
Ok |
7 |
Correct |
34 ms |
10872 KB |
Ok |
8 |
Correct |
21 ms |
10240 KB |
Ok |
9 |
Correct |
37 ms |
11076 KB |
Ok |
10 |
Correct |
27 ms |
10496 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9728 KB |
Ok |
2 |
Correct |
10 ms |
9728 KB |
Ok |
3 |
Correct |
10 ms |
9728 KB |
Ok |
4 |
Correct |
10 ms |
9728 KB |
Ok |
5 |
Correct |
10 ms |
9728 KB |
Ok |
6 |
Correct |
10 ms |
9728 KB |
Ok |
7 |
Correct |
10 ms |
9728 KB |
Ok |
8 |
Correct |
11 ms |
9728 KB |
Ok |
9 |
Correct |
10 ms |
9728 KB |
Ok |
10 |
Correct |
10 ms |
9728 KB |
Ok |
11 |
Correct |
10 ms |
9728 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9728 KB |
Ok |
2 |
Correct |
10 ms |
9728 KB |
Ok |
3 |
Correct |
10 ms |
9728 KB |
Ok |
4 |
Correct |
10 ms |
9728 KB |
Ok |
5 |
Correct |
10 ms |
9728 KB |
Ok |
6 |
Correct |
374 ms |
26848 KB |
Ok |
7 |
Correct |
332 ms |
28792 KB |
Ok |
8 |
Correct |
747 ms |
31608 KB |
Ok |
9 |
Correct |
427 ms |
28920 KB |
Ok |
10 |
Correct |
222 ms |
20344 KB |
Ok |
11 |
Correct |
369 ms |
30328 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9728 KB |
Ok |
2 |
Correct |
10 ms |
9728 KB |
Ok |
3 |
Correct |
10 ms |
9728 KB |
Ok |
4 |
Correct |
10 ms |
9728 KB |
Ok |
5 |
Correct |
10 ms |
9728 KB |
Ok |
6 |
Correct |
11 ms |
9600 KB |
Ok |
7 |
Correct |
10 ms |
9728 KB |
Ok |
8 |
Correct |
10 ms |
9728 KB |
Ok |
9 |
Correct |
10 ms |
9728 KB |
Ok |
10 |
Correct |
10 ms |
9728 KB |
Ok |
11 |
Correct |
10 ms |
9728 KB |
Ok |
12 |
Correct |
10 ms |
9728 KB |
Ok |
13 |
Correct |
10 ms |
9728 KB |
Ok |
14 |
Correct |
10 ms |
9728 KB |
Ok |
15 |
Correct |
10 ms |
9728 KB |
Ok |
16 |
Correct |
10 ms |
9728 KB |
Ok |
17 |
Correct |
10 ms |
9728 KB |
Ok |
18 |
Correct |
10 ms |
9728 KB |
Ok |
19 |
Correct |
10 ms |
9728 KB |
Ok |
20 |
Correct |
11 ms |
9728 KB |
Ok |
21 |
Correct |
10 ms |
9728 KB |
Ok |
22 |
Correct |
10 ms |
9728 KB |
Ok |
23 |
Correct |
10 ms |
9728 KB |
Ok |
24 |
Correct |
14 ms |
9856 KB |
Ok |
25 |
Correct |
14 ms |
9984 KB |
Ok |
26 |
Correct |
14 ms |
9856 KB |
Ok |
27 |
Correct |
14 ms |
9856 KB |
Ok |
28 |
Correct |
13 ms |
9856 KB |
Ok |
29 |
Correct |
13 ms |
9856 KB |
Ok |
30 |
Correct |
13 ms |
9856 KB |
Ok |
31 |
Correct |
14 ms |
9984 KB |
Ok |
32 |
Correct |
15 ms |
9856 KB |
Ok |
33 |
Correct |
14 ms |
9856 KB |
Ok |
34 |
Correct |
20 ms |
10112 KB |
Ok |
35 |
Correct |
21 ms |
10240 KB |
Ok |
36 |
Correct |
21 ms |
10368 KB |
Ok |
37 |
Correct |
20 ms |
10240 KB |
Ok |
38 |
Correct |
21 ms |
10240 KB |
Ok |
39 |
Correct |
20 ms |
10112 KB |
Ok |
40 |
Correct |
23 ms |
10240 KB |
Ok |
41 |
Correct |
21 ms |
10240 KB |
Ok |
42 |
Correct |
21 ms |
10232 KB |
Ok |
43 |
Correct |
23 ms |
10240 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9728 KB |
Ok |
2 |
Correct |
10 ms |
9728 KB |
Ok |
3 |
Correct |
10 ms |
9728 KB |
Ok |
4 |
Correct |
10 ms |
9728 KB |
Ok |
5 |
Correct |
10 ms |
9728 KB |
Ok |
6 |
Correct |
11 ms |
9600 KB |
Ok |
7 |
Correct |
10 ms |
9728 KB |
Ok |
8 |
Correct |
10 ms |
9728 KB |
Ok |
9 |
Correct |
10 ms |
9728 KB |
Ok |
10 |
Correct |
10 ms |
9728 KB |
Ok |
11 |
Correct |
10 ms |
9728 KB |
Ok |
12 |
Correct |
10 ms |
9728 KB |
Ok |
13 |
Correct |
10 ms |
9728 KB |
Ok |
14 |
Correct |
12 ms |
9728 KB |
Ok |
15 |
Correct |
10 ms |
9728 KB |
Ok |
16 |
Correct |
10 ms |
9728 KB |
Ok |
17 |
Correct |
10 ms |
9728 KB |
Ok |
18 |
Correct |
14 ms |
9984 KB |
Ok |
19 |
Correct |
34 ms |
10872 KB |
Ok |
20 |
Correct |
21 ms |
10240 KB |
Ok |
21 |
Correct |
37 ms |
11076 KB |
Ok |
22 |
Correct |
27 ms |
10496 KB |
Ok |
23 |
Correct |
10 ms |
9728 KB |
Ok |
24 |
Correct |
10 ms |
9728 KB |
Ok |
25 |
Correct |
10 ms |
9728 KB |
Ok |
26 |
Correct |
10 ms |
9728 KB |
Ok |
27 |
Correct |
10 ms |
9728 KB |
Ok |
28 |
Correct |
10 ms |
9728 KB |
Ok |
29 |
Correct |
10 ms |
9728 KB |
Ok |
30 |
Correct |
11 ms |
9728 KB |
Ok |
31 |
Correct |
10 ms |
9728 KB |
Ok |
32 |
Correct |
10 ms |
9728 KB |
Ok |
33 |
Correct |
10 ms |
9728 KB |
Ok |
34 |
Correct |
14 ms |
9856 KB |
Ok |
35 |
Correct |
14 ms |
9984 KB |
Ok |
36 |
Correct |
14 ms |
9856 KB |
Ok |
37 |
Correct |
14 ms |
9856 KB |
Ok |
38 |
Correct |
13 ms |
9856 KB |
Ok |
39 |
Correct |
13 ms |
9856 KB |
Ok |
40 |
Correct |
13 ms |
9856 KB |
Ok |
41 |
Correct |
14 ms |
9984 KB |
Ok |
42 |
Correct |
15 ms |
9856 KB |
Ok |
43 |
Correct |
14 ms |
9856 KB |
Ok |
44 |
Correct |
20 ms |
10112 KB |
Ok |
45 |
Correct |
21 ms |
10240 KB |
Ok |
46 |
Correct |
21 ms |
10368 KB |
Ok |
47 |
Correct |
20 ms |
10240 KB |
Ok |
48 |
Correct |
21 ms |
10240 KB |
Ok |
49 |
Correct |
20 ms |
10112 KB |
Ok |
50 |
Correct |
23 ms |
10240 KB |
Ok |
51 |
Correct |
21 ms |
10240 KB |
Ok |
52 |
Correct |
21 ms |
10232 KB |
Ok |
53 |
Correct |
23 ms |
10240 KB |
Ok |
54 |
Correct |
251 ms |
15080 KB |
Ok |
55 |
Correct |
343 ms |
15552 KB |
Ok |
56 |
Correct |
310 ms |
15544 KB |
Ok |
57 |
Correct |
200 ms |
14456 KB |
Ok |
58 |
Correct |
239 ms |
14924 KB |
Ok |
59 |
Correct |
200 ms |
14456 KB |
Ok |
60 |
Correct |
174 ms |
14072 KB |
Ok |
61 |
Correct |
203 ms |
14584 KB |
Ok |
62 |
Correct |
270 ms |
15096 KB |
Ok |
63 |
Correct |
227 ms |
14584 KB |
Ok |
64 |
Correct |
310 ms |
15352 KB |
Ok |
65 |
Correct |
255 ms |
14980 KB |
Ok |
66 |
Correct |
227 ms |
14712 KB |
Ok |
67 |
Correct |
209 ms |
14712 KB |
Ok |
68 |
Correct |
214 ms |
14840 KB |
Ok |
69 |
Correct |
1089 ms |
24388 KB |
Ok |
70 |
Correct |
902 ms |
24828 KB |
Ok |
71 |
Correct |
1041 ms |
24440 KB |
Ok |
72 |
Correct |
1041 ms |
24316 KB |
Ok |
73 |
Correct |
834 ms |
24440 KB |
Ok |
74 |
Correct |
1089 ms |
24440 KB |
Ok |
75 |
Correct |
1010 ms |
23928 KB |
Ok |
76 |
Correct |
979 ms |
24656 KB |
Ok |
77 |
Correct |
1214 ms |
23928 KB |
Ok |
78 |
Correct |
1033 ms |
24504 KB |
Ok |
79 |
Correct |
1040 ms |
24568 KB |
Ok |
80 |
Correct |
1059 ms |
24824 KB |
Ok |
81 |
Correct |
1238 ms |
24544 KB |
Ok |
82 |
Correct |
1167 ms |
24648 KB |
Ok |
83 |
Correct |
1077 ms |
24136 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
9728 KB |
Ok |
2 |
Correct |
10 ms |
9728 KB |
Ok |
3 |
Correct |
10 ms |
9728 KB |
Ok |
4 |
Correct |
10 ms |
9728 KB |
Ok |
5 |
Correct |
10 ms |
9728 KB |
Ok |
6 |
Correct |
11 ms |
9600 KB |
Ok |
7 |
Correct |
10 ms |
9728 KB |
Ok |
8 |
Correct |
10 ms |
9728 KB |
Ok |
9 |
Correct |
10 ms |
9728 KB |
Ok |
10 |
Correct |
10 ms |
9728 KB |
Ok |
11 |
Correct |
10 ms |
9728 KB |
Ok |
12 |
Correct |
10 ms |
9728 KB |
Ok |
13 |
Correct |
10 ms |
9728 KB |
Ok |
14 |
Correct |
12 ms |
9728 KB |
Ok |
15 |
Correct |
10 ms |
9728 KB |
Ok |
16 |
Correct |
10 ms |
9728 KB |
Ok |
17 |
Correct |
10 ms |
9728 KB |
Ok |
18 |
Correct |
14 ms |
9984 KB |
Ok |
19 |
Correct |
34 ms |
10872 KB |
Ok |
20 |
Correct |
21 ms |
10240 KB |
Ok |
21 |
Correct |
37 ms |
11076 KB |
Ok |
22 |
Correct |
27 ms |
10496 KB |
Ok |
23 |
Correct |
10 ms |
9728 KB |
Ok |
24 |
Correct |
10 ms |
9728 KB |
Ok |
25 |
Correct |
10 ms |
9728 KB |
Ok |
26 |
Correct |
10 ms |
9728 KB |
Ok |
27 |
Correct |
10 ms |
9728 KB |
Ok |
28 |
Correct |
10 ms |
9728 KB |
Ok |
29 |
Correct |
10 ms |
9728 KB |
Ok |
30 |
Correct |
11 ms |
9728 KB |
Ok |
31 |
Correct |
10 ms |
9728 KB |
Ok |
32 |
Correct |
10 ms |
9728 KB |
Ok |
33 |
Correct |
10 ms |
9728 KB |
Ok |
34 |
Correct |
10 ms |
9728 KB |
Ok |
35 |
Correct |
10 ms |
9728 KB |
Ok |
36 |
Correct |
10 ms |
9728 KB |
Ok |
37 |
Correct |
10 ms |
9728 KB |
Ok |
38 |
Correct |
10 ms |
9728 KB |
Ok |
39 |
Correct |
374 ms |
26848 KB |
Ok |
40 |
Correct |
332 ms |
28792 KB |
Ok |
41 |
Correct |
747 ms |
31608 KB |
Ok |
42 |
Correct |
427 ms |
28920 KB |
Ok |
43 |
Correct |
222 ms |
20344 KB |
Ok |
44 |
Correct |
369 ms |
30328 KB |
Ok |
45 |
Correct |
14 ms |
9856 KB |
Ok |
46 |
Correct |
14 ms |
9984 KB |
Ok |
47 |
Correct |
14 ms |
9856 KB |
Ok |
48 |
Correct |
14 ms |
9856 KB |
Ok |
49 |
Correct |
13 ms |
9856 KB |
Ok |
50 |
Correct |
13 ms |
9856 KB |
Ok |
51 |
Correct |
13 ms |
9856 KB |
Ok |
52 |
Correct |
14 ms |
9984 KB |
Ok |
53 |
Correct |
15 ms |
9856 KB |
Ok |
54 |
Correct |
14 ms |
9856 KB |
Ok |
55 |
Correct |
20 ms |
10112 KB |
Ok |
56 |
Correct |
21 ms |
10240 KB |
Ok |
57 |
Correct |
21 ms |
10368 KB |
Ok |
58 |
Correct |
20 ms |
10240 KB |
Ok |
59 |
Correct |
21 ms |
10240 KB |
Ok |
60 |
Correct |
20 ms |
10112 KB |
Ok |
61 |
Correct |
23 ms |
10240 KB |
Ok |
62 |
Correct |
21 ms |
10240 KB |
Ok |
63 |
Correct |
21 ms |
10232 KB |
Ok |
64 |
Correct |
23 ms |
10240 KB |
Ok |
65 |
Correct |
251 ms |
15080 KB |
Ok |
66 |
Correct |
343 ms |
15552 KB |
Ok |
67 |
Correct |
310 ms |
15544 KB |
Ok |
68 |
Correct |
200 ms |
14456 KB |
Ok |
69 |
Correct |
239 ms |
14924 KB |
Ok |
70 |
Correct |
200 ms |
14456 KB |
Ok |
71 |
Correct |
174 ms |
14072 KB |
Ok |
72 |
Correct |
203 ms |
14584 KB |
Ok |
73 |
Correct |
270 ms |
15096 KB |
Ok |
74 |
Correct |
227 ms |
14584 KB |
Ok |
75 |
Correct |
310 ms |
15352 KB |
Ok |
76 |
Correct |
255 ms |
14980 KB |
Ok |
77 |
Correct |
227 ms |
14712 KB |
Ok |
78 |
Correct |
209 ms |
14712 KB |
Ok |
79 |
Correct |
214 ms |
14840 KB |
Ok |
80 |
Correct |
1089 ms |
24388 KB |
Ok |
81 |
Correct |
902 ms |
24828 KB |
Ok |
82 |
Correct |
1041 ms |
24440 KB |
Ok |
83 |
Correct |
1041 ms |
24316 KB |
Ok |
84 |
Correct |
834 ms |
24440 KB |
Ok |
85 |
Correct |
1089 ms |
24440 KB |
Ok |
86 |
Correct |
1010 ms |
23928 KB |
Ok |
87 |
Correct |
979 ms |
24656 KB |
Ok |
88 |
Correct |
1214 ms |
23928 KB |
Ok |
89 |
Correct |
1033 ms |
24504 KB |
Ok |
90 |
Correct |
1040 ms |
24568 KB |
Ok |
91 |
Correct |
1059 ms |
24824 KB |
Ok |
92 |
Correct |
1238 ms |
24544 KB |
Ok |
93 |
Correct |
1167 ms |
24648 KB |
Ok |
94 |
Correct |
1077 ms |
24136 KB |
Ok |
95 |
Correct |
824 ms |
23672 KB |
Ok |
96 |
Correct |
1347 ms |
29560 KB |
Ok |
97 |
Correct |
1012 ms |
26360 KB |
Ok |
98 |
Correct |
642 ms |
26104 KB |
Ok |
99 |
Correct |
894 ms |
25640 KB |
Ok |
100 |
Correct |
935 ms |
25208 KB |
Ok |
101 |
Correct |
890 ms |
27896 KB |
Ok |
102 |
Correct |
977 ms |
26232 KB |
Ok |
103 |
Correct |
868 ms |
27256 KB |
Ok |
104 |
Correct |
1267 ms |
28968 KB |
Ok |
105 |
Correct |
1170 ms |
29252 KB |
Ok |
106 |
Correct |
1092 ms |
29348 KB |
Ok |
107 |
Correct |
940 ms |
28476 KB |
Ok |
108 |
Correct |
1525 ms |
29132 KB |
Ok |
109 |
Correct |
1261 ms |
30200 KB |
Ok |
110 |
Execution timed out |
2082 ms |
39736 KB |
Time limit exceeded |
111 |
Halted |
0 ms |
0 KB |
- |