結果
| 問題 |
No.157 2つの空洞
|
| コンテスト | |
| ユーザー |
kuuso1
|
| 提出日時 | 2015-02-26 23:51:55 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 29 ms / 2,000 ms |
| コード長 | 1,887 bytes |
| コンパイル時間 | 1,241 ms |
| コンパイル使用メモリ | 116,108 KB |
| 実行使用メモリ | 26,356 KB |
| 最終ジャッジ日時 | 2024-06-23 21:48:23 |
| 合計ジャッジ時間 | 2,798 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 16 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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));}
}
kuuso1