Submission #1086564

# Submission time Handle Problem Language Result Execution time Memory
1086564 2024-09-11T04:11:57 Z 8pete8 Nice sequence (IZhO18_sequence) C
100 / 100
806 ms 73844 KB
#include<stdio.h>
#include <stdlib.h>
#define int long long
int compare(const void* a, const void* b){
   return (*(int*)a - *(int*)b);
}
const int mx=1e9,mxn=400000;
int k=0;
int *adj[400000+10],sz[400000+10],vis[400000+10],ord[400000+10],cnt=0;
int what[400000+10];
void ts(int cur){
    vis[cur]=1;
    for(int i=0;i<sz[cur];i++)if(!vis[adj[cur][i]])ts(adj[cur][i]);
    ord[cnt++]=cur;
}
void re(int m,int n){
    //get length
    k+=(m/n)*n;
    if(m%n)re(n,m%n);
}
void add(int x,int y){
    int o=sz[x]++;
    if(!o)adj[x]=(int*)malloc(2 * sizeof ** adj);
    else if(0==(o&o-1))adj[x]=(int*)realloc(sz[x],2*o*sizeof **adj);
    adj[x][o]=y;
}
void solve(){
    k=0,cnt=0;
    int n,m;scanf("%lld %lld",&n,&m);
    int mul=-1;
    if(n>m){
        n^=m,m^=n,n^=m;
        mul=1;
    }
    re(m,n);
    k--;
    for(int i=0;i<=k;i++){
        if(i-m>=0)add(i,i-m);
        if(i-n>=0)add(i-n,i);
    }
    printf("%lld\n",k);
    for(int i=0;i<=k;i++)if(!vis[i])ts(i);
    int mx2=mx;
    for(int i=0;i<=k;i++)what[ord[i]]=mx2--;
    for(int i=1;i<=k;i++)printf("%lld ",mul*(what[i]-what[i-1]));
    for(int i=0;i<=k;i++){
        if(adj[i]!=NULL)free(adj[i]);
        adj[i]=NULL;
        sz[i]=what[i]=vis[i]=0;
    }
    printf("\n");
}
int32_t main(){
    int t;scanf("%lld",&t);
    while(t--)solve();
}
/*
 
+++-
 
3
3 1
2 3 
1 1

case 


 
*/

Compilation message

sequence.c: In function 'add':
sequence.c:24:20: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   24 |     else if(0==(o&o-1))adj[x]=(int*)realloc(sz[x],2*o*sizeof **adj);
      |                   ~^~
sequence.c:24:47: warning: passing argument 1 of 'realloc' makes pointer from integer without a cast [-Wint-conversion]
   24 |     else if(0==(o&o-1))adj[x]=(int*)realloc(sz[x],2*o*sizeof **adj);
      |                                             ~~^~~
      |                                               |
      |                                               long long int
In file included from sequence.c:2:
/usr/include/stdlib.h:550:29: note: expected 'void *' but argument is of type 'long long int'
  550 | extern void *realloc (void *__ptr, size_t __size)
      |                       ~~~~~~^~~~~
sequence.c: In function 'solve':
sequence.c:29:13: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     int n,m;scanf("%lld %lld",&n,&m);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~
sequence.c: In function 'main':
sequence.c:54:11: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |     int t;scanf("%lld",&t);
      |           ^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 0 ms 348 KB Ok
4 Correct 0 ms 348 KB Ok
5 Correct 0 ms 348 KB Ok
6 Correct 0 ms 348 KB Ok
7 Correct 0 ms 344 KB Ok
8 Correct 0 ms 424 KB Ok
9 Correct 0 ms 348 KB Ok
10 Correct 0 ms 348 KB Ok
11 Correct 0 ms 348 KB Ok
12 Correct 0 ms 344 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 0 ms 348 KB Ok
4 Correct 0 ms 344 KB Ok
5 Correct 0 ms 348 KB Ok
6 Correct 2 ms 604 KB Ok
7 Correct 7 ms 1628 KB Ok
8 Correct 3 ms 860 KB Ok
9 Correct 8 ms 1868 KB Ok
10 Correct 5 ms 1116 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 0 ms 348 KB Ok
4 Correct 0 ms 432 KB Ok
5 Correct 0 ms 348 KB Ok
6 Correct 0 ms 348 KB Ok
7 Correct 0 ms 348 KB Ok
8 Correct 0 ms 348 KB Ok
9 Correct 0 ms 344 KB Ok
10 Correct 1 ms 348 KB Ok
11 Correct 0 ms 348 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Ok
2 Correct 0 ms 600 KB Ok
3 Correct 1 ms 344 KB Ok
4 Correct 0 ms 604 KB Ok
5 Correct 0 ms 348 KB Ok
6 Correct 72 ms 17748 KB Ok
7 Correct 62 ms 17504 KB Ok
8 Correct 128 ms 22864 KB Ok
9 Correct 96 ms 20644 KB Ok
10 Correct 54 ms 11348 KB Ok
11 Correct 91 ms 22208 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 0 ms 348 KB Ok
4 Correct 0 ms 348 KB Ok
5 Correct 0 ms 348 KB Ok
6 Correct 0 ms 348 KB Ok
7 Correct 0 ms 344 KB Ok
8 Correct 0 ms 424 KB Ok
9 Correct 0 ms 348 KB Ok
10 Correct 0 ms 348 KB Ok
11 Correct 0 ms 348 KB Ok
12 Correct 0 ms 344 KB Ok
13 Correct 0 ms 344 KB Ok
14 Correct 0 ms 348 KB Ok
15 Correct 0 ms 348 KB Ok
16 Correct 0 ms 432 KB Ok
17 Correct 0 ms 348 KB Ok
18 Correct 0 ms 348 KB Ok
19 Correct 0 ms 348 KB Ok
20 Correct 0 ms 348 KB Ok
21 Correct 0 ms 344 KB Ok
22 Correct 1 ms 348 KB Ok
23 Correct 0 ms 348 KB Ok
24 Correct 2 ms 604 KB Ok
25 Correct 1 ms 604 KB Ok
26 Correct 2 ms 604 KB Ok
27 Correct 1 ms 604 KB Ok
28 Correct 1 ms 604 KB Ok
29 Correct 2 ms 428 KB Ok
30 Correct 1 ms 604 KB Ok
31 Correct 2 ms 604 KB Ok
32 Correct 2 ms 604 KB Ok
33 Correct 2 ms 604 KB Ok
34 Correct 4 ms 856 KB Ok
35 Correct 5 ms 860 KB Ok
36 Correct 3 ms 876 KB Ok
37 Correct 3 ms 860 KB Ok
38 Correct 3 ms 860 KB Ok
39 Correct 3 ms 860 KB Ok
40 Correct 3 ms 856 KB Ok
41 Correct 3 ms 780 KB Ok
42 Correct 3 ms 860 KB Ok
43 Correct 4 ms 980 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 0 ms 348 KB Ok
4 Correct 0 ms 348 KB Ok
5 Correct 0 ms 348 KB Ok
6 Correct 0 ms 348 KB Ok
7 Correct 0 ms 344 KB Ok
8 Correct 0 ms 424 KB Ok
9 Correct 0 ms 348 KB Ok
10 Correct 0 ms 348 KB Ok
11 Correct 0 ms 348 KB Ok
12 Correct 0 ms 344 KB Ok
13 Correct 0 ms 348 KB Ok
14 Correct 0 ms 348 KB Ok
15 Correct 0 ms 348 KB Ok
16 Correct 0 ms 344 KB Ok
17 Correct 0 ms 348 KB Ok
18 Correct 2 ms 604 KB Ok
19 Correct 7 ms 1628 KB Ok
20 Correct 3 ms 860 KB Ok
21 Correct 8 ms 1868 KB Ok
22 Correct 5 ms 1116 KB Ok
23 Correct 0 ms 344 KB Ok
24 Correct 0 ms 348 KB Ok
25 Correct 0 ms 348 KB Ok
26 Correct 0 ms 432 KB Ok
27 Correct 0 ms 348 KB Ok
28 Correct 0 ms 348 KB Ok
29 Correct 0 ms 348 KB Ok
30 Correct 0 ms 348 KB Ok
31 Correct 0 ms 344 KB Ok
32 Correct 1 ms 348 KB Ok
33 Correct 0 ms 348 KB Ok
34 Correct 2 ms 604 KB Ok
35 Correct 1 ms 604 KB Ok
36 Correct 2 ms 604 KB Ok
37 Correct 1 ms 604 KB Ok
38 Correct 1 ms 604 KB Ok
39 Correct 2 ms 428 KB Ok
40 Correct 1 ms 604 KB Ok
41 Correct 2 ms 604 KB Ok
42 Correct 2 ms 604 KB Ok
43 Correct 2 ms 604 KB Ok
44 Correct 4 ms 856 KB Ok
45 Correct 5 ms 860 KB Ok
46 Correct 3 ms 876 KB Ok
47 Correct 3 ms 860 KB Ok
48 Correct 3 ms 860 KB Ok
49 Correct 3 ms 860 KB Ok
50 Correct 3 ms 856 KB Ok
51 Correct 3 ms 780 KB Ok
52 Correct 3 ms 860 KB Ok
53 Correct 4 ms 980 KB Ok
54 Correct 54 ms 8532 KB Ok
55 Correct 64 ms 8768 KB Ok
56 Correct 60 ms 9208 KB Ok
57 Correct 42 ms 7504 KB Ok
58 Correct 52 ms 8272 KB Ok
59 Correct 50 ms 7644 KB Ok
60 Correct 44 ms 7252 KB Ok
61 Correct 43 ms 8084 KB Ok
62 Correct 64 ms 8720 KB Ok
63 Correct 52 ms 7632 KB Ok
64 Correct 66 ms 8832 KB Ok
65 Correct 58 ms 8532 KB Ok
66 Correct 50 ms 8272 KB Ok
67 Correct 46 ms 7920 KB Ok
68 Correct 53 ms 8528 KB Ok
69 Correct 122 ms 18020 KB Ok
70 Correct 126 ms 17488 KB Ok
71 Correct 124 ms 16512 KB Ok
72 Correct 120 ms 18000 KB Ok
73 Correct 125 ms 17164 KB Ok
74 Correct 128 ms 16844 KB Ok
75 Correct 124 ms 17276 KB Ok
76 Correct 126 ms 18004 KB Ok
77 Correct 121 ms 16464 KB Ok
78 Correct 126 ms 18000 KB Ok
79 Correct 124 ms 17080 KB Ok
80 Correct 122 ms 17752 KB Ok
81 Correct 127 ms 17744 KB Ok
82 Correct 127 ms 17232 KB Ok
83 Correct 126 ms 17524 KB Ok
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Ok
2 Correct 0 ms 348 KB Ok
3 Correct 0 ms 348 KB Ok
4 Correct 0 ms 348 KB Ok
5 Correct 0 ms 348 KB Ok
6 Correct 0 ms 348 KB Ok
7 Correct 0 ms 344 KB Ok
8 Correct 0 ms 424 KB Ok
9 Correct 0 ms 348 KB Ok
10 Correct 0 ms 348 KB Ok
11 Correct 0 ms 348 KB Ok
12 Correct 0 ms 344 KB Ok
13 Correct 0 ms 348 KB Ok
14 Correct 0 ms 348 KB Ok
15 Correct 0 ms 348 KB Ok
16 Correct 0 ms 344 KB Ok
17 Correct 0 ms 348 KB Ok
18 Correct 2 ms 604 KB Ok
19 Correct 7 ms 1628 KB Ok
20 Correct 3 ms 860 KB Ok
21 Correct 8 ms 1868 KB Ok
22 Correct 5 ms 1116 KB Ok
23 Correct 0 ms 344 KB Ok
24 Correct 0 ms 348 KB Ok
25 Correct 0 ms 348 KB Ok
26 Correct 0 ms 432 KB Ok
27 Correct 0 ms 348 KB Ok
28 Correct 0 ms 348 KB Ok
29 Correct 0 ms 348 KB Ok
30 Correct 0 ms 348 KB Ok
31 Correct 0 ms 344 KB Ok
32 Correct 1 ms 348 KB Ok
33 Correct 0 ms 348 KB Ok
34 Correct 0 ms 348 KB Ok
35 Correct 0 ms 600 KB Ok
36 Correct 1 ms 344 KB Ok
37 Correct 0 ms 604 KB Ok
38 Correct 0 ms 348 KB Ok
39 Correct 72 ms 17748 KB Ok
40 Correct 62 ms 17504 KB Ok
41 Correct 128 ms 22864 KB Ok
42 Correct 96 ms 20644 KB Ok
43 Correct 54 ms 11348 KB Ok
44 Correct 91 ms 22208 KB Ok
45 Correct 2 ms 604 KB Ok
46 Correct 1 ms 604 KB Ok
47 Correct 2 ms 604 KB Ok
48 Correct 1 ms 604 KB Ok
49 Correct 1 ms 604 KB Ok
50 Correct 2 ms 428 KB Ok
51 Correct 1 ms 604 KB Ok
52 Correct 2 ms 604 KB Ok
53 Correct 2 ms 604 KB Ok
54 Correct 2 ms 604 KB Ok
55 Correct 4 ms 856 KB Ok
56 Correct 5 ms 860 KB Ok
57 Correct 3 ms 876 KB Ok
58 Correct 3 ms 860 KB Ok
59 Correct 3 ms 860 KB Ok
60 Correct 3 ms 860 KB Ok
61 Correct 3 ms 856 KB Ok
62 Correct 3 ms 780 KB Ok
63 Correct 3 ms 860 KB Ok
64 Correct 4 ms 980 KB Ok
65 Correct 54 ms 8532 KB Ok
66 Correct 64 ms 8768 KB Ok
67 Correct 60 ms 9208 KB Ok
68 Correct 42 ms 7504 KB Ok
69 Correct 52 ms 8272 KB Ok
70 Correct 50 ms 7644 KB Ok
71 Correct 44 ms 7252 KB Ok
72 Correct 43 ms 8084 KB Ok
73 Correct 64 ms 8720 KB Ok
74 Correct 52 ms 7632 KB Ok
75 Correct 66 ms 8832 KB Ok
76 Correct 58 ms 8532 KB Ok
77 Correct 50 ms 8272 KB Ok
78 Correct 46 ms 7920 KB Ok
79 Correct 53 ms 8528 KB Ok
80 Correct 122 ms 18020 KB Ok
81 Correct 126 ms 17488 KB Ok
82 Correct 124 ms 16512 KB Ok
83 Correct 120 ms 18000 KB Ok
84 Correct 125 ms 17164 KB Ok
85 Correct 128 ms 16844 KB Ok
86 Correct 124 ms 17276 KB Ok
87 Correct 126 ms 18004 KB Ok
88 Correct 121 ms 16464 KB Ok
89 Correct 126 ms 18000 KB Ok
90 Correct 124 ms 17080 KB Ok
91 Correct 122 ms 17752 KB Ok
92 Correct 127 ms 17744 KB Ok
93 Correct 127 ms 17232 KB Ok
94 Correct 126 ms 17524 KB Ok
95 Correct 127 ms 21592 KB Ok
96 Correct 202 ms 31572 KB Ok
97 Correct 207 ms 25916 KB Ok
98 Correct 130 ms 26708 KB Ok
99 Correct 167 ms 24392 KB Ok
100 Correct 189 ms 24660 KB Ok
101 Correct 172 ms 29012 KB Ok
102 Correct 176 ms 25940 KB Ok
103 Correct 181 ms 27984 KB Ok
104 Correct 232 ms 29764 KB Ok
105 Correct 204 ms 31312 KB Ok
106 Correct 151 ms 31828 KB Ok
107 Correct 188 ms 29264 KB Ok
108 Correct 212 ms 30800 KB Ok
109 Correct 180 ms 33156 KB Ok
110 Correct 742 ms 72784 KB Ok
111 Correct 800 ms 73844 KB Ok
112 Correct 792 ms 66156 KB Ok
113 Correct 745 ms 73048 KB Ok
114 Correct 788 ms 73620 KB Ok
115 Correct 773 ms 72760 KB Ok
116 Correct 806 ms 72784 KB Ok
117 Correct 772 ms 73552 KB Ok
118 Correct 726 ms 68436 KB Ok
119 Correct 782 ms 72792 KB Ok
120 Correct 781 ms 72780 KB Ok
121 Correct 760 ms 73712 KB Ok
122 Correct 753 ms 70224 KB Ok
123 Correct 798 ms 73296 KB Ok
124 Correct 742 ms 66368 KB Ok
125 Correct 421 ms 38640 KB Ok