Submission #750302


Source Code Expand

using System;
using System.Text;
using System.IO;
using System.Globalization;
using System.Collections.Generic;

namespace ConsoleApplication21
{
    using P = KeyValuePair<int, int>;
    class Program
    {
        static void Main()
        {
            StreamScanner sc = new StreamScanner(Console.OpenStandardInput());
            int H = sc.integer();
            int W = sc.integer();
            int sx = 0, sy = 0, gx = 0, gy = 0;
            char[,] c = new char[W, H];
            bool[,] d = new bool[W, H];
            int[] dx = { 1, -1, 0, 0 }, dy = { 0, 0, 1, -1 };
            Stack<P> a = new Stack<P>();
            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    c[j, i] = sc.Char();
                    if (c[j, i] == 's') { sx = j; sy = i; }
                    if (c[j, i] == 'g') { gx = j; gy = i; }
                }
            }
            a.Push(new P(sx, sy));
            while (a.Count > 0)
            {
                P pop = a.Pop();
                for (int i = 0; i < 4; i++)
                {
                    int x = pop.Key + dx[i];
                    int y = pop.Value + dy[i];
                    if (0 <= x && x < W && 0 <= y && y < H && c[x, y] != '#' && d[x, y] == false)
                    {
                        a.Push(new P(x, y));
                        d[x, y] = true;
                    }
                }
            }
            if (d[gx, gy]) Console.Write("Yes\n");
            else Console.Write("No\n");
        }
    }
    public class StreamScanner
    {
        public StreamScanner(Stream stream) { str = stream; }
        private readonly Stream str;
        private readonly byte[] buf = new byte[1024];
        private long len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream { get { return isEof; } }
        private byte read()
        {
            if (isEof) throw new EndOfStreamException();
            if (ptr >= len)
            {
                ptr = 0;
                if ((len = str.Read(buf, 0, 1024)) <= 0)
                {
                    isEof = true;
                    return 0;
                }
            }
            return buf[ptr++];
        }
        public char Char()
        {
            byte b = 0;
            do b = read();
            while (b < 33 || 126 < b);
            return (char)b;
        }
        public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        public long Long()
        {
            long ret = 0; byte b = 0; var ng = false;
            do b = read();
            while (b != '-' && (b < '0' || '9' < b));
            if (b == '-') { ng = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = ret * 10 + b - '0';
            }
        }
        public int integer() { return (int)Long(); }
        public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); }
    }
}

Submission Info

Submission Time
Task A - 深さ優先探索
User autumn_eel
Language C# (Mono 3.2.1.0)
Score 100
Code Size 3334 Byte
Status AC
Exec Time 153 ms
Memory 11964 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 5
AC × 83
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 00_sample_04.txt, 00_sample_05.txt
All 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 AC 110 ms 9516 KB
00_min_02.txt AC 108 ms 9512 KB
00_min_03.txt AC 114 ms 9524 KB
00_min_04.txt AC 114 ms 9512 KB
00_min_05.txt AC 112 ms 9508 KB
00_min_06.txt AC 114 ms 9508 KB
00_min_07.txt AC 113 ms 9508 KB
00_min_08.txt AC 113 ms 9508 KB
00_sample_01.txt AC 115 ms 9508 KB
00_sample_02.txt AC 115 ms 9512 KB
00_sample_03.txt AC 115 ms 9484 KB
00_sample_04.txt AC 111 ms 9516 KB
00_sample_05.txt AC 110 ms 9536 KB
01_rnd_00.txt AC 118 ms 9924 KB
01_rnd_01.txt AC 142 ms 10436 KB
01_rnd_02.txt AC 145 ms 10392 KB
01_rnd_03.txt AC 148 ms 11896 KB
01_rnd_04.txt AC 146 ms 11592 KB
01_rnd_05.txt AC 118 ms 9952 KB
01_rnd_06.txt AC 140 ms 10444 KB
01_rnd_07.txt AC 139 ms 10444 KB
01_rnd_08.txt AC 118 ms 9928 KB
01_rnd_09.txt AC 122 ms 9908 KB
01_rnd_10.txt AC 135 ms 10052 KB
01_rnd_11.txt AC 121 ms 9928 KB
01_rnd_12.txt AC 153 ms 10948 KB
01_rnd_13.txt AC 148 ms 10952 KB
01_rnd_14.txt AC 122 ms 9920 KB
01_rnd_15.txt AC 140 ms 10184 KB
01_rnd_16.txt AC 123 ms 9876 KB
01_rnd_17.txt AC 139 ms 10028 KB
01_rnd_18.txt AC 123 ms 9928 KB
01_rnd_19.txt AC 147 ms 11964 KB
02_rndhard_00.txt AC 119 ms 9928 KB
02_rndhard_01.txt AC 123 ms 9928 KB
02_rndhard_02.txt AC 123 ms 9876 KB
02_rndhard_03.txt AC 123 ms 9932 KB
02_rndhard_04.txt AC 118 ms 9928 KB
02_rndhard_05.txt AC 118 ms 9936 KB
02_rndhard_06.txt AC 118 ms 9928 KB
02_rndhard_07.txt AC 117 ms 9932 KB
02_rndhard_08.txt AC 118 ms 9932 KB
02_rndhard_09.txt AC 121 ms 9972 KB
02_rndhard_10.txt AC 121 ms 9928 KB
02_rndhard_11.txt AC 120 ms 9908 KB
02_rndhard_12.txt AC 121 ms 9924 KB
02_rndhard_13.txt AC 120 ms 9924 KB
02_rndhard_14.txt AC 120 ms 9884 KB
02_rndhard_15.txt AC 116 ms 9924 KB
02_rndhard_16.txt AC 125 ms 9932 KB
02_rndhard_17.txt AC 115 ms 9928 KB
02_rndhard_18.txt AC 117 ms 9932 KB
02_rndhard_19.txt AC 116 ms 9928 KB
02_rndhard_20.txt AC 118 ms 9924 KB
02_rndhard_21.txt AC 118 ms 9924 KB
02_rndhard_22.txt AC 121 ms 9956 KB
02_rndhard_23.txt AC 122 ms 9952 KB
02_rndhard_24.txt AC 124 ms 9928 KB
02_rndhard_25.txt AC 119 ms 9924 KB
02_rndhard_26.txt AC 126 ms 9928 KB
02_rndhard_27.txt AC 121 ms 9924 KB
02_rndhard_28.txt AC 121 ms 9928 KB
02_rndhard_29.txt AC 119 ms 9924 KB
02_rndhard_30.txt AC 120 ms 9956 KB
02_rndhard_31.txt AC 118 ms 9924 KB
02_rndhard_32.txt AC 121 ms 9928 KB
02_rndhard_33.txt AC 121 ms 9924 KB
02_rndhard_34.txt AC 119 ms 9928 KB
02_rndhard_35.txt AC 122 ms 9924 KB
02_rndhard_36.txt AC 114 ms 9932 KB
02_rndhard_37.txt AC 115 ms 9932 KB
02_rndhard_38.txt AC 116 ms 9932 KB
02_rndhard_39.txt AC 115 ms 9928 KB
03_rndhardsmall_00.txt AC 108 ms 9512 KB
03_rndhardsmall_01.txt AC 108 ms 9528 KB
03_rndhardsmall_02.txt AC 107 ms 9516 KB
03_rndhardsmall_03.txt AC 107 ms 9512 KB
03_rndhardsmall_04.txt AC 113 ms 9488 KB
03_rndhardsmall_05.txt AC 111 ms 9440 KB
03_rndhardsmall_06.txt AC 115 ms 9516 KB
03_rndhardsmall_07.txt AC 111 ms 9508 KB
03_rndhardsmall_08.txt AC 111 ms 9508 KB
03_rndhardsmall_09.txt AC 112 ms 9544 KB