結果

問題 No.460 裏表ちわーわ
ユーザー tails
提出日時 2016-12-11 00:49:21
言語 C90
(gcc 12.3.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 696 bytes
コンパイル時間 138 ms
コンパイル使用メモリ 21,248 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-23 15:04:08
合計ジャッジ時間 1,152 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 28
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:1:1: warning: data definition has no type or storage class
    1 | m;n;b;a[9][9];
      | ^
main.c:1:1: warning: type defaults to ‘int’ in declaration of ‘m’ [-Wimplicit-int]
main.c:1:3: warning: data definition has no type or storage class
    1 | m;n;b;a[9][9];
      |   ^
main.c:1:3: warning: type defaults to ‘int’ in declaration of ‘n’ [-Wimplicit-int]
main.c:1:5: warning: data definition has no type or storage class
    1 | m;n;b;a[9][9];
      |     ^
main.c:1:5: warning: type defaults to ‘int’ in declaration of ‘b’ [-Wimplicit-int]
main.c:1:7: warning: data definition has no type or storage class
    1 | m;n;b;a[9][9];
      |       ^
main.c:1:7: warning: type defaults to ‘int’ in declaration of ‘a’ [-Wimplicit-int]
main.c:3:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
    3 | d(y,x,j,i){
      | ^
main.c: In function ‘d’:
main.c:3:1: warning: type of ‘y’ defaults to ‘int’ [-Wimplicit-int]
main.c:3:1: warning: type of ‘x’ defaults to ‘int’ [-Wimplicit-int]
main.c:3:1: warning: type of ‘j’ defaults to ‘int’ [-Wimplicit-int]
main.c:3:1: warning: type of ‘i’ defaults to ‘int’ [-Wimplicit-int]
main.c: At top level:
main.c:15:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
   15 | f(y,x,c,j,i){
      | ^
main.c: In function ‘f’:
main.c:15:1: warning: type of ‘y’ defaults to ‘int’ [-Wimplicit-int]
main.c:15:1: warning: type of ‘x’ defaults to ‘int’ [-Wimplicit-int]
main.c:15:1: warning: type of ‘c’ defaults to ‘int’ [-Wimplicit-int]
main.c:15:1: warning: type of ‘j’ defaults to ‘int’ [-Wimplicit-int]
main.c:15:1: warning: type of ‘i’ defaults to ‘int’ [-Wimplicit-int]
main.c:24:41: warning: ‘return’ with no value, in function returning non-void
   24 |                                         return;
      |                                         ^~~~~~
main.c:15:1: note: declared here
   15 | f(y,x,c,j,i){
    

ソースコード

diff #

m;n;b;a[9][9];

d(y,x,j,i){
	for(j=y-1;j<=y+1;++j){
		if(j>=0&&j<m){
			for(i=x-1;i<=x+1;++i){
				if(i>=0&&i<n){
					a[j][i]^=1;
				}
			}
		}
	}
}

f(y,x,c,j,i){
	if(x==n){
		x=0;
		++y;
	}
	if(y==m){
		for(j=0;j<m;++j){
			for(i=0;i<n;++i){
				if(a[j][i]){
					return;
				}
			}
		}
		if(b>c){
			b=c;
		}
		return;
	}

	if(y>0&&x>0){
		if(a[y-1][x-1]){
			d(y,x);
			f(y,x+1,c+1);
			d(y,x);
		}else{
			f(y,x+1,c);
		}
	}else{
		f(y,x+1,c);
		d(y,x);
		f(y,x+1,c+1);
		d(y,x);
	}
}		

main(y,x,j,i){
	scanf("%d%d",&m,&n);
	for(y=0;y<m;++y){
		for(x=0;x<n;++x){
			scanf("%d",&a[y][x]);
		}
	}
	b=99;
	f(0,0,0);
	if(b==99){
		puts("Impossible");
	}else{
		printf("%d",b);
	}
	return 0;
}
0