結果

問題 No.402 最も海から遠い場所
ユーザー fgwiebfaoish
提出日時 2020-09-07 00:27:53
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 1,833 ms / 3,000 ms
コード長 3,313 bytes
コンパイル時間 1,504 ms
コンパイル使用メモリ 116,912 KB
実行使用メモリ 278,272 KB
最終ジャッジ日時 2024-11-29 07:57:05
合計ジャッジ時間 11,497 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
const int mod=(int)1e9+7;
static readonly int[][] di1=new int[][]{new int[]{-1,0},new int[]{1,0},new int[]{0,-1},new int[]{0,1}};
static readonly int[][] di2=new int[][]{new int[]{-1,-1},new int[]{-1,0},new int[]{-1,1},new int[]{0,-1},new int[]{0,1},new int[]{1,-1},new
        int[]{1,0},new int[]{1,1}};
static char[][] bm;
static int[][] b;
static void Main(){
Sc sc=new Sc();
var s=sc.Ia;
int h=s[0],w=s[1];
char c='.';
bm=new char[h+2][];
b=new int[h+2][];
var qu=new Queue<ValueTuple<int,int,int>>();
for(int i = 1;i<=h;i++) {
bm[i]=(c+sc.S+c).ToCharArray();
b[i]=new int[w+2];
for(int j = 0;j<w+2;j++) {
if(bm[i][j]=='.'){qu.Enqueue(ValueTuple.Create(i,j,0));}
else{b[i][j]=mod;}
}
}
for(int j = 0;j<w+2;j++) {
qu.Enqueue(ValueTuple.Create(0,j,0));
qu.Enqueue(ValueTuple.Create(h+1,j,0));
}
bm[0]=bm[h+1]=new string(c,w+2).ToCharArray();
b[0]=b[h+1]=new int[w+2];
int ans=0;
while(qu.Count>0){
var e=qu.Dequeue();
ans=Max(ans,e.Item3);
Fdi(e.Item1,e.Item2,(y,x)=>{
if(y<0||x<0||y>h+1||x>w+1){return;}
if(b[y][x]==mod){
qu.Enqueue(ValueTuple.Create(y,x,e.Item3+1));
b[y][x]=e.Item3+1;
}
});
}
Console.WriteLine("{0}",ans);
}
static void Fdi(int y,int x,Action<int,int> f){for(int i=0;i<8;i++){f(y+di2[i][0],x+di2[i][1]);}}
}
public class Sc{
public int I{get{return int.Parse(Console.ReadLine());}}
public long L{get{return long.Parse(Console.ReadLine());}}
public double D{get{return double.Parse(Console.ReadLine());}}
public string S{get{return Console.ReadLine();}}
public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
public string[] Sa{get{return Console.ReadLine().Split();}}
public object[] Oa{get{return Console.ReadLine().Split();}}
public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0