結果

問題 No.101 ぐるぐる!あみだくじ!
コンテスト
ユーザー testestest
提出日時 2015-12-06 14:12:27
言語 C90
(gcc 12.4.0)
コンパイル:
gcc-12 -O2 -std=c90 -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 495 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 148 ms
コンパイル使用メモリ 30,020 KB
最終ジャッジ日時 2026-02-23 19:58:43
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 37
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:1:1: warning: data definition has no type or storage class
    1 | num[100];count;
      | ^~~
main.c:1:10: warning: data definition has no type or storage class
    1 | num[100];count;
      |          ^~~~~
main.c:2:1: warning: data definition has no type or storage class
    2 | check[101];
      | ^~~~~
main.c:3:1: warning: data definition has no type or storage class
    3 | x[1000];y[1000];
      | ^
main.c:3:9: warning: data definition has no type or storage class
    3 | x[1000];y[1000];
      |         ^
main.c: In function ‘main’:
main.c:15:1: warning: incompatible implicit declaration of built-in function ‘scanf’ [-Wbuiltin-declaration-mismatch]
   15 | scanf("%d%d",&n,&k);
      | ^~~~~
main.c:1:1: note: include ‘<stdio.h>’ or provide a declaration of ‘scanf’
  +++ |+#include <stdio.h>
    1 | num[100];count;
main.c:31:1: warning: incompatible implicit declaration of built-in function ‘printf’ [-Wbuiltin-declaration-mismatch]
   31 | printf("%d",lcm(num));
      | ^~~~~~
main.c:31:1: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’

ソースコード

diff #
raw source code

num[100];count;
check[101];
x[1000];y[1000];

gcd(a,b){return b?gcd(b,a%b):a;}

lcm(int*a){
if(a[1]==0)return *a;
a[1]*=*a/gcd(*a,a[1]);
return lcm(a+1);
}

main(){
int n,k,i,j,temp,times;
scanf("%d%d",&n,&k);
for(i=0;i<k;i++)scanf("%d%d",x+i,y+i);
for(i=1;i<=n;i++){
	if(check[i]++)continue;
	temp=i;
	times=0;
	do{
		for(j=0;j<k;j++){
			if(x[j]==temp)temp=y[j];
			else if(y[j]==temp)temp=x[j];
		}
		times++;
		check[temp]++;
	}while(temp!=i);
	num[count++]=times;
}
printf("%d",lcm(num));
}
0