#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 inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 4e5 + 11;
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 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;
return;
}
}
t[v] = ++timer;
c[v] = 2;
}
inline 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 && !cycle; ++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:62:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for (int i = 0; i <= k; ++i)
^~~
sequence.cpp:66: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:88:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main () {
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
9728 KB |
Ok |
2 |
Correct |
10 ms |
9728 KB |
Ok |
3 |
Correct |
11 ms |
9728 KB |
Ok |
4 |
Correct |
10 ms |
9728 KB |
Ok |
5 |
Correct |
12 ms |
9728 KB |
Ok |
6 |
Correct |
10 ms |
9728 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
9728 KB |
Ok |
2 |
Correct |
11 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 |
15 ms |
9984 KB |
Ok |
7 |
Correct |
35 ms |
10872 KB |
Ok |
8 |
Correct |
22 ms |
10240 KB |
Ok |
9 |
Correct |
40 ms |
11016 KB |
Ok |
10 |
Correct |
26 ms |
10496 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
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 |
14 ms |
9728 KB |
Ok |
7 |
Correct |
10 ms |
9728 KB |
Ok |
8 |
Correct |
10 ms |
9728 KB |
Ok |
9 |
Correct |
10 ms |
9716 KB |
Ok |
10 |
Correct |
12 ms |
9728 KB |
Ok |
11 |
Correct |
10 ms |
9728 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
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 |
356 ms |
26744 KB |
Ok |
7 |
Correct |
330 ms |
28792 KB |
Ok |
8 |
Correct |
683 ms |
31616 KB |
Ok |
9 |
Correct |
449 ms |
28900 KB |
Ok |
10 |
Correct |
205 ms |
20348 KB |
Ok |
11 |
Correct |
357 ms |
30200 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
9728 KB |
Ok |
2 |
Correct |
10 ms |
9728 KB |
Ok |
3 |
Correct |
11 ms |
9728 KB |
Ok |
4 |
Correct |
10 ms |
9728 KB |
Ok |
5 |
Correct |
12 ms |
9728 KB |
Ok |
6 |
Correct |
10 ms |
9728 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 |
14 ms |
9728 KB |
Ok |
19 |
Correct |
10 ms |
9728 KB |
Ok |
20 |
Correct |
10 ms |
9728 KB |
Ok |
21 |
Correct |
10 ms |
9716 KB |
Ok |
22 |
Correct |
12 ms |
9728 KB |
Ok |
23 |
Correct |
10 ms |
9728 KB |
Ok |
24 |
Correct |
14 ms |
9984 KB |
Ok |
25 |
Correct |
16 ms |
9856 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 |
9856 KB |
Ok |
32 |
Correct |
15 ms |
9856 KB |
Ok |
33 |
Correct |
13 ms |
9856 KB |
Ok |
34 |
Correct |
20 ms |
10216 KB |
Ok |
35 |
Correct |
20 ms |
10164 KB |
Ok |
36 |
Correct |
21 ms |
10240 KB |
Ok |
37 |
Correct |
21 ms |
10240 KB |
Ok |
38 |
Correct |
20 ms |
10240 KB |
Ok |
39 |
Correct |
20 ms |
10240 KB |
Ok |
40 |
Correct |
21 ms |
10240 KB |
Ok |
41 |
Correct |
20 ms |
10240 KB |
Ok |
42 |
Correct |
20 ms |
10240 KB |
Ok |
43 |
Correct |
21 ms |
10240 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
9728 KB |
Ok |
2 |
Correct |
10 ms |
9728 KB |
Ok |
3 |
Correct |
11 ms |
9728 KB |
Ok |
4 |
Correct |
10 ms |
9728 KB |
Ok |
5 |
Correct |
12 ms |
9728 KB |
Ok |
6 |
Correct |
10 ms |
9728 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 |
11 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 |
15 ms |
9984 KB |
Ok |
19 |
Correct |
35 ms |
10872 KB |
Ok |
20 |
Correct |
22 ms |
10240 KB |
Ok |
21 |
Correct |
40 ms |
11016 KB |
Ok |
22 |
Correct |
26 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 |
14 ms |
9728 KB |
Ok |
29 |
Correct |
10 ms |
9728 KB |
Ok |
30 |
Correct |
10 ms |
9728 KB |
Ok |
31 |
Correct |
10 ms |
9716 KB |
Ok |
32 |
Correct |
12 ms |
9728 KB |
Ok |
33 |
Correct |
10 ms |
9728 KB |
Ok |
34 |
Correct |
14 ms |
9984 KB |
Ok |
35 |
Correct |
16 ms |
9856 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 |
9856 KB |
Ok |
42 |
Correct |
15 ms |
9856 KB |
Ok |
43 |
Correct |
13 ms |
9856 KB |
Ok |
44 |
Correct |
20 ms |
10216 KB |
Ok |
45 |
Correct |
20 ms |
10164 KB |
Ok |
46 |
Correct |
21 ms |
10240 KB |
Ok |
47 |
Correct |
21 ms |
10240 KB |
Ok |
48 |
Correct |
20 ms |
10240 KB |
Ok |
49 |
Correct |
20 ms |
10240 KB |
Ok |
50 |
Correct |
21 ms |
10240 KB |
Ok |
51 |
Correct |
20 ms |
10240 KB |
Ok |
52 |
Correct |
20 ms |
10240 KB |
Ok |
53 |
Correct |
21 ms |
10240 KB |
Ok |
54 |
Correct |
216 ms |
14968 KB |
Ok |
55 |
Correct |
272 ms |
15352 KB |
Ok |
56 |
Correct |
264 ms |
15352 KB |
Ok |
57 |
Correct |
163 ms |
14456 KB |
Ok |
58 |
Correct |
209 ms |
14840 KB |
Ok |
59 |
Correct |
173 ms |
14456 KB |
Ok |
60 |
Correct |
151 ms |
14072 KB |
Ok |
61 |
Correct |
164 ms |
14656 KB |
Ok |
62 |
Correct |
225 ms |
15096 KB |
Ok |
63 |
Correct |
180 ms |
14456 KB |
Ok |
64 |
Correct |
259 ms |
15352 KB |
Ok |
65 |
Correct |
205 ms |
14968 KB |
Ok |
66 |
Correct |
184 ms |
14712 KB |
Ok |
67 |
Correct |
181 ms |
14640 KB |
Ok |
68 |
Correct |
192 ms |
14840 KB |
Ok |
69 |
Correct |
1073 ms |
24568 KB |
Ok |
70 |
Correct |
927 ms |
24824 KB |
Ok |
71 |
Correct |
1018 ms |
24312 KB |
Ok |
72 |
Correct |
996 ms |
24312 KB |
Ok |
73 |
Correct |
771 ms |
24508 KB |
Ok |
74 |
Correct |
1112 ms |
24312 KB |
Ok |
75 |
Correct |
1074 ms |
23804 KB |
Ok |
76 |
Correct |
1008 ms |
24672 KB |
Ok |
77 |
Correct |
1063 ms |
24056 KB |
Ok |
78 |
Correct |
953 ms |
24404 KB |
Ok |
79 |
Correct |
989 ms |
24568 KB |
Ok |
80 |
Correct |
1094 ms |
24568 KB |
Ok |
81 |
Correct |
1265 ms |
24568 KB |
Ok |
82 |
Correct |
964 ms |
24568 KB |
Ok |
83 |
Correct |
1004 ms |
24160 KB |
Ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
9728 KB |
Ok |
2 |
Correct |
10 ms |
9728 KB |
Ok |
3 |
Correct |
11 ms |
9728 KB |
Ok |
4 |
Correct |
10 ms |
9728 KB |
Ok |
5 |
Correct |
12 ms |
9728 KB |
Ok |
6 |
Correct |
10 ms |
9728 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 |
11 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 |
15 ms |
9984 KB |
Ok |
19 |
Correct |
35 ms |
10872 KB |
Ok |
20 |
Correct |
22 ms |
10240 KB |
Ok |
21 |
Correct |
40 ms |
11016 KB |
Ok |
22 |
Correct |
26 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 |
14 ms |
9728 KB |
Ok |
29 |
Correct |
10 ms |
9728 KB |
Ok |
30 |
Correct |
10 ms |
9728 KB |
Ok |
31 |
Correct |
10 ms |
9716 KB |
Ok |
32 |
Correct |
12 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 |
356 ms |
26744 KB |
Ok |
40 |
Correct |
330 ms |
28792 KB |
Ok |
41 |
Correct |
683 ms |
31616 KB |
Ok |
42 |
Correct |
449 ms |
28900 KB |
Ok |
43 |
Correct |
205 ms |
20348 KB |
Ok |
44 |
Correct |
357 ms |
30200 KB |
Ok |
45 |
Correct |
14 ms |
9984 KB |
Ok |
46 |
Correct |
16 ms |
9856 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 |
9856 KB |
Ok |
53 |
Correct |
15 ms |
9856 KB |
Ok |
54 |
Correct |
13 ms |
9856 KB |
Ok |
55 |
Correct |
20 ms |
10216 KB |
Ok |
56 |
Correct |
20 ms |
10164 KB |
Ok |
57 |
Correct |
21 ms |
10240 KB |
Ok |
58 |
Correct |
21 ms |
10240 KB |
Ok |
59 |
Correct |
20 ms |
10240 KB |
Ok |
60 |
Correct |
20 ms |
10240 KB |
Ok |
61 |
Correct |
21 ms |
10240 KB |
Ok |
62 |
Correct |
20 ms |
10240 KB |
Ok |
63 |
Correct |
20 ms |
10240 KB |
Ok |
64 |
Correct |
21 ms |
10240 KB |
Ok |
65 |
Correct |
216 ms |
14968 KB |
Ok |
66 |
Correct |
272 ms |
15352 KB |
Ok |
67 |
Correct |
264 ms |
15352 KB |
Ok |
68 |
Correct |
163 ms |
14456 KB |
Ok |
69 |
Correct |
209 ms |
14840 KB |
Ok |
70 |
Correct |
173 ms |
14456 KB |
Ok |
71 |
Correct |
151 ms |
14072 KB |
Ok |
72 |
Correct |
164 ms |
14656 KB |
Ok |
73 |
Correct |
225 ms |
15096 KB |
Ok |
74 |
Correct |
180 ms |
14456 KB |
Ok |
75 |
Correct |
259 ms |
15352 KB |
Ok |
76 |
Correct |
205 ms |
14968 KB |
Ok |
77 |
Correct |
184 ms |
14712 KB |
Ok |
78 |
Correct |
181 ms |
14640 KB |
Ok |
79 |
Correct |
192 ms |
14840 KB |
Ok |
80 |
Correct |
1073 ms |
24568 KB |
Ok |
81 |
Correct |
927 ms |
24824 KB |
Ok |
82 |
Correct |
1018 ms |
24312 KB |
Ok |
83 |
Correct |
996 ms |
24312 KB |
Ok |
84 |
Correct |
771 ms |
24508 KB |
Ok |
85 |
Correct |
1112 ms |
24312 KB |
Ok |
86 |
Correct |
1074 ms |
23804 KB |
Ok |
87 |
Correct |
1008 ms |
24672 KB |
Ok |
88 |
Correct |
1063 ms |
24056 KB |
Ok |
89 |
Correct |
953 ms |
24404 KB |
Ok |
90 |
Correct |
989 ms |
24568 KB |
Ok |
91 |
Correct |
1094 ms |
24568 KB |
Ok |
92 |
Correct |
1265 ms |
24568 KB |
Ok |
93 |
Correct |
964 ms |
24568 KB |
Ok |
94 |
Correct |
1004 ms |
24160 KB |
Ok |
95 |
Correct |
685 ms |
23472 KB |
Ok |
96 |
Correct |
944 ms |
29564 KB |
Ok |
97 |
Correct |
883 ms |
26360 KB |
Ok |
98 |
Correct |
507 ms |
26104 KB |
Ok |
99 |
Correct |
747 ms |
25816 KB |
Ok |
100 |
Correct |
765 ms |
25224 KB |
Ok |
101 |
Correct |
753 ms |
27896 KB |
Ok |
102 |
Correct |
804 ms |
26104 KB |
Ok |
103 |
Correct |
728 ms |
27228 KB |
Ok |
104 |
Correct |
1020 ms |
29152 KB |
Ok |
105 |
Correct |
925 ms |
29432 KB |
Ok |
106 |
Correct |
819 ms |
29288 KB |
Ok |
107 |
Correct |
781 ms |
28148 KB |
Ok |
108 |
Correct |
1120 ms |
28920 KB |
Ok |
109 |
Correct |
946 ms |
30072 KB |
Ok |
110 |
Execution timed out |
2090 ms |
42508 KB |
Time limit exceeded |
111 |
Halted |
0 ms |
0 KB |
- |