結果

問題 No.157 2つの空洞
ユーザー kuuso1kuuso1
提出日時 2015-02-26 23:51:55
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 1,887 bytes
コンパイル時間 4,023 ms
コンパイル使用メモリ 111,796 KB
実行使用メモリ 22,968 KB
最終ジャッジ日時 2023-09-06 02:55:38
合計ジャッジ時間 4,896 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
20,796 KB
testcase_01 AC 59 ms
20,864 KB
testcase_02 AC 59 ms
20,880 KB
testcase_03 AC 60 ms
20,804 KB
testcase_04 AC 58 ms
20,756 KB
testcase_05 AC 58 ms
22,856 KB
testcase_06 AC 59 ms
20,820 KB
testcase_07 AC 59 ms
20,796 KB
testcase_08 AC 60 ms
22,948 KB
testcase_09 AC 59 ms
20,788 KB
testcase_10 AC 61 ms
22,884 KB
testcase_11 AC 61 ms
22,844 KB
testcase_12 AC 61 ms
20,716 KB
testcase_13 AC 61 ms
22,820 KB
testcase_14 AC 61 ms
20,812 KB
testcase_15 AC 63 ms
20,896 KB
testcase_16 AC 58 ms
22,924 KB
testcase_17 AC 59 ms
20,784 KB
testcase_18 AC 59 ms
22,968 KB
testcase_19 AC 59 ms
20,820 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections;
using System.Collections.Generic;
 
class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		used=new bool[H,W];
		int cnt=-1;
		Buf=new List<int>[2];
		Buf[0]=new List<int>();
		Buf[1]=new List<int>();
		
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				if(Map[i][j]=='.' && !used[i,j])dfs(i,j,++cnt);
			}
		}
		
		int Min=9999;
		foreach(var s in Buf[0]){
			foreach(var t in Buf[1]){
//Console.WriteLine(s+" "+t);
				Min=Math.Min(Min,MHD(s,t)-1);
			}
		}
		Console.WriteLine(Min);
		
		
		
	}
	
	int decX(int s){return s%W;}
	int decY(int s){return s/W;}
	int enc(int x,int y){return x+y*W;}
	int MHD(int s,int t){return Math.Abs(decX(s)-decX(t))+Math.Abs(decY(s)-decY(t));}
	
	List<int>[] Buf;
	bool[,] used;
	int[] dx=new int[]{0,1,0,-1};
	int[] dy=new int[]{1,0,-1,0};

	void dfs(int y,int x,int c){
//Console.WriteLine(x+" "+y+" "+c);
		used[y,x]=true;
		Buf[c].Add(enc(x,y));
		for(int i=0;i<4;i++){
			if(y+dy[i]>=0 && y+dy[i]<H && x+dx[i]>=0 && x+dx[i]<W && Map[y+dy[i]][x+dx[i]]=='.' && !used[y+dy[i],x+dx[i]]){
				dfs(y+dy[i],x+dx[i],c);
			}
		}
	}
	
	
	
	int W,H;
	String[] Map;
	public Sol(){
		var d=ria();
		W=d[0];H=d[1];
		Map=new String[H];
		for(int i=0;i<H;i++)Map[i]=rs();
	}




	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(){return Console.ReadLine().Split(' ');}
	static int[] ria(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>int.Parse(e));}
	static long[] rla(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>long.Parse(e));}
	static double[] rda(){return Array.ConvertAll(Console.ReadLine().Split(' '),e=>double.Parse(e));}
}
0