답안 #1086400

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1086400 2024-09-10T13:05:09 Z 8pete8 Nice sequence (IZhO18_sequence) C
컴파일 오류
0 ms 0 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=4e5;
int k=0;
int *adj[mxn+10],sz[mxn+10],vis[mxn+10],ord[mxn+10],cnt=0;
int what[mxn+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 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){
            adj[i] = (int *)realloc(adj[i],(sz[i] + 1)*sizeof(int));
            adj[i][sz[i]++]=i-m;
        }
        if(i-n>=0){
            adj[i-n]=(int *)realloc(adj[i-n],(sz[i-n] + 1)*sizeof(int));
            adj[i-n][sz[i-n]++]=i;
        }
    }
    //get length
    printf("%lld\n",k);
    for(int i=0;i<=k;i++)if(!vis[i])ts(i);
    for(int i=cnt;i>=0;i--)what[ord[i]]=(k-i);
    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:9:6: error: variably modified 'adj' at file scope
    9 | int *adj[mxn+10],sz[mxn+10],vis[mxn+10],ord[mxn+10],cnt=0;
      |      ^~~
sequence.c:9:18: error: variably modified 'sz' at file scope
    9 | int *adj[mxn+10],sz[mxn+10],vis[mxn+10],ord[mxn+10],cnt=0;
      |                  ^~
sequence.c:9:29: error: variably modified 'vis' at file scope
    9 | int *adj[mxn+10],sz[mxn+10],vis[mxn+10],ord[mxn+10],cnt=0;
      |                             ^~~
sequence.c:9:41: error: variably modified 'ord' at file scope
    9 | int *adj[mxn+10],sz[mxn+10],vis[mxn+10],ord[mxn+10],cnt=0;
      |                                         ^~~
sequence.c:10:5: error: variably modified 'what' at file scope
   10 | int what[mxn+10];
      |     ^~~~
sequence.c: In function 'solve':
sequence.c:23:13: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |     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);
      |           ^~~~~~~~~~~~~~~~