結果

問題 No.460 裏表ちわーわ
コンテスト
ユーザー 👑 tails
提出日時 2016-12-11 00:49:21
言語 C90(gcc15)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=c90 -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 696 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 249 ms
コンパイル使用メモリ 39,588 KB
最終ジャッジ日時 2026-02-23 23:36:37
ジャッジサーバー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:3: warning: data definition has no type or storage class
    1 | m;n;b;a[9][9];
      |   ^
main.c:1:5: warning: data definition has no type or storage class
    1 | m;n;b;a[9][9];
      |     ^
main.c:1:7: warning: data definition has no type or storage class
    1 | m;n;b;a[9][9];
      |       ^
main.c: In function 'main':
main.c:51:9: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
   51 |         scanf("%d%d",&m,&n);
      |         ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
  +++ |+#include <stdio.h>
    1 | m;n;b;a[9][9];
main.c:62:17: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
   62 |                 printf("%d",b);
      |                 ^~~~~~
main.c:62:17: note: include '<stdio.h>' or provide a declaration of 'printf'

ソースコード

diff #
raw source code

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