Submission #173125

# Submission time Handle Problem Language Result Execution time Memory
173125 2020-01-03T12:08:06 Z mosiashvililuka Nice sequence (IZhO18_sequence) C++14
100 / 100
1829 ms 40260 KB
#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,deq;
int bo[500009],fls;
int de[500009];
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(){
    scanf("%d\n",&tes);
    for(t=1; t<=tes; t++){
        scanf("%d%d\n",&n,&m);
        lef=0;rig=400001;
        pas=0;
        while(1){
            if(lef+1>=rig) break;
            mid=(lef+rig)/2;
            deq=0;
            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--){
                        deq++;
                        de[deq]=p[j];
                    }
                }
            }
            if(fls==1){
                rig=mid;
                continue;
            }
            for(i=1; i<=deq/2; i++){
                swap(de[i],de[deq-i+1]);
            }
            for(i=1; i<=deq; i++){
                if(de[i]==0){
                    zx=i;break;
                }
            }
            for(i=1; i<=deq; 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);
        for(i=1; i<pas; i++) printf("%d ",ans[i]);/*cout<<ans[i]<<" ";*/
        if(pas!=0){
            printf("%d\n",ans[pas]);
        }
    }
    return 0;
}

Compilation message

sequence.cpp: In function 'int main()':
sequence.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d\n",&tes);
     ~~~~~^~~~~~~~~~~~~
sequence.cpp:30: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 5880 KB Ok
2 Correct 23 ms 5756 KB Ok
3 Correct 10 ms 2168 KB Ok
4 Correct 10 ms 2140 KB Ok
5 Correct 10 ms 2232 KB Ok
6 Correct 11 ms 2888 KB Ok
7 Correct 10 ms 2040 KB Ok
8 Correct 11 ms 2972 KB Ok
9 Correct 9 ms 2040 KB Ok
10 Correct 12 ms 3832 KB Ok
11 Correct 9 ms 2040 KB Ok
12 Correct 10 ms 2012 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 20 ms 3832 KB Ok
2 Correct 19 ms 3832 KB Ok
3 Correct 20 ms 3832 KB Ok
4 Correct 17 ms 3832 KB Ok
5 Correct 18 ms 3832 KB Ok
6 Correct 22 ms 3960 KB Ok
7 Correct 41 ms 4444 KB Ok
8 Correct 32 ms 4060 KB Ok
9 Correct 45 ms 4584 KB Ok
10 Correct 35 ms 4272 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 15 ms 5876 KB Ok
2 Correct 37 ms 5864 KB Ok
3 Correct 22 ms 3832 KB Ok
4 Correct 18 ms 3164 KB Ok
5 Correct 22 ms 5864 KB Ok
6 Correct 19 ms 5744 KB Ok
7 Correct 21 ms 5860 KB Ok
8 Correct 21 ms 5872 KB Ok
9 Correct 20 ms 5852 KB Ok
10 Correct 16 ms 3888 KB Ok
11 Correct 14 ms 3192 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 17 ms 3904 KB Ok
2 Correct 12 ms 2424 KB Ok
3 Correct 11 ms 2256 KB Ok
4 Correct 11 ms 2140 KB Ok
5 Correct 10 ms 2128 KB Ok
6 Correct 251 ms 8424 KB Ok
7 Correct 215 ms 7876 KB Ok
8 Correct 427 ms 11288 KB Ok
9 Correct 311 ms 9916 KB Ok
10 Correct 182 ms 5536 KB Ok
11 Correct 319 ms 9336 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 28 ms 5880 KB Ok
2 Correct 23 ms 5756 KB Ok
3 Correct 10 ms 2168 KB Ok
4 Correct 10 ms 2140 KB Ok
5 Correct 10 ms 2232 KB Ok
6 Correct 11 ms 2888 KB Ok
7 Correct 10 ms 2040 KB Ok
8 Correct 11 ms 2972 KB Ok
9 Correct 9 ms 2040 KB Ok
10 Correct 12 ms 3832 KB Ok
11 Correct 9 ms 2040 KB Ok
12 Correct 10 ms 2012 KB Ok
13 Correct 15 ms 5876 KB Ok
14 Correct 37 ms 5864 KB Ok
15 Correct 22 ms 3832 KB Ok
16 Correct 18 ms 3164 KB Ok
17 Correct 22 ms 5864 KB Ok
18 Correct 19 ms 5744 KB Ok
19 Correct 21 ms 5860 KB Ok
20 Correct 21 ms 5872 KB Ok
21 Correct 20 ms 5852 KB Ok
22 Correct 16 ms 3888 KB Ok
23 Correct 14 ms 3192 KB Ok
24 Correct 12 ms 1912 KB Ok
25 Correct 12 ms 2040 KB Ok
26 Correct 12 ms 2040 KB Ok
27 Correct 12 ms 1912 KB Ok
28 Correct 12 ms 2040 KB Ok
29 Correct 11 ms 1912 KB Ok
30 Correct 11 ms 1912 KB Ok
31 Correct 12 ms 1912 KB Ok
32 Correct 12 ms 1916 KB Ok
33 Correct 16 ms 2040 KB Ok
34 Correct 17 ms 2040 KB Ok
35 Correct 18 ms 2168 KB Ok
36 Correct 17 ms 2168 KB Ok
37 Correct 18 ms 2168 KB Ok
38 Correct 18 ms 2216 KB Ok
39 Correct 17 ms 2168 KB Ok
40 Correct 19 ms 2168 KB Ok
41 Correct 18 ms 2168 KB Ok
42 Correct 17 ms 2168 KB Ok
43 Correct 19 ms 2168 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 28 ms 5880 KB Ok
2 Correct 23 ms 5756 KB Ok
3 Correct 10 ms 2168 KB Ok
4 Correct 10 ms 2140 KB Ok
5 Correct 10 ms 2232 KB Ok
6 Correct 11 ms 2888 KB Ok
7 Correct 10 ms 2040 KB Ok
8 Correct 11 ms 2972 KB Ok
9 Correct 9 ms 2040 KB Ok
10 Correct 12 ms 3832 KB Ok
11 Correct 9 ms 2040 KB Ok
12 Correct 10 ms 2012 KB Ok
13 Correct 20 ms 3832 KB Ok
14 Correct 19 ms 3832 KB Ok
15 Correct 20 ms 3832 KB Ok
16 Correct 17 ms 3832 KB Ok
17 Correct 18 ms 3832 KB Ok
18 Correct 22 ms 3960 KB Ok
19 Correct 41 ms 4444 KB Ok
20 Correct 32 ms 4060 KB Ok
21 Correct 45 ms 4584 KB Ok
22 Correct 35 ms 4272 KB Ok
23 Correct 15 ms 5876 KB Ok
24 Correct 37 ms 5864 KB Ok
25 Correct 22 ms 3832 KB Ok
26 Correct 18 ms 3164 KB Ok
27 Correct 22 ms 5864 KB Ok
28 Correct 19 ms 5744 KB Ok
29 Correct 21 ms 5860 KB Ok
30 Correct 21 ms 5872 KB Ok
31 Correct 20 ms 5852 KB Ok
32 Correct 16 ms 3888 KB Ok
33 Correct 14 ms 3192 KB Ok
34 Correct 12 ms 1912 KB Ok
35 Correct 12 ms 2040 KB Ok
36 Correct 12 ms 2040 KB Ok
37 Correct 12 ms 1912 KB Ok
38 Correct 12 ms 2040 KB Ok
39 Correct 11 ms 1912 KB Ok
40 Correct 11 ms 1912 KB Ok
41 Correct 12 ms 1912 KB Ok
42 Correct 12 ms 1916 KB Ok
43 Correct 16 ms 2040 KB Ok
44 Correct 17 ms 2040 KB Ok
45 Correct 18 ms 2168 KB Ok
46 Correct 17 ms 2168 KB Ok
47 Correct 18 ms 2168 KB Ok
48 Correct 18 ms 2216 KB Ok
49 Correct 17 ms 2168 KB Ok
50 Correct 19 ms 2168 KB Ok
51 Correct 18 ms 2168 KB Ok
52 Correct 17 ms 2168 KB Ok
53 Correct 19 ms 2168 KB Ok
54 Correct 161 ms 4316 KB Ok
55 Correct 198 ms 4600 KB Ok
56 Correct 193 ms 4856 KB Ok
57 Correct 147 ms 3960 KB Ok
58 Correct 172 ms 4088 KB Ok
59 Correct 183 ms 3960 KB Ok
60 Correct 141 ms 3832 KB Ok
61 Correct 142 ms 3960 KB Ok
62 Correct 195 ms 4472 KB Ok
63 Correct 153 ms 4208 KB Ok
64 Correct 195 ms 4600 KB Ok
65 Correct 192 ms 4348 KB Ok
66 Correct 164 ms 4216 KB Ok
67 Correct 153 ms 4188 KB Ok
68 Correct 168 ms 4232 KB Ok
69 Correct 356 ms 9824 KB Ok
70 Correct 370 ms 10616 KB Ok
71 Correct 332 ms 9996 KB Ok
72 Correct 358 ms 9720 KB Ok
73 Correct 345 ms 9980 KB Ok
74 Correct 324 ms 9848 KB Ok
75 Correct 339 ms 9336 KB Ok
76 Correct 370 ms 10100 KB Ok
77 Correct 318 ms 9544 KB Ok
78 Correct 368 ms 9872 KB Ok
79 Correct 348 ms 10104 KB Ok
80 Correct 355 ms 10092 KB Ok
81 Correct 367 ms 10036 KB Ok
82 Correct 349 ms 10100 KB Ok
83 Correct 327 ms 9464 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 28 ms 5880 KB Ok
2 Correct 23 ms 5756 KB Ok
3 Correct 10 ms 2168 KB Ok
4 Correct 10 ms 2140 KB Ok
5 Correct 10 ms 2232 KB Ok
6 Correct 11 ms 2888 KB Ok
7 Correct 10 ms 2040 KB Ok
8 Correct 11 ms 2972 KB Ok
9 Correct 9 ms 2040 KB Ok
10 Correct 12 ms 3832 KB Ok
11 Correct 9 ms 2040 KB Ok
12 Correct 10 ms 2012 KB Ok
13 Correct 20 ms 3832 KB Ok
14 Correct 19 ms 3832 KB Ok
15 Correct 20 ms 3832 KB Ok
16 Correct 17 ms 3832 KB Ok
17 Correct 18 ms 3832 KB Ok
18 Correct 22 ms 3960 KB Ok
19 Correct 41 ms 4444 KB Ok
20 Correct 32 ms 4060 KB Ok
21 Correct 45 ms 4584 KB Ok
22 Correct 35 ms 4272 KB Ok
23 Correct 15 ms 5876 KB Ok
24 Correct 37 ms 5864 KB Ok
25 Correct 22 ms 3832 KB Ok
26 Correct 18 ms 3164 KB Ok
27 Correct 22 ms 5864 KB Ok
28 Correct 19 ms 5744 KB Ok
29 Correct 21 ms 5860 KB Ok
30 Correct 21 ms 5872 KB Ok
31 Correct 20 ms 5852 KB Ok
32 Correct 16 ms 3888 KB Ok
33 Correct 14 ms 3192 KB Ok
34 Correct 17 ms 3904 KB Ok
35 Correct 12 ms 2424 KB Ok
36 Correct 11 ms 2256 KB Ok
37 Correct 11 ms 2140 KB Ok
38 Correct 10 ms 2128 KB Ok
39 Correct 251 ms 8424 KB Ok
40 Correct 215 ms 7876 KB Ok
41 Correct 427 ms 11288 KB Ok
42 Correct 311 ms 9916 KB Ok
43 Correct 182 ms 5536 KB Ok
44 Correct 319 ms 9336 KB Ok
45 Correct 12 ms 1912 KB Ok
46 Correct 12 ms 2040 KB Ok
47 Correct 12 ms 2040 KB Ok
48 Correct 12 ms 1912 KB Ok
49 Correct 12 ms 2040 KB Ok
50 Correct 11 ms 1912 KB Ok
51 Correct 11 ms 1912 KB Ok
52 Correct 12 ms 1912 KB Ok
53 Correct 12 ms 1916 KB Ok
54 Correct 16 ms 2040 KB Ok
55 Correct 17 ms 2040 KB Ok
56 Correct 18 ms 2168 KB Ok
57 Correct 17 ms 2168 KB Ok
58 Correct 18 ms 2168 KB Ok
59 Correct 18 ms 2216 KB Ok
60 Correct 17 ms 2168 KB Ok
61 Correct 19 ms 2168 KB Ok
62 Correct 18 ms 2168 KB Ok
63 Correct 17 ms 2168 KB Ok
64 Correct 19 ms 2168 KB Ok
65 Correct 161 ms 4316 KB Ok
66 Correct 198 ms 4600 KB Ok
67 Correct 193 ms 4856 KB Ok
68 Correct 147 ms 3960 KB Ok
69 Correct 172 ms 4088 KB Ok
70 Correct 183 ms 3960 KB Ok
71 Correct 141 ms 3832 KB Ok
72 Correct 142 ms 3960 KB Ok
73 Correct 195 ms 4472 KB Ok
74 Correct 153 ms 4208 KB Ok
75 Correct 195 ms 4600 KB Ok
76 Correct 192 ms 4348 KB Ok
77 Correct 164 ms 4216 KB Ok
78 Correct 153 ms 4188 KB Ok
79 Correct 168 ms 4232 KB Ok
80 Correct 356 ms 9824 KB Ok
81 Correct 370 ms 10616 KB Ok
82 Correct 332 ms 9996 KB Ok
83 Correct 358 ms 9720 KB Ok
84 Correct 345 ms 9980 KB Ok
85 Correct 324 ms 9848 KB Ok
86 Correct 339 ms 9336 KB Ok
87 Correct 370 ms 10100 KB Ok
88 Correct 318 ms 9544 KB Ok
89 Correct 368 ms 9872 KB Ok
90 Correct 348 ms 10104 KB Ok
91 Correct 355 ms 10092 KB Ok
92 Correct 367 ms 10036 KB Ok
93 Correct 349 ms 10100 KB Ok
94 Correct 327 ms 9464 KB Ok
95 Correct 442 ms 8820 KB Ok
96 Correct 621 ms 11768 KB Ok
97 Correct 599 ms 10084 KB Ok
98 Correct 477 ms 9576 KB Ok
99 Correct 570 ms 9612 KB Ok
100 Correct 528 ms 9616 KB Ok
101 Correct 615 ms 10588 KB Ok
102 Correct 569 ms 9924 KB Ok
103 Correct 536 ms 10372 KB Ok
104 Correct 672 ms 11652 KB Ok
105 Correct 563 ms 11688 KB Ok
106 Correct 543 ms 11400 KB Ok
107 Correct 601 ms 11000 KB Ok
108 Correct 614 ms 11896 KB Ok
109 Correct 562 ms 11896 KB Ok
110 Correct 1461 ms 36572 KB Ok
111 Correct 1829 ms 39188 KB Ok
112 Correct 1474 ms 38948 KB Ok
113 Correct 1713 ms 38388 KB Ok
114 Correct 1674 ms 40260 KB Ok
115 Correct 1674 ms 38008 KB Ok
116 Correct 1614 ms 39388 KB Ok
117 Correct 1736 ms 38084 KB Ok
118 Correct 1582 ms 37952 KB Ok
119 Correct 1796 ms 38008 KB Ok
120 Correct 1685 ms 37660 KB Ok
121 Correct 1552 ms 36300 KB Ok
122 Correct 1604 ms 39156 KB Ok
123 Correct 1737 ms 39156 KB Ok
124 Correct 1353 ms 36600 KB Ok
125 Correct 1527 ms 21564 KB Ok