Submission #420841


Source Code Expand

Copy
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoderTypicalContest001
{
    class Program
    {
        static int[] dy = { 0, 1, 0, -1 };
        static int[] dx = { 1, 0, -1, 0 };
        static void A()
        {
            string[] one = Console.ReadLine().Split(' ');
            int H = int.Parse(one[0]);
            int W = int.Parse(one[1]);
            string[] map = new string[H];
            bool[,] b = new bool[H, W];
            int startx = 0;
            int starty = 0;
            int goalx = 0;
            int goaly = 0;
            for(int i = 0;i<H;i++)
            {
                map[i] = Console.ReadLine();
                for(int j = 0;j<W;j++)
                {
                    if(map[i][j] == 's')
                    {
                        startx = j;
                        starty = i;
                    }

                    if(map[i][j] == 'g')
                    {
                        goalx = j;
                        goaly = i;
                    }
                }
            }

            if(A_Dfs(startx, starty, goalx, goaly, b, map,W,H))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

        }

        static bool A_Dfs(int nowX,int nowY,int endX,int endY,bool[,] b,string[] map,int W,int H)
        {
            if(map[nowY][nowX] == 'g')return true;
            bool ans = false;
            for (int i = 0; i < 4; i++)
            {
                int nextx = nowX + dx[i];
                int nexty = nowY + dy[i];
                if (nextx < 0 || nextx >= W || nexty < 0 || nexty >= H) continue;
                if (b[nexty, nextx]) continue;
                if (map[nexty][nextx] == '#') continue;
                b[nexty, nextx] = true;
                ans = ans || A_Dfs(nextx, nexty, endX, endY, b, map, W, H);
            }


            return ans;
        }
        static void B()
        {

        }
        static void Main(string[] args)
        {
            A();
            //B();
        }
    }
}

Submission Info

Submission Time
Task A - 深さ優先探索
User tookunn
Language C# (Mono 3.2.1.0)
Score 100
Code Size 2264 Byte
Status
Exec Time 178 ms
Memory 35356 KB

Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 00_sample_04.txt, 00_sample_05.txt
All 100 / 100 00_min_01.txt, 00_min_02.txt, 00_min_03.txt, 00_min_04.txt, 00_min_05.txt, 00_min_06.txt, 00_min_07.txt, 00_min_08.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 00_sample_04.txt, 00_sample_05.txt, 01_rnd_00.txt, 01_rnd_01.txt, 01_rnd_02.txt, 01_rnd_03.txt, 01_rnd_04.txt, 01_rnd_05.txt, 01_rnd_06.txt, 01_rnd_07.txt, 01_rnd_08.txt, 01_rnd_09.txt, 01_rnd_10.txt, 01_rnd_11.txt, 01_rnd_12.txt, 01_rnd_13.txt, 01_rnd_14.txt, 01_rnd_15.txt, 01_rnd_16.txt, 01_rnd_17.txt, 01_rnd_18.txt, 01_rnd_19.txt, 02_rndhard_00.txt, 02_rndhard_01.txt, 02_rndhard_02.txt, 02_rndhard_03.txt, 02_rndhard_04.txt, 02_rndhard_05.txt, 02_rndhard_06.txt, 02_rndhard_07.txt, 02_rndhard_08.txt, 02_rndhard_09.txt, 02_rndhard_10.txt, 02_rndhard_11.txt, 02_rndhard_12.txt, 02_rndhard_13.txt, 02_rndhard_14.txt, 02_rndhard_15.txt, 02_rndhard_16.txt, 02_rndhard_17.txt, 02_rndhard_18.txt, 02_rndhard_19.txt, 02_rndhard_20.txt, 02_rndhard_21.txt, 02_rndhard_22.txt, 02_rndhard_23.txt, 02_rndhard_24.txt, 02_rndhard_25.txt, 02_rndhard_26.txt, 02_rndhard_27.txt, 02_rndhard_28.txt, 02_rndhard_29.txt, 02_rndhard_30.txt, 02_rndhard_31.txt, 02_rndhard_32.txt, 02_rndhard_33.txt, 02_rndhard_34.txt, 02_rndhard_35.txt, 02_rndhard_36.txt, 02_rndhard_37.txt, 02_rndhard_38.txt, 02_rndhard_39.txt, 03_rndhardsmall_00.txt, 03_rndhardsmall_01.txt, 03_rndhardsmall_02.txt, 03_rndhardsmall_03.txt, 03_rndhardsmall_04.txt, 03_rndhardsmall_05.txt, 03_rndhardsmall_06.txt, 03_rndhardsmall_07.txt, 03_rndhardsmall_08.txt, 03_rndhardsmall_09.txt
Case Name Status Exec Time Memory
00_min_01.txt 162 ms 8816 KB
00_min_02.txt 108 ms 8840 KB
00_min_03.txt 106 ms 8844 KB
00_min_04.txt 109 ms 8852 KB
00_min_05.txt 105 ms 8840 KB
00_min_06.txt 106 ms 8844 KB
00_min_07.txt 107 ms 8844 KB
00_min_08.txt 112 ms 8840 KB
00_sample_01.txt 118 ms 8844 KB
00_sample_02.txt 106 ms 8844 KB
00_sample_03.txt 106 ms 8844 KB
00_sample_04.txt 107 ms 8844 KB
00_sample_05.txt 111 ms 8840 KB
01_rnd_00.txt 119 ms 9368 KB
01_rnd_01.txt 136 ms 15372 KB
01_rnd_02.txt 135 ms 14728 KB
01_rnd_03.txt 150 ms 24888 KB
01_rnd_04.txt 178 ms 30180 KB
01_rnd_05.txt 120 ms 9356 KB
01_rnd_06.txt 140 ms 15500 KB
01_rnd_07.txt 124 ms 11656 KB
01_rnd_08.txt 112 ms 9356 KB
01_rnd_09.txt 115 ms 9356 KB
01_rnd_10.txt 129 ms 10508 KB
01_rnd_11.txt 116 ms 9352 KB
01_rnd_12.txt 128 ms 13964 KB
01_rnd_13.txt 153 ms 22020 KB
01_rnd_14.txt 117 ms 9352 KB
01_rnd_15.txt 133 ms 13084 KB
01_rnd_16.txt 115 ms 9352 KB
01_rnd_17.txt 130 ms 12044 KB
01_rnd_18.txt 114 ms 9356 KB
01_rnd_19.txt 176 ms 35356 KB
02_rndhard_00.txt 125 ms 9356 KB
02_rndhard_01.txt 122 ms 9356 KB
02_rndhard_02.txt 118 ms 9612 KB
02_rndhard_03.txt 116 ms 9612 KB
02_rndhard_04.txt 114 ms 9356 KB
02_rndhard_05.txt 117 ms 9320 KB
02_rndhard_06.txt 115 ms 9388 KB
02_rndhard_07.txt 118 ms 9356 KB
02_rndhard_08.txt 120 ms 9364 KB
02_rndhard_09.txt 117 ms 9480 KB
02_rndhard_10.txt 117 ms 9364 KB
02_rndhard_11.txt 115 ms 9364 KB
02_rndhard_12.txt 115 ms 9356 KB
02_rndhard_13.txt 118 ms 9352 KB
02_rndhard_14.txt 120 ms 9480 KB
02_rndhard_15.txt 120 ms 9468 KB
02_rndhard_16.txt 115 ms 9356 KB
02_rndhard_17.txt 113 ms 9356 KB
02_rndhard_18.txt 113 ms 9352 KB
02_rndhard_19.txt 114 ms 9356 KB
02_rndhard_20.txt 116 ms 9356 KB
02_rndhard_21.txt 117 ms 9356 KB
02_rndhard_22.txt 130 ms 9484 KB
02_rndhard_23.txt 121 ms 9432 KB
02_rndhard_24.txt 116 ms 9352 KB
02_rndhard_25.txt 115 ms 9352 KB
02_rndhard_26.txt 115 ms 9352 KB
02_rndhard_27.txt 116 ms 9352 KB
02_rndhard_28.txt 115 ms 9336 KB
02_rndhard_29.txt 116 ms 9356 KB
02_rndhard_30.txt 117 ms 9352 KB
02_rndhard_31.txt 116 ms 9368 KB
02_rndhard_32.txt 114 ms 9484 KB
02_rndhard_33.txt 114 ms 9356 KB
02_rndhard_34.txt 119 ms 9364 KB
02_rndhard_35.txt 115 ms 9356 KB
02_rndhard_36.txt 119 ms 9356 KB
02_rndhard_37.txt 116 ms 9360 KB
02_rndhard_38.txt 127 ms 9340 KB
02_rndhard_39.txt 116 ms 9348 KB
03_rndhardsmall_00.txt 107 ms 8852 KB
03_rndhardsmall_01.txt 106 ms 8852 KB
03_rndhardsmall_02.txt 106 ms 8844 KB
03_rndhardsmall_03.txt 107 ms 8828 KB
03_rndhardsmall_04.txt 107 ms 8844 KB
03_rndhardsmall_05.txt 107 ms 8844 KB
03_rndhardsmall_06.txt 105 ms 8840 KB
03_rndhardsmall_07.txt 105 ms 8844 KB
03_rndhardsmall_08.txt 106 ms 8852 KB
03_rndhardsmall_09.txt 112 ms 8824 KB