#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pll pair<ll, ll>
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
const int N = 5e5+5;
const int M = (1<<17);
const ll inf = 1e15;
const ll mod = 1e15+7;
int n, t, k, m, d[N], in[N], out[N];
ll ans, tong, a[N], b[N], c[N];
string s[N];
struct node
{
int x[2];
set<int> vi;
node(){}
node( int _x, int _y)
{
x[0] = _x;
x[1] = _y;
}
};
vector<node> q;
vector<int> adj[N], kq;
void dfs(int u)
{
a[u] = ++t;
if(u+m <= k && a[u+m] == 0)dfs(u+m);
if(u-n >= 0 && a[u-n] == 0)dfs(u-n);
}
bool check(int mid)
{
k = mid;
for(int i = 0; i <= k; i ++)adj[i].clear();
fill_n(a, k+1, 0);
t = 0;
for(int i = 0; i <= k; i ++)
{
if(i+m <= k)
{
adj[i].pb(i+m);
++a[i+m];
}
if(i >= n)
{
adj[i].pb(i-n);
++a[i-n];
}
}
queue<int> q;
for(int i = 0; i <= k; i ++)if(a[i] == 0)q.push(i);
while(!q.empty())
{
int u = q.front();
q.pop();
a[u] = ++t;
for(int v: adj[u])
{
--a[v];
if(a[v] == 0)q.push(v);
}
}
if(t == k+1)return true;
return false;
}
void sol()
{
cin >> n >> m;
int l = 1, r = 5e5, mid;
while(l <= r)
{
mid = (l+r)>>1;
if(check(mid))l = mid+1;
else r = mid-1;
}
check(r);
cout << r << '\n';
for(int i = 1; i <= r; i ++)cout << a[i]-a[i-1] <<" ";
cout << '\n';
}
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
#define task "test"
if(fopen(task".inp", "r"))
{
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int ntest = 1;
cin >> ntest;
while(ntest -- > 0)
sol();
}
Compilation message
sequence.cpp: In function 'int main()':
sequence.cpp:96:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
96 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sequence.cpp:97:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
97 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
129 ms |
37492 KB |
Ok |
2 |
Correct |
110 ms |
37492 KB |
Ok |
3 |
Correct |
116 ms |
37496 KB |
Ok |
4 |
Correct |
119 ms |
37512 KB |
Ok |
5 |
Correct |
119 ms |
37492 KB |
Ok |
6 |
Correct |
122 ms |
37492 KB |
Ok |
7 |
Correct |
116 ms |
37444 KB |
Ok |
8 |
Correct |
108 ms |
37488 KB |
Ok |
9 |
Correct |
112 ms |
37488 KB |
Ok |
10 |
Correct |
112 ms |
37496 KB |
Ok |
11 |
Correct |
126 ms |
37504 KB |
Ok |
12 |
Correct |
114 ms |
37504 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
37384 KB |
Ok |
2 |
Correct |
117 ms |
37604 KB |
Ok |
3 |
Correct |
123 ms |
37492 KB |
Ok |
4 |
Correct |
123 ms |
37440 KB |
Ok |
5 |
Correct |
111 ms |
37460 KB |
Ok |
6 |
Correct |
113 ms |
37532 KB |
Ok |
7 |
Correct |
145 ms |
37768 KB |
Ok |
8 |
Correct |
118 ms |
37660 KB |
Ok |
9 |
Correct |
134 ms |
37844 KB |
Ok |
10 |
Correct |
121 ms |
37656 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
37528 KB |
Ok |
2 |
Correct |
115 ms |
37492 KB |
Ok |
3 |
Correct |
113 ms |
37492 KB |
Ok |
4 |
Correct |
114 ms |
37492 KB |
Ok |
5 |
Correct |
136 ms |
37492 KB |
Ok |
6 |
Correct |
126 ms |
37444 KB |
Ok |
7 |
Correct |
113 ms |
37540 KB |
Ok |
8 |
Correct |
113 ms |
37496 KB |
Ok |
9 |
Correct |
115 ms |
37496 KB |
Ok |
10 |
Correct |
110 ms |
37492 KB |
Ok |
11 |
Correct |
113 ms |
37584 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
37392 KB |
Ok |
2 |
Correct |
125 ms |
37492 KB |
Ok |
3 |
Correct |
115 ms |
37492 KB |
Ok |
4 |
Correct |
113 ms |
37492 KB |
Ok |
5 |
Correct |
113 ms |
37492 KB |
Ok |
6 |
Correct |
376 ms |
40476 KB |
Ok |
7 |
Correct |
306 ms |
39668 KB |
Ok |
8 |
Correct |
609 ms |
41844 KB |
Ok |
9 |
Correct |
436 ms |
42344 KB |
Ok |
10 |
Correct |
272 ms |
39364 KB |
Ok |
11 |
Correct |
479 ms |
41192 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
129 ms |
37492 KB |
Ok |
2 |
Correct |
110 ms |
37492 KB |
Ok |
3 |
Correct |
116 ms |
37496 KB |
Ok |
4 |
Correct |
119 ms |
37512 KB |
Ok |
5 |
Correct |
119 ms |
37492 KB |
Ok |
6 |
Correct |
122 ms |
37492 KB |
Ok |
7 |
Correct |
116 ms |
37444 KB |
Ok |
8 |
Correct |
108 ms |
37488 KB |
Ok |
9 |
Correct |
112 ms |
37488 KB |
Ok |
10 |
Correct |
112 ms |
37496 KB |
Ok |
11 |
Correct |
126 ms |
37504 KB |
Ok |
12 |
Correct |
114 ms |
37504 KB |
Ok |
13 |
Correct |
54 ms |
37528 KB |
Ok |
14 |
Correct |
115 ms |
37492 KB |
Ok |
15 |
Correct |
113 ms |
37492 KB |
Ok |
16 |
Correct |
114 ms |
37492 KB |
Ok |
17 |
Correct |
136 ms |
37492 KB |
Ok |
18 |
Correct |
126 ms |
37444 KB |
Ok |
19 |
Correct |
113 ms |
37540 KB |
Ok |
20 |
Correct |
113 ms |
37496 KB |
Ok |
21 |
Correct |
115 ms |
37496 KB |
Ok |
22 |
Correct |
110 ms |
37492 KB |
Ok |
23 |
Correct |
113 ms |
37584 KB |
Ok |
24 |
Correct |
118 ms |
37524 KB |
Ok |
25 |
Correct |
131 ms |
37644 KB |
Ok |
26 |
Correct |
119 ms |
37448 KB |
Ok |
27 |
Correct |
125 ms |
37532 KB |
Ok |
28 |
Correct |
114 ms |
37632 KB |
Ok |
29 |
Correct |
115 ms |
37444 KB |
Ok |
30 |
Correct |
127 ms |
37628 KB |
Ok |
31 |
Correct |
110 ms |
37504 KB |
Ok |
32 |
Correct |
111 ms |
37536 KB |
Ok |
33 |
Correct |
128 ms |
37528 KB |
Ok |
34 |
Correct |
119 ms |
37704 KB |
Ok |
35 |
Correct |
117 ms |
37640 KB |
Ok |
36 |
Correct |
118 ms |
37524 KB |
Ok |
37 |
Correct |
120 ms |
37640 KB |
Ok |
38 |
Correct |
133 ms |
37592 KB |
Ok |
39 |
Correct |
123 ms |
37560 KB |
Ok |
40 |
Correct |
130 ms |
37536 KB |
Ok |
41 |
Correct |
117 ms |
37600 KB |
Ok |
42 |
Correct |
116 ms |
37572 KB |
Ok |
43 |
Correct |
126 ms |
37624 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
129 ms |
37492 KB |
Ok |
2 |
Correct |
110 ms |
37492 KB |
Ok |
3 |
Correct |
116 ms |
37496 KB |
Ok |
4 |
Correct |
119 ms |
37512 KB |
Ok |
5 |
Correct |
119 ms |
37492 KB |
Ok |
6 |
Correct |
122 ms |
37492 KB |
Ok |
7 |
Correct |
116 ms |
37444 KB |
Ok |
8 |
Correct |
108 ms |
37488 KB |
Ok |
9 |
Correct |
112 ms |
37488 KB |
Ok |
10 |
Correct |
112 ms |
37496 KB |
Ok |
11 |
Correct |
126 ms |
37504 KB |
Ok |
12 |
Correct |
114 ms |
37504 KB |
Ok |
13 |
Correct |
109 ms |
37384 KB |
Ok |
14 |
Correct |
117 ms |
37604 KB |
Ok |
15 |
Correct |
123 ms |
37492 KB |
Ok |
16 |
Correct |
123 ms |
37440 KB |
Ok |
17 |
Correct |
111 ms |
37460 KB |
Ok |
18 |
Correct |
113 ms |
37532 KB |
Ok |
19 |
Correct |
145 ms |
37768 KB |
Ok |
20 |
Correct |
118 ms |
37660 KB |
Ok |
21 |
Correct |
134 ms |
37844 KB |
Ok |
22 |
Correct |
121 ms |
37656 KB |
Ok |
23 |
Correct |
54 ms |
37528 KB |
Ok |
24 |
Correct |
115 ms |
37492 KB |
Ok |
25 |
Correct |
113 ms |
37492 KB |
Ok |
26 |
Correct |
114 ms |
37492 KB |
Ok |
27 |
Correct |
136 ms |
37492 KB |
Ok |
28 |
Correct |
126 ms |
37444 KB |
Ok |
29 |
Correct |
113 ms |
37540 KB |
Ok |
30 |
Correct |
113 ms |
37496 KB |
Ok |
31 |
Correct |
115 ms |
37496 KB |
Ok |
32 |
Correct |
110 ms |
37492 KB |
Ok |
33 |
Correct |
113 ms |
37584 KB |
Ok |
34 |
Correct |
118 ms |
37524 KB |
Ok |
35 |
Correct |
131 ms |
37644 KB |
Ok |
36 |
Correct |
119 ms |
37448 KB |
Ok |
37 |
Correct |
125 ms |
37532 KB |
Ok |
38 |
Correct |
114 ms |
37632 KB |
Ok |
39 |
Correct |
115 ms |
37444 KB |
Ok |
40 |
Correct |
127 ms |
37628 KB |
Ok |
41 |
Correct |
110 ms |
37504 KB |
Ok |
42 |
Correct |
111 ms |
37536 KB |
Ok |
43 |
Correct |
128 ms |
37528 KB |
Ok |
44 |
Correct |
119 ms |
37704 KB |
Ok |
45 |
Correct |
117 ms |
37640 KB |
Ok |
46 |
Correct |
118 ms |
37524 KB |
Ok |
47 |
Correct |
120 ms |
37640 KB |
Ok |
48 |
Correct |
133 ms |
37592 KB |
Ok |
49 |
Correct |
123 ms |
37560 KB |
Ok |
50 |
Correct |
130 ms |
37536 KB |
Ok |
51 |
Correct |
117 ms |
37600 KB |
Ok |
52 |
Correct |
116 ms |
37572 KB |
Ok |
53 |
Correct |
126 ms |
37624 KB |
Ok |
54 |
Correct |
312 ms |
38924 KB |
Ok |
55 |
Correct |
363 ms |
39280 KB |
Ok |
56 |
Correct |
351 ms |
39128 KB |
Ok |
57 |
Correct |
315 ms |
39008 KB |
Ok |
58 |
Correct |
366 ms |
38980 KB |
Ok |
59 |
Correct |
323 ms |
39012 KB |
Ok |
60 |
Correct |
283 ms |
38784 KB |
Ok |
61 |
Correct |
306 ms |
38844 KB |
Ok |
62 |
Correct |
374 ms |
39204 KB |
Ok |
63 |
Correct |
314 ms |
38856 KB |
Ok |
64 |
Correct |
370 ms |
39168 KB |
Ok |
65 |
Correct |
357 ms |
39096 KB |
Ok |
66 |
Correct |
337 ms |
38964 KB |
Ok |
67 |
Correct |
273 ms |
38920 KB |
Ok |
68 |
Correct |
316 ms |
39000 KB |
Ok |
69 |
Correct |
534 ms |
42880 KB |
Ok |
70 |
Correct |
589 ms |
44384 KB |
Ok |
71 |
Correct |
537 ms |
42172 KB |
Ok |
72 |
Correct |
614 ms |
43220 KB |
Ok |
73 |
Correct |
621 ms |
42704 KB |
Ok |
74 |
Correct |
504 ms |
41600 KB |
Ok |
75 |
Correct |
490 ms |
41664 KB |
Ok |
76 |
Correct |
624 ms |
43796 KB |
Ok |
77 |
Correct |
543 ms |
41300 KB |
Ok |
78 |
Correct |
565 ms |
43572 KB |
Ok |
79 |
Correct |
574 ms |
43072 KB |
Ok |
80 |
Correct |
509 ms |
42672 KB |
Ok |
81 |
Correct |
573 ms |
43288 KB |
Ok |
82 |
Correct |
517 ms |
42800 KB |
Ok |
83 |
Correct |
534 ms |
41752 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
129 ms |
37492 KB |
Ok |
2 |
Correct |
110 ms |
37492 KB |
Ok |
3 |
Correct |
116 ms |
37496 KB |
Ok |
4 |
Correct |
119 ms |
37512 KB |
Ok |
5 |
Correct |
119 ms |
37492 KB |
Ok |
6 |
Correct |
122 ms |
37492 KB |
Ok |
7 |
Correct |
116 ms |
37444 KB |
Ok |
8 |
Correct |
108 ms |
37488 KB |
Ok |
9 |
Correct |
112 ms |
37488 KB |
Ok |
10 |
Correct |
112 ms |
37496 KB |
Ok |
11 |
Correct |
126 ms |
37504 KB |
Ok |
12 |
Correct |
114 ms |
37504 KB |
Ok |
13 |
Correct |
109 ms |
37384 KB |
Ok |
14 |
Correct |
117 ms |
37604 KB |
Ok |
15 |
Correct |
123 ms |
37492 KB |
Ok |
16 |
Correct |
123 ms |
37440 KB |
Ok |
17 |
Correct |
111 ms |
37460 KB |
Ok |
18 |
Correct |
113 ms |
37532 KB |
Ok |
19 |
Correct |
145 ms |
37768 KB |
Ok |
20 |
Correct |
118 ms |
37660 KB |
Ok |
21 |
Correct |
134 ms |
37844 KB |
Ok |
22 |
Correct |
121 ms |
37656 KB |
Ok |
23 |
Correct |
54 ms |
37528 KB |
Ok |
24 |
Correct |
115 ms |
37492 KB |
Ok |
25 |
Correct |
113 ms |
37492 KB |
Ok |
26 |
Correct |
114 ms |
37492 KB |
Ok |
27 |
Correct |
136 ms |
37492 KB |
Ok |
28 |
Correct |
126 ms |
37444 KB |
Ok |
29 |
Correct |
113 ms |
37540 KB |
Ok |
30 |
Correct |
113 ms |
37496 KB |
Ok |
31 |
Correct |
115 ms |
37496 KB |
Ok |
32 |
Correct |
110 ms |
37492 KB |
Ok |
33 |
Correct |
113 ms |
37584 KB |
Ok |
34 |
Correct |
111 ms |
37392 KB |
Ok |
35 |
Correct |
125 ms |
37492 KB |
Ok |
36 |
Correct |
115 ms |
37492 KB |
Ok |
37 |
Correct |
113 ms |
37492 KB |
Ok |
38 |
Correct |
113 ms |
37492 KB |
Ok |
39 |
Correct |
376 ms |
40476 KB |
Ok |
40 |
Correct |
306 ms |
39668 KB |
Ok |
41 |
Correct |
609 ms |
41844 KB |
Ok |
42 |
Correct |
436 ms |
42344 KB |
Ok |
43 |
Correct |
272 ms |
39364 KB |
Ok |
44 |
Correct |
479 ms |
41192 KB |
Ok |
45 |
Correct |
118 ms |
37524 KB |
Ok |
46 |
Correct |
131 ms |
37644 KB |
Ok |
47 |
Correct |
119 ms |
37448 KB |
Ok |
48 |
Correct |
125 ms |
37532 KB |
Ok |
49 |
Correct |
114 ms |
37632 KB |
Ok |
50 |
Correct |
115 ms |
37444 KB |
Ok |
51 |
Correct |
127 ms |
37628 KB |
Ok |
52 |
Correct |
110 ms |
37504 KB |
Ok |
53 |
Correct |
111 ms |
37536 KB |
Ok |
54 |
Correct |
128 ms |
37528 KB |
Ok |
55 |
Correct |
119 ms |
37704 KB |
Ok |
56 |
Correct |
117 ms |
37640 KB |
Ok |
57 |
Correct |
118 ms |
37524 KB |
Ok |
58 |
Correct |
120 ms |
37640 KB |
Ok |
59 |
Correct |
133 ms |
37592 KB |
Ok |
60 |
Correct |
123 ms |
37560 KB |
Ok |
61 |
Correct |
130 ms |
37536 KB |
Ok |
62 |
Correct |
117 ms |
37600 KB |
Ok |
63 |
Correct |
116 ms |
37572 KB |
Ok |
64 |
Correct |
126 ms |
37624 KB |
Ok |
65 |
Correct |
312 ms |
38924 KB |
Ok |
66 |
Correct |
363 ms |
39280 KB |
Ok |
67 |
Correct |
351 ms |
39128 KB |
Ok |
68 |
Correct |
315 ms |
39008 KB |
Ok |
69 |
Correct |
366 ms |
38980 KB |
Ok |
70 |
Correct |
323 ms |
39012 KB |
Ok |
71 |
Correct |
283 ms |
38784 KB |
Ok |
72 |
Correct |
306 ms |
38844 KB |
Ok |
73 |
Correct |
374 ms |
39204 KB |
Ok |
74 |
Correct |
314 ms |
38856 KB |
Ok |
75 |
Correct |
370 ms |
39168 KB |
Ok |
76 |
Correct |
357 ms |
39096 KB |
Ok |
77 |
Correct |
337 ms |
38964 KB |
Ok |
78 |
Correct |
273 ms |
38920 KB |
Ok |
79 |
Correct |
316 ms |
39000 KB |
Ok |
80 |
Correct |
534 ms |
42880 KB |
Ok |
81 |
Correct |
589 ms |
44384 KB |
Ok |
82 |
Correct |
537 ms |
42172 KB |
Ok |
83 |
Correct |
614 ms |
43220 KB |
Ok |
84 |
Correct |
621 ms |
42704 KB |
Ok |
85 |
Correct |
504 ms |
41600 KB |
Ok |
86 |
Correct |
490 ms |
41664 KB |
Ok |
87 |
Correct |
624 ms |
43796 KB |
Ok |
88 |
Correct |
543 ms |
41300 KB |
Ok |
89 |
Correct |
565 ms |
43572 KB |
Ok |
90 |
Correct |
574 ms |
43072 KB |
Ok |
91 |
Correct |
509 ms |
42672 KB |
Ok |
92 |
Correct |
573 ms |
43288 KB |
Ok |
93 |
Correct |
517 ms |
42800 KB |
Ok |
94 |
Correct |
534 ms |
41752 KB |
Ok |
95 |
Correct |
687 ms |
41428 KB |
Ok |
96 |
Correct |
1036 ms |
47728 KB |
Ok |
97 |
Correct |
1008 ms |
47520 KB |
Ok |
98 |
Correct |
746 ms |
46536 KB |
Ok |
99 |
Correct |
932 ms |
47168 KB |
Ok |
100 |
Correct |
984 ms |
46912 KB |
Ok |
101 |
Correct |
966 ms |
46996 KB |
Ok |
102 |
Correct |
926 ms |
46784 KB |
Ok |
103 |
Correct |
911 ms |
46936 KB |
Ok |
104 |
Correct |
1086 ms |
47856 KB |
Ok |
105 |
Correct |
1051 ms |
47288 KB |
Ok |
106 |
Correct |
814 ms |
46700 KB |
Ok |
107 |
Correct |
962 ms |
47368 KB |
Ok |
108 |
Correct |
1107 ms |
47980 KB |
Ok |
109 |
Correct |
980 ms |
49548 KB |
Ok |
110 |
Execution timed out |
2100 ms |
55548 KB |
Time limit exceeded |
111 |
Halted |
0 ms |
0 KB |
- |