Submission #7164832


Source Code Expand

using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
	var tmp = ReadIntArray();
	int h = tmp[0], w = tmp[1];
	char[][] a = new char[h+2][];
	a[0] = a[h+1] = (new string('#', w+2)).ToCharArray();
	for (int i = 1; i <= h; i++)
	{
	    a[i] = ("#" + ReadLine() + "#").ToCharArray();
	}

	List<Tuple<int, int>> next = new List<Tuple<int, int>>();
	// Search Initial '#'s
	for (int i = 1; i <= h; i++)
	{
	    for (int j = 1; j <= w; j++)
	    {
		if (a[i][j] == '#')
		    next.Add(Tuple.Create(i, j));
	    }
	}

	int ans = 0;
	// Solve
	while (next.Count > 0)
	{
	    ans++;
	    List<Tuple<int,int>> tls = next;
	    next = new List<Tuple<int,int>>();
	    foreach (Tuple<int,int> t in tls)
	    {
		int x = t.Item1, y = t.Item2;
		if (a[x-1][y] != '#'){ next.Add(Tuple.Create(x-1,y)); a[x-1][y] = '#'; }
		if (a[x+1][y] != '#'){ next.Add(Tuple.Create(x+1,y)); a[x+1][y] = '#'; }
		if (a[x][y-1] != '#'){ next.Add(Tuple.Create(x,y-1)); a[x][y-1] = '#'; }
		if (a[x][y+1] != '#'){ next.Add(Tuple.Create(x,y+1)); a[x][y+1] = '#'; }
	    }
	}

	WriteLine(ans-1);
    }
}

Submission Info

Submission Time
Task A - Darker and Darker
User unnohideyuki
Language C# (Mono 4.6.2.0)
Score 300
Code Size 1415 Byte
Status AC
Exec Time 151 ms
Memory 54424 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 17
Set Name Test Cases
Sample sample01.txt, sample02.txt
All sample01.txt, sample02.txt, in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, sample01.txt, sample02.txt
Case Name Status Exec Time Memory
in01.txt AC 151 ms 51544 KiB
in02.txt AC 149 ms 48900 KiB
in03.txt AC 145 ms 54424 KiB
in04.txt AC 137 ms 54316 KiB
in05.txt AC 24 ms 9300 KiB
in06.txt AC 133 ms 33480 KiB
in07.txt AC 138 ms 36932 KiB
in08.txt AC 141 ms 35636 KiB
in09.txt AC 140 ms 36288 KiB
in10.txt AC 77 ms 32980 KiB
in11.txt AC 73 ms 32600 KiB
in12.txt AC 77 ms 32596 KiB
in13.txt AC 74 ms 34776 KiB
sample01.txt AC 24 ms 11348 KiB
sample02.txt AC 24 ms 11348 KiB