結果

問題 No.659 徘徊迷路
ユーザー AreTrashAreTrash
提出日時 2018-03-03 02:53:27
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 150 ms / 2,000 ms
コード長 3,732 bytes
コンパイル時間 2,747 ms
コンパイル使用メモリ 109,852 KB
実行使用メモリ 31,472 KB
最終ジャッジ日時 2023-09-05 06:20:47
合計ジャッジ時間 5,609 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
24,536 KB
testcase_01 AC 67 ms
22,532 KB
testcase_02 AC 67 ms
20,736 KB
testcase_03 AC 65 ms
24,668 KB
testcase_04 AC 91 ms
24,572 KB
testcase_05 AC 65 ms
22,520 KB
testcase_06 AC 65 ms
22,432 KB
testcase_07 AC 62 ms
20,864 KB
testcase_08 AC 77 ms
25,096 KB
testcase_09 AC 108 ms
27,476 KB
testcase_10 AC 126 ms
29,408 KB
testcase_11 AC 145 ms
29,248 KB
testcase_12 AC 63 ms
20,676 KB
testcase_13 AC 148 ms
31,472 KB
testcase_14 AC 145 ms
29,560 KB
testcase_15 AC 145 ms
27,640 KB
testcase_16 AC 150 ms
31,360 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.IO;
using System.Collections.Generic;

namespace No659_2
{
    public class Program
    {
        void Solve(StreamScanner ss, StreamWriter sw)
        {
            //---------------------------------
            var H = ss.Next(Int);
            var W = ss.Next(Int);
            var T = ss.Next(Int);

            var Sy = ss.Next(Int);
            var Sx = ss.Next(Int);
            var Gy = ss.Next(Int);
            var Gx = ss.Next(Int);

            var B = ss.Next(String, H);

            int[] dx = { 0, 1, 0, -1 };
            int[] dy = { 1, 0, -1, 0 };
            var dl = 4;

            var walkCount = Math.Min(T, 4000 + T % 2);
            var dp = new double[walkCount + 1, H, W];
            dp[0, Sy, Sx] = 1.0;

            for (var k = 1; k <= walkCount; k++)
            {
                for (var y = 1; y < H - 1; y++)
                {
                    for (var x = 1; x < W - 1; x++)
                    {
                        if (B[y][x] == '#') continue;

                        var xQue = new Queue<int>();
                        var yQue = new Queue<int>();
                        var qc = 0;

                        for (var i = 0; i < dl; i++)
                        {
                            var nx = x + dx[i];
                            var ny = y + dy[i];
                            if (B[ny][nx] == '.')
                            {
                                xQue.Enqueue(nx);
                                yQue.Enqueue(ny);
                                qc++;
                            }
                        }

                        if (qc == 0) dp[k, y, x] = dp[k - 1, y, x];

                        while (xQue.Count > 0)
                        {
                            var nx = xQue.Dequeue();
                            var ny = yQue.Dequeue();
                            dp[k, ny, nx] += dp[k - 1, y, x] / qc;
                        }
                    }
                }
            }

            sw.WriteLine(dp[walkCount, Gy, Gx]);
            //---------------------------------
        }

        static void Main()
        {
            var ss = new StreamScanner(new StreamReader(Console.OpenStandardInput()));
            var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            new Program().Solve(ss, sw);
            sw.Flush();
        }

        static readonly Func<string, string> String = s => s;
        static readonly Func<string, int> Int = int.Parse;
        static readonly Func<string, long> Long = long.Parse;
        static readonly Func<string, double> Double = double.Parse;
    }

    public class StreamScanner
    {
        static readonly char[] Sep = {' '};
        readonly Queue<string> buffer = new Queue<string>();
        readonly TextReader textReader;

        public StreamScanner(TextReader textReader)
        {
            this.textReader = textReader;
        }

        public T Next<T>(Func<string, T> parser)
        {
            if (buffer.Count != 0) return parser(buffer.Dequeue());
            var nextStrings = textReader.ReadLine().Split(Sep, StringSplitOptions.RemoveEmptyEntries);
            foreach (var nextString in nextStrings) buffer.Enqueue(nextString);
            return Next(parser);
        }

        public T[] Next<T>(Func<string, T> parser, int x)
        {
            var ret = new T[x];
            for (var i = 0; i < x; ++i) ret[i] = Next(parser);
            return ret;
        }

        public T[][] Next<T>(Func<string, T> parser, int x, int y)
        {
            var ret = new T[y][];
            for (var i = 0; i < y; ++i) ret[i] = Next(parser, x);
            return ret;
        }
    }
}
0