結果

問題 No.659 徘徊迷路
ユーザー iwkjoseciwkjosec
提出日時 2018-06-16 14:23:16
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 538 ms / 2,000 ms
コード長 1,876 bytes
コンパイル時間 2,971 ms
コンパイル使用メモリ 105,084 KB
実行使用メモリ 79,420 KB
最終ジャッジ日時 2023-09-13 06:04:59
合計ジャッジ時間 9,608 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 146 ms
43,192 KB
testcase_01 AC 424 ms
72,120 KB
testcase_02 AC 74 ms
25,308 KB
testcase_03 AC 58 ms
21,872 KB
testcase_04 AC 285 ms
58,076 KB
testcase_05 AC 157 ms
37,056 KB
testcase_06 AC 147 ms
38,800 KB
testcase_07 AC 83 ms
24,364 KB
testcase_08 AC 407 ms
77,808 KB
testcase_09 AC 416 ms
79,420 KB
testcase_10 AC 451 ms
78,256 KB
testcase_11 AC 513 ms
76,576 KB
testcase_12 AC 453 ms
76,128 KB
testcase_13 AC 511 ms
76,624 KB
testcase_14 AC 507 ms
74,808 KB
testcase_15 AC 538 ms
74,656 KB
testcase_16 AC 525 ms
76,688 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.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main()
    {
        var RCT = ReadLine().Split().Select(int.Parse).ToArray();
        var Syx = ReadLine().Split().Select(int.Parse).ToArray();
        var Gyx = ReadLine().Split().Select(int.Parse).ToArray();
        var R = RCT[0];
        var C = RCT[1];
        var T = RCT[2];
        var Sy = Syx[0];
        var Sx = Syx[1];
        var Gy = Gyx[0];
        var Gx = Gyx[1];
        var map = new bool[R, C];
        for (int i = 0; i < R; i++)
        {
            var line = ReadLine();
            for (int j = 0; j < C; j++)
            {
                map[i, j] = line[j] == '.';
            }
        }

        var d = new int[R, C];
        for (int i = 1; i < R - 1; i++)
        {
            for (int j = 1; j < C - 1; j++)
            {
                if (map[i + 1, j]) d[i, j]++;
                if (map[i, j + 1]) d[i, j]++;
                if (map[i - 1, j]) d[i, j]++;
                if (map[i, j - 1]) d[i, j]++;
            }
        }
        if (d[Sy, Sx] == 0)
        {
            WriteLine(1);
            return;
        }
        var dp = new double[R, C, 100000];
        dp[Sy, Sx, 0] = 1;
        for (int k = 1; k < 100000; k++)
        {
            for (int i = 1; i < R - 1; i++)
            {
                for (int j = 1; j < C - 1; j++)
                {
                    dp[i, j, k] = (map[i + 1, j] ? dp[i + 1, j, k - 1] / d[i + 1, j] : 0) + (map[i - 1, j] ? dp[i - 1, j, k - 1] / d[i - 1, j] : 0) + (map[i, j + 1] ? dp[i, j + 1, k - 1] / d[i, j + 1] : 0) + (map[i, j - 1] ? dp[i, j - 1, k - 1] / d[i, j - 1] : 0);
                }
            }
        }
        if (T < 100000) WriteLine(dp[Gy, Gx, T]);
        else WriteLine(T % 2 == 0 ? dp[Gy, Gx, 99998] : dp[Gy, Gx, 99999]);
    }
}
0