結果
問題 | No.659 徘徊迷路 |
ユーザー | AreTrash |
提出日時 | 2018-03-03 04:22:16 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 694 ms / 2,000 ms |
コード長 | 3,856 bytes |
コンパイル時間 | 1,678 ms |
コンパイル使用メモリ | 108,672 KB |
実行使用メモリ | 22,912 KB |
最終ジャッジ日時 | 2024-06-23 04:39:13 |
合計ジャッジ時間 | 6,942 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 28 ms
18,816 KB |
testcase_01 | AC | 29 ms
18,816 KB |
testcase_02 | AC | 58 ms
22,016 KB |
testcase_03 | AC | 42 ms
22,912 KB |
testcase_04 | AC | 243 ms
22,144 KB |
testcase_05 | AC | 28 ms
18,560 KB |
testcase_06 | AC | 30 ms
18,560 KB |
testcase_07 | AC | 27 ms
18,304 KB |
testcase_08 | AC | 34 ms
19,456 KB |
testcase_09 | AC | 362 ms
22,912 KB |
testcase_10 | AC | 497 ms
22,656 KB |
testcase_11 | AC | 681 ms
22,656 KB |
testcase_12 | AC | 26 ms
17,792 KB |
testcase_13 | AC | 691 ms
22,784 KB |
testcase_14 | AC | 693 ms
22,144 KB |
testcase_15 | AC | 694 ms
22,144 KB |
testcase_16 | AC | 685 ms
22,784 KB |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.IO; using System.Collections.Generic; namespace No659_3 { 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); var d = new (int x, int y)[] {(0, 1), (1, 0), (0, -1), (-1, 0)}; var canGo = new List<(int x, int y)>[H, W]; for (var y = 1; y < H - 1; y++) { for (var x = 1; x < W - 1; x++) { if (B[y][x] == '#') continue; canGo[y, x] = new List<(int x, int y)>(); for (var i = 0; i < d.Length; i++) { var nx = x + d[i].x; var ny = y + d[i].y; if (B[ny][nx] == '.') canGo[y, x].Add((nx, ny)); } } } var walkCount = Math.Min(T, 100000 + T % 2); var dp = new double[2][,]; dp[0] = new double[H, W]; dp[0][Sy, Sx] = 1.0; for (var k = 1; k <= walkCount; k++) { dp[k % 2] = new double[H, W]; for (var y = 1; y < H - 1; y++) { for (var x = 1; x < W - 1; x++) { if (B[y][x] == '#') continue; if (canGo[y,x].Count == 0) { dp[k % 2][y, x] = dp[(k - 1) % 2][y, x]; continue; } foreach (var (nx, ny) in canGo[y,x]) { dp[k % 2][ny, nx] += dp[(k - 1) % 2][y, x] / canGo[y, x].Count; } } } } sw.WriteLine(dp[walkCount % 2][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; } } }