結果

問題 No.157 2つの空洞
ユーザー kotatsugamekotatsugame
提出日時 2017-08-10 10:33:34
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 447 bytes
コンパイル時間 1,222 ms
コンパイル使用メモリ 31,488 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 08:31:18
合計ジャッジ時間 1,131 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:1:16: warning: data definition has no type or storage class
    1 | char m[30][30];i,j,a,b;u[30][30];d[5]={0,1,0,-1};M=1e9;w,h;
      |                ^
main.c:1:16: warning: type defaults to 'int' in declaration of 'i' [-Wimplicit-int]
main.c:1:18: warning: type defaults to 'int' in declaration of 'j' [-Wimplicit-int]
    1 | char m[30][30];i,j,a,b;u[30][30];d[5]={0,1,0,-1};M=1e9;w,h;
      |                  ^
main.c:1:20: warning: type defaults to 'int' in declaration of 'a' [-Wimplicit-int]
    1 | char m[30][30];i,j,a,b;u[30][30];d[5]={0,1,0,-1};M=1e9;w,h;
      |                    ^
main.c:1:22: warning: type defaults to 'int' in declaration of 'b' [-Wimplicit-int]
    1 | char m[30][30];i,j,a,b;u[30][30];d[5]={0,1,0,-1};M=1e9;w,h;
      |                      ^
main.c:1:24: warning: data definition has no type or storage class
    1 | char m[30][30];i,j,a,b;u[30][30];d[5]={0,1,0,-1};M=1e9;w,h;
      |                        ^
main.c:1:24: warning: type defaults to 'int' in declaration of 'u' [-Wimplicit-int]
main.c:1:34: warning: data definition has no type or storage class
    1 | char m[30][30];i,j,a,b;u[30][30];d[5]={0,1,0,-1};M=1e9;w,h;
      |                                  ^
main.c:1:34: warning: type defaults to 'int' in declaration of 'd' [-Wimplicit-int]
main.c:1:50: warning: data definition has no type or storage class
    1 | char m[30][30];i,j,a,b;u[30][30];d[5]={0,1,0,-1};M=1e9;w,h;
      |                                                  ^
main.c:1:50: warning: type defaults to 'int' in declaration of 'M' [-Wimplicit-int]
main.c:1:56: warning: data definition has no type or storage class
    1 | char m[30][30];i,j,a,b;u[30][30];d[5]={0,1,0,-1};M=1e9;w,h;
      |                                                        ^
main.c:1:56: warning: type defaults to 'int' in declaration of 'w' [-Wimplicit-int]
main.c:1:58: warning: type defaults to 'int' in declaration of 'h' [-Wimplicit-int]
    1 | char m[30][30];i,j,a,b;u[30][30];d[5]={0,1,0,

ソースコード

diff #

char m[30][30];i,j,a,b;u[30][30];d[5]={0,1,0,-1};M=1e9;w,h;
f(x,y,r,s,t){
	for(u[x][y]=a;r<4;){
		s=x+d[r];t=y+d[++r];
		if(s>=0&&t>=0&&s<h&&t<w&&!u[s][t]&&m[s][t]-'#')f(s,t,0,0,0);
	}
}
main(){
	for(scanf("%d%d\n",&w,&h);gets(m[i++]););
	for(i=0;i<h;i++)for(j=0;j<w;j++)u[i][j]||m[i][j]-'.'||f(i,j,0,++a,0);
	for(i=0;i<h;i++)for(j=0;j<w;j++)for(a=0;a<h;a++)for(b=0;b<w;b++)u[i][j]+u[a][b]==3&&(M=fmin(M,fabs(i-a)+fabs(j-b)-1));
	printf("%d",M);
}
0