結果
問題 | No.34 砂漠の行商人 |
ユーザー | AreTrash |
提出日時 | 2016-08-31 06:37:16 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 3,509 ms / 5,000 ms |
コード長 | 3,191 bytes |
コンパイル時間 | 3,849 ms |
コンパイル使用メモリ | 106,676 KB |
実行使用メモリ | 87,060 KB |
最終ジャッジ日時 | 2023-09-10 19:25:00 |
合計ジャッジ時間 | 19,109 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 59 ms
20,704 KB |
testcase_01 | AC | 61 ms
20,772 KB |
testcase_02 | AC | 61 ms
20,780 KB |
testcase_03 | AC | 59 ms
22,816 KB |
testcase_04 | AC | 93 ms
21,992 KB |
testcase_05 | AC | 92 ms
20,020 KB |
testcase_06 | AC | 63 ms
20,772 KB |
testcase_07 | AC | 116 ms
22,868 KB |
testcase_08 | AC | 136 ms
25,860 KB |
testcase_09 | AC | 1,046 ms
49,232 KB |
testcase_10 | AC | 123 ms
25,960 KB |
testcase_11 | AC | 1,734 ms
83,496 KB |
testcase_12 | AC | 80 ms
21,788 KB |
testcase_13 | AC | 3,509 ms
87,060 KB |
testcase_14 | AC | 2,584 ms
74,012 KB |
testcase_15 | AC | 66 ms
25,300 KB |
testcase_16 | AC | 183 ms
29,992 KB |
testcase_17 | AC | 65 ms
26,576 KB |
testcase_18 | AC | 71 ms
21,236 KB |
testcase_19 | AC | 776 ms
41,908 KB |
testcase_20 | AC | 1,354 ms
57,912 KB |
testcase_21 | AC | 66 ms
22,896 KB |
testcase_22 | AC | 78 ms
26,412 KB |
testcase_23 | AC | 65 ms
23,440 KB |
testcase_24 | AC | 1,859 ms
65,924 KB |
testcase_25 | AC | 137 ms
24,860 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.Collections.Generic; using System.IO; namespace No34{ public class Program{ public static void Main(string[] args){ var sr = new StreamReader(); //--------------------------------- var N = sr.Next<int>(); var V = sr.Next<int>(); var Sx = sr.Next<int>() - 1; var Sy = sr.Next<int>() - 1; var Gx = sr.Next<int>() - 1; var Gy = sr.Next<int>() - 1; var L = sr.Next<int>(N, N); Func<int, int, bool> isInside = (x, y) => 0 <= x && x < N && 0 <= y && y < N; var dx = new[]{0, 1, 0, -1}; var dy = new[]{1, 0, -1, 0}; var dist = new int[V + 1, N, N]; var que = new Queue<int>(); dist[V, Sx, Sy] = 1; que.Enqueue(V); que.Enqueue(Sx); que.Enqueue(Sy); var res = 0; while(que.Count > 0){ var v = que.Dequeue(); var x = que.Dequeue(); var y = que.Dequeue(); for(var i = 0; i < 4; i++){ var nx = x + dx[i]; var ny = y + dy[i]; if(isInside(nx, ny)){ var nv = v - L[ny][nx]; if(nv <= 0) continue; if(dist[nv, nx, ny] != 0 && dist[nv, nx, ny] <= dist[v, x, y] + 1) continue; que.Enqueue(nv); que.Enqueue(nx); que.Enqueue(ny); dist[nv, nx, ny] = dist[v, x, y] + 1; if(nx == Gx && ny == Gy){ res = dist[nv, nx, ny]; goto End; } } } } End: Console.WriteLine(res - 1); //--------------------------------- } } public class StreamReader{ private readonly char[] _c = {' '}; private int _index = -1; private string[] _input = new string[0]; public T Next<T>(){ if(_index == _input.Length - 1){ _index = -1; while(true){ string rl = Console.ReadLine(); if(rl == null){ if(typeof(T).IsClass) return default(T); return (T)typeof(T).GetField("MinValue").GetValue(null); } if(rl != ""){ _input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries); break; } } } return (T)Convert.ChangeType(_input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture); } public T[] Next<T>(int x){ var ret = new T[x]; for(var i = 0; i < x; ++i) ret[i] = Next<T>(); return ret; } public T[][] Next<T>(int y, int x){ var ret = new T[y][]; for(var i = 0; i < y; ++i) ret[i] = Next<T>(x); return ret; } } }