Submission #1086564

#TimeUsernameProblemLanguageResultExecution timeMemory
10865648pete8Nice sequence (IZhO18_sequence)C11
100 / 100
806 ms73844 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...