#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,lef,rig,mid,tes,t,n,m,i,j,p[500009],pi,pr[500009],ans[500009],pas,zx,xc,it;
int bo[500009],fls;
deque <int> de;
void dfs(int q){
bo[q]=i;
pi++;
p[pi]=q;
if(q+n<=mid){
it=q+n;
if(bo[it]==i){
fls=1;return;
}
if(bo[it]==-1) dfs(it);
if(fls==1) return;
}
if(q>=m){
it=q-m;
if(bo[it]==i){
fls=1;return;
}
if(bo[it]==-1) dfs(it);
if(fls==1) return;
}
}
int main(){
// ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
// cin>>tes;
scanf("%d\n",&tes);
for(t=1; t<=tes; t++){
// cin>>n>>m;
scanf("%d%d\n",&n,&m);
lef=0;rig=400001;
pas=0;
// long long lonn=n,lonm=m;
// long long lon=lonn*lonm/__gcd(lonn,lonm),lonrg=rig;
// if(lonrg>lon) rig=lon;
/* if(rig==1){
// printf("0\n");
cout<<0<<endl;
continue;
}*/
// return 0;
while(1){
if(lef+1>=rig) break;
mid=(lef+rig)/2;
de.clear();
for(i=0; i<=mid; i++){
pr[i]=0;bo[i]=-1;
}
fls=0;
for(i=0; i<=mid; i++){
if(bo[i]==-1){
pi=0;
dfs(i);
if(fls==1) break;
for(j=pi; j>=1; j--){
de.push_front(p[j]);
}
}
}
if(fls==1){
rig=mid;
continue;
}
de.push_front(-1);
for(i=1; i<de.size(); i++){
if(de[i]==0){
zx=i;break;
}
}
for(i=1; i<de.size(); i++){
pr[de[i]]=zx-i;
}
pas=mid;
for(i=1; i<=mid; i++){
ans[i]=pr[i]-pr[i-1];
}
lef=mid;
}
printf("%d\n",pas);
//cout<<pas<<endl;
for(i=1; i<pas; i++) printf("%d ",ans[i]);/*cout<<ans[i]<<" ";*/
if(pas!=0){
printf("%d\n",ans[pas]);
//cout<<ans[pas]<<endl;
}
}
return 0;
}
Compilation message
sequence.cpp: In function 'int main()':
sequence.cpp:68:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=1; i<de.size(); i++){
~^~~~~~~~~~
sequence.cpp:73:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=1; i<de.size(); i++){
~^~~~~~~~~~
sequence.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d\n",&tes);
~~~~~^~~~~~~~~~~~~
sequence.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d\n",&n,&m);
~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
5752 KB |
Ok |
2 |
Correct |
25 ms |
5880 KB |
Ok |
3 |
Correct |
10 ms |
2168 KB |
Ok |
4 |
Correct |
11 ms |
2168 KB |
Ok |
5 |
Correct |
10 ms |
2168 KB |
Ok |
6 |
Correct |
11 ms |
2936 KB |
Ok |
7 |
Correct |
10 ms |
2168 KB |
Ok |
8 |
Correct |
11 ms |
2936 KB |
Ok |
9 |
Correct |
9 ms |
2040 KB |
Ok |
10 |
Correct |
12 ms |
3836 KB |
Ok |
11 |
Correct |
9 ms |
2040 KB |
Ok |
12 |
Correct |
9 ms |
2040 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
3960 KB |
Ok |
2 |
Correct |
16 ms |
3832 KB |
Ok |
3 |
Correct |
20 ms |
3832 KB |
Ok |
4 |
Correct |
17 ms |
3940 KB |
Ok |
5 |
Correct |
16 ms |
3832 KB |
Ok |
6 |
Correct |
23 ms |
3960 KB |
Ok |
7 |
Correct |
44 ms |
4472 KB |
Ok |
8 |
Correct |
34 ms |
4088 KB |
Ok |
9 |
Correct |
48 ms |
4560 KB |
Ok |
10 |
Correct |
37 ms |
4344 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
5752 KB |
Ok |
2 |
Correct |
31 ms |
5896 KB |
Ok |
3 |
Correct |
23 ms |
3832 KB |
Ok |
4 |
Correct |
18 ms |
3192 KB |
Ok |
5 |
Correct |
22 ms |
5752 KB |
Ok |
6 |
Correct |
21 ms |
5752 KB |
Ok |
7 |
Correct |
21 ms |
5860 KB |
Ok |
8 |
Correct |
19 ms |
5752 KB |
Ok |
9 |
Correct |
19 ms |
5880 KB |
Ok |
10 |
Correct |
15 ms |
3832 KB |
Ok |
11 |
Correct |
14 ms |
3196 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
3832 KB |
Ok |
2 |
Correct |
12 ms |
2424 KB |
Ok |
3 |
Correct |
11 ms |
2168 KB |
Ok |
4 |
Correct |
10 ms |
2172 KB |
Ok |
5 |
Correct |
10 ms |
2040 KB |
Ok |
6 |
Correct |
283 ms |
8608 KB |
Ok |
7 |
Correct |
242 ms |
8088 KB |
Ok |
8 |
Correct |
473 ms |
11284 KB |
Ok |
9 |
Correct |
357 ms |
10016 KB |
Ok |
10 |
Correct |
204 ms |
5624 KB |
Ok |
11 |
Correct |
366 ms |
9608 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
5752 KB |
Ok |
2 |
Correct |
25 ms |
5880 KB |
Ok |
3 |
Correct |
10 ms |
2168 KB |
Ok |
4 |
Correct |
11 ms |
2168 KB |
Ok |
5 |
Correct |
10 ms |
2168 KB |
Ok |
6 |
Correct |
11 ms |
2936 KB |
Ok |
7 |
Correct |
10 ms |
2168 KB |
Ok |
8 |
Correct |
11 ms |
2936 KB |
Ok |
9 |
Correct |
9 ms |
2040 KB |
Ok |
10 |
Correct |
12 ms |
3836 KB |
Ok |
11 |
Correct |
9 ms |
2040 KB |
Ok |
12 |
Correct |
9 ms |
2040 KB |
Ok |
13 |
Correct |
14 ms |
5752 KB |
Ok |
14 |
Correct |
31 ms |
5896 KB |
Ok |
15 |
Correct |
23 ms |
3832 KB |
Ok |
16 |
Correct |
18 ms |
3192 KB |
Ok |
17 |
Correct |
22 ms |
5752 KB |
Ok |
18 |
Correct |
21 ms |
5752 KB |
Ok |
19 |
Correct |
21 ms |
5860 KB |
Ok |
20 |
Correct |
19 ms |
5752 KB |
Ok |
21 |
Correct |
19 ms |
5880 KB |
Ok |
22 |
Correct |
15 ms |
3832 KB |
Ok |
23 |
Correct |
14 ms |
3196 KB |
Ok |
24 |
Correct |
12 ms |
2012 KB |
Ok |
25 |
Correct |
12 ms |
2012 KB |
Ok |
26 |
Correct |
13 ms |
2040 KB |
Ok |
27 |
Correct |
12 ms |
1912 KB |
Ok |
28 |
Correct |
13 ms |
2040 KB |
Ok |
29 |
Correct |
12 ms |
2040 KB |
Ok |
30 |
Correct |
12 ms |
1912 KB |
Ok |
31 |
Correct |
13 ms |
2040 KB |
Ok |
32 |
Correct |
14 ms |
1912 KB |
Ok |
33 |
Correct |
13 ms |
2040 KB |
Ok |
34 |
Correct |
18 ms |
2040 KB |
Ok |
35 |
Correct |
19 ms |
2168 KB |
Ok |
36 |
Correct |
18 ms |
2168 KB |
Ok |
37 |
Correct |
19 ms |
2172 KB |
Ok |
38 |
Correct |
19 ms |
2168 KB |
Ok |
39 |
Correct |
18 ms |
2044 KB |
Ok |
40 |
Correct |
20 ms |
2168 KB |
Ok |
41 |
Correct |
19 ms |
2168 KB |
Ok |
42 |
Correct |
18 ms |
2168 KB |
Ok |
43 |
Correct |
21 ms |
2168 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
5752 KB |
Ok |
2 |
Correct |
25 ms |
5880 KB |
Ok |
3 |
Correct |
10 ms |
2168 KB |
Ok |
4 |
Correct |
11 ms |
2168 KB |
Ok |
5 |
Correct |
10 ms |
2168 KB |
Ok |
6 |
Correct |
11 ms |
2936 KB |
Ok |
7 |
Correct |
10 ms |
2168 KB |
Ok |
8 |
Correct |
11 ms |
2936 KB |
Ok |
9 |
Correct |
9 ms |
2040 KB |
Ok |
10 |
Correct |
12 ms |
3836 KB |
Ok |
11 |
Correct |
9 ms |
2040 KB |
Ok |
12 |
Correct |
9 ms |
2040 KB |
Ok |
13 |
Correct |
20 ms |
3960 KB |
Ok |
14 |
Correct |
16 ms |
3832 KB |
Ok |
15 |
Correct |
20 ms |
3832 KB |
Ok |
16 |
Correct |
17 ms |
3940 KB |
Ok |
17 |
Correct |
16 ms |
3832 KB |
Ok |
18 |
Correct |
23 ms |
3960 KB |
Ok |
19 |
Correct |
44 ms |
4472 KB |
Ok |
20 |
Correct |
34 ms |
4088 KB |
Ok |
21 |
Correct |
48 ms |
4560 KB |
Ok |
22 |
Correct |
37 ms |
4344 KB |
Ok |
23 |
Correct |
14 ms |
5752 KB |
Ok |
24 |
Correct |
31 ms |
5896 KB |
Ok |
25 |
Correct |
23 ms |
3832 KB |
Ok |
26 |
Correct |
18 ms |
3192 KB |
Ok |
27 |
Correct |
22 ms |
5752 KB |
Ok |
28 |
Correct |
21 ms |
5752 KB |
Ok |
29 |
Correct |
21 ms |
5860 KB |
Ok |
30 |
Correct |
19 ms |
5752 KB |
Ok |
31 |
Correct |
19 ms |
5880 KB |
Ok |
32 |
Correct |
15 ms |
3832 KB |
Ok |
33 |
Correct |
14 ms |
3196 KB |
Ok |
34 |
Correct |
12 ms |
2012 KB |
Ok |
35 |
Correct |
12 ms |
2012 KB |
Ok |
36 |
Correct |
13 ms |
2040 KB |
Ok |
37 |
Correct |
12 ms |
1912 KB |
Ok |
38 |
Correct |
13 ms |
2040 KB |
Ok |
39 |
Correct |
12 ms |
2040 KB |
Ok |
40 |
Correct |
12 ms |
1912 KB |
Ok |
41 |
Correct |
13 ms |
2040 KB |
Ok |
42 |
Correct |
14 ms |
1912 KB |
Ok |
43 |
Correct |
13 ms |
2040 KB |
Ok |
44 |
Correct |
18 ms |
2040 KB |
Ok |
45 |
Correct |
19 ms |
2168 KB |
Ok |
46 |
Correct |
18 ms |
2168 KB |
Ok |
47 |
Correct |
19 ms |
2172 KB |
Ok |
48 |
Correct |
19 ms |
2168 KB |
Ok |
49 |
Correct |
18 ms |
2044 KB |
Ok |
50 |
Correct |
20 ms |
2168 KB |
Ok |
51 |
Correct |
19 ms |
2168 KB |
Ok |
52 |
Correct |
18 ms |
2168 KB |
Ok |
53 |
Correct |
21 ms |
2168 KB |
Ok |
54 |
Correct |
189 ms |
4324 KB |
Ok |
55 |
Correct |
238 ms |
4684 KB |
Ok |
56 |
Correct |
230 ms |
4856 KB |
Ok |
57 |
Correct |
170 ms |
3908 KB |
Ok |
58 |
Correct |
205 ms |
4304 KB |
Ok |
59 |
Correct |
201 ms |
3960 KB |
Ok |
60 |
Correct |
169 ms |
3892 KB |
Ok |
61 |
Correct |
165 ms |
3900 KB |
Ok |
62 |
Correct |
229 ms |
4384 KB |
Ok |
63 |
Correct |
177 ms |
4088 KB |
Ok |
64 |
Correct |
219 ms |
4680 KB |
Ok |
65 |
Correct |
226 ms |
4420 KB |
Ok |
66 |
Correct |
194 ms |
4088 KB |
Ok |
67 |
Correct |
173 ms |
4060 KB |
Ok |
68 |
Correct |
197 ms |
4228 KB |
Ok |
69 |
Correct |
489 ms |
9980 KB |
Ok |
70 |
Correct |
499 ms |
10640 KB |
Ok |
71 |
Correct |
444 ms |
9976 KB |
Ok |
72 |
Correct |
471 ms |
9848 KB |
Ok |
73 |
Correct |
457 ms |
10072 KB |
Ok |
74 |
Correct |
436 ms |
9964 KB |
Ok |
75 |
Correct |
463 ms |
9392 KB |
Ok |
76 |
Correct |
521 ms |
10232 KB |
Ok |
77 |
Correct |
436 ms |
9624 KB |
Ok |
78 |
Correct |
535 ms |
10020 KB |
Ok |
79 |
Correct |
444 ms |
10112 KB |
Ok |
80 |
Correct |
562 ms |
10232 KB |
Ok |
81 |
Correct |
513 ms |
10076 KB |
Ok |
82 |
Correct |
457 ms |
10076 KB |
Ok |
83 |
Correct |
443 ms |
9464 KB |
Ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
5752 KB |
Ok |
2 |
Correct |
25 ms |
5880 KB |
Ok |
3 |
Correct |
10 ms |
2168 KB |
Ok |
4 |
Correct |
11 ms |
2168 KB |
Ok |
5 |
Correct |
10 ms |
2168 KB |
Ok |
6 |
Correct |
11 ms |
2936 KB |
Ok |
7 |
Correct |
10 ms |
2168 KB |
Ok |
8 |
Correct |
11 ms |
2936 KB |
Ok |
9 |
Correct |
9 ms |
2040 KB |
Ok |
10 |
Correct |
12 ms |
3836 KB |
Ok |
11 |
Correct |
9 ms |
2040 KB |
Ok |
12 |
Correct |
9 ms |
2040 KB |
Ok |
13 |
Correct |
20 ms |
3960 KB |
Ok |
14 |
Correct |
16 ms |
3832 KB |
Ok |
15 |
Correct |
20 ms |
3832 KB |
Ok |
16 |
Correct |
17 ms |
3940 KB |
Ok |
17 |
Correct |
16 ms |
3832 KB |
Ok |
18 |
Correct |
23 ms |
3960 KB |
Ok |
19 |
Correct |
44 ms |
4472 KB |
Ok |
20 |
Correct |
34 ms |
4088 KB |
Ok |
21 |
Correct |
48 ms |
4560 KB |
Ok |
22 |
Correct |
37 ms |
4344 KB |
Ok |
23 |
Correct |
14 ms |
5752 KB |
Ok |
24 |
Correct |
31 ms |
5896 KB |
Ok |
25 |
Correct |
23 ms |
3832 KB |
Ok |
26 |
Correct |
18 ms |
3192 KB |
Ok |
27 |
Correct |
22 ms |
5752 KB |
Ok |
28 |
Correct |
21 ms |
5752 KB |
Ok |
29 |
Correct |
21 ms |
5860 KB |
Ok |
30 |
Correct |
19 ms |
5752 KB |
Ok |
31 |
Correct |
19 ms |
5880 KB |
Ok |
32 |
Correct |
15 ms |
3832 KB |
Ok |
33 |
Correct |
14 ms |
3196 KB |
Ok |
34 |
Correct |
18 ms |
3832 KB |
Ok |
35 |
Correct |
12 ms |
2424 KB |
Ok |
36 |
Correct |
11 ms |
2168 KB |
Ok |
37 |
Correct |
10 ms |
2172 KB |
Ok |
38 |
Correct |
10 ms |
2040 KB |
Ok |
39 |
Correct |
283 ms |
8608 KB |
Ok |
40 |
Correct |
242 ms |
8088 KB |
Ok |
41 |
Correct |
473 ms |
11284 KB |
Ok |
42 |
Correct |
357 ms |
10016 KB |
Ok |
43 |
Correct |
204 ms |
5624 KB |
Ok |
44 |
Correct |
366 ms |
9608 KB |
Ok |
45 |
Correct |
12 ms |
2012 KB |
Ok |
46 |
Correct |
12 ms |
2012 KB |
Ok |
47 |
Correct |
13 ms |
2040 KB |
Ok |
48 |
Correct |
12 ms |
1912 KB |
Ok |
49 |
Correct |
13 ms |
2040 KB |
Ok |
50 |
Correct |
12 ms |
2040 KB |
Ok |
51 |
Correct |
12 ms |
1912 KB |
Ok |
52 |
Correct |
13 ms |
2040 KB |
Ok |
53 |
Correct |
14 ms |
1912 KB |
Ok |
54 |
Correct |
13 ms |
2040 KB |
Ok |
55 |
Correct |
18 ms |
2040 KB |
Ok |
56 |
Correct |
19 ms |
2168 KB |
Ok |
57 |
Correct |
18 ms |
2168 KB |
Ok |
58 |
Correct |
19 ms |
2172 KB |
Ok |
59 |
Correct |
19 ms |
2168 KB |
Ok |
60 |
Correct |
18 ms |
2044 KB |
Ok |
61 |
Correct |
20 ms |
2168 KB |
Ok |
62 |
Correct |
19 ms |
2168 KB |
Ok |
63 |
Correct |
18 ms |
2168 KB |
Ok |
64 |
Correct |
21 ms |
2168 KB |
Ok |
65 |
Correct |
189 ms |
4324 KB |
Ok |
66 |
Correct |
238 ms |
4684 KB |
Ok |
67 |
Correct |
230 ms |
4856 KB |
Ok |
68 |
Correct |
170 ms |
3908 KB |
Ok |
69 |
Correct |
205 ms |
4304 KB |
Ok |
70 |
Correct |
201 ms |
3960 KB |
Ok |
71 |
Correct |
169 ms |
3892 KB |
Ok |
72 |
Correct |
165 ms |
3900 KB |
Ok |
73 |
Correct |
229 ms |
4384 KB |
Ok |
74 |
Correct |
177 ms |
4088 KB |
Ok |
75 |
Correct |
219 ms |
4680 KB |
Ok |
76 |
Correct |
226 ms |
4420 KB |
Ok |
77 |
Correct |
194 ms |
4088 KB |
Ok |
78 |
Correct |
173 ms |
4060 KB |
Ok |
79 |
Correct |
197 ms |
4228 KB |
Ok |
80 |
Correct |
489 ms |
9980 KB |
Ok |
81 |
Correct |
499 ms |
10640 KB |
Ok |
82 |
Correct |
444 ms |
9976 KB |
Ok |
83 |
Correct |
471 ms |
9848 KB |
Ok |
84 |
Correct |
457 ms |
10072 KB |
Ok |
85 |
Correct |
436 ms |
9964 KB |
Ok |
86 |
Correct |
463 ms |
9392 KB |
Ok |
87 |
Correct |
521 ms |
10232 KB |
Ok |
88 |
Correct |
436 ms |
9624 KB |
Ok |
89 |
Correct |
535 ms |
10020 KB |
Ok |
90 |
Correct |
444 ms |
10112 KB |
Ok |
91 |
Correct |
562 ms |
10232 KB |
Ok |
92 |
Correct |
513 ms |
10076 KB |
Ok |
93 |
Correct |
457 ms |
10076 KB |
Ok |
94 |
Correct |
443 ms |
9464 KB |
Ok |
95 |
Correct |
519 ms |
8888 KB |
Ok |
96 |
Correct |
756 ms |
11812 KB |
Ok |
97 |
Correct |
729 ms |
10040 KB |
Ok |
98 |
Correct |
542 ms |
9384 KB |
Ok |
99 |
Correct |
692 ms |
9608 KB |
Ok |
100 |
Correct |
650 ms |
9748 KB |
Ok |
101 |
Correct |
760 ms |
11000 KB |
Ok |
102 |
Correct |
692 ms |
10140 KB |
Ok |
103 |
Correct |
642 ms |
10256 KB |
Ok |
104 |
Correct |
810 ms |
12036 KB |
Ok |
105 |
Correct |
672 ms |
11976 KB |
Ok |
106 |
Correct |
651 ms |
11548 KB |
Ok |
107 |
Correct |
727 ms |
11196 KB |
Ok |
108 |
Correct |
760 ms |
12088 KB |
Ok |
109 |
Correct |
695 ms |
12116 KB |
Ok |
110 |
Execution timed out |
2021 ms |
34276 KB |
Time limit exceeded |
111 |
Halted |
0 ms |
0 KB |
- |