結果
問題 | No.20 砂漠のオアシス |
ユーザー | AreTrash |
提出日時 | 2016-08-31 05:34:02 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 78 ms / 5,000 ms |
コード長 | 5,408 bytes |
コンパイル時間 | 956 ms |
コンパイル使用メモリ | 117,344 KB |
実行使用メモリ | 28,624 KB |
最終ジャッジ日時 | 2024-10-13 05:39:00 |
合計ジャッジ時間 | 2,503 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 28 ms
24,000 KB |
testcase_01 | AC | 26 ms
23,996 KB |
testcase_02 | AC | 27 ms
24,004 KB |
testcase_03 | AC | 29 ms
23,872 KB |
testcase_04 | AC | 30 ms
23,628 KB |
testcase_05 | AC | 77 ms
26,116 KB |
testcase_06 | AC | 43 ms
26,316 KB |
testcase_07 | AC | 78 ms
28,624 KB |
testcase_08 | AC | 52 ms
26,960 KB |
testcase_09 | AC | 70 ms
26,572 KB |
testcase_10 | AC | 27 ms
23,876 KB |
testcase_11 | AC | 27 ms
23,876 KB |
testcase_12 | AC | 28 ms
24,124 KB |
testcase_13 | AC | 28 ms
24,628 KB |
testcase_14 | AC | 31 ms
25,800 KB |
testcase_15 | AC | 30 ms
25,792 KB |
testcase_16 | AC | 35 ms
24,164 KB |
testcase_17 | AC | 34 ms
23,892 KB |
testcase_18 | AC | 35 ms
23,896 KB |
testcase_19 | AC | 35 ms
25,828 KB |
testcase_20 | AC | 29 ms
24,008 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; using System.Collections.Generic; using System.Linq; namespace No20{ public class Program{ public static void Main(string[] args){ var sr = new StreamReader(); //--------------------------------- var N = sr.Next<int>(); var V = sr.Next<int>(); var Ox = sr.Next<int>() - 1; var Oy = 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 hp = new int[N, N].ToJaggedArray(); var pq = new PriorityQueue<Status>(); pq.Enqueue(new Status(V, 0, 0)); while(pq.Count > 0){ var stat = pq.Dequeue(); for(var i = 0; i < 4; i++){ var nx = stat.X + dx[i]; var ny = stat.Y + dy[i]; if(isInside(nx, ny)){ var nv = stat.Hp - L[ny][nx]; if(nv <= hp[ny][nx]) continue; if(nx == Ox && ny == Oy) nv *= 2; pq.Enqueue(new Status(nv, nx, ny)); hp[ny][nx] = nv; } } } //foreach(var b in hp){ // Console.WriteLine(string.Join(" ", b)); //} Console.WriteLine(hp[N - 1][N - 1] > 0 ? "YES" : "NO"); //--------------------------------- } } public static class ExMethod{ public static T[][] ToJaggedArray<T>(this T[,] src){ var x = src.GetLength(1); var y = src.GetLength(0); var ret = new T[y][]; for(var i = 0; i < y; i++){ ret[i] = new T[x]; for(var j = 0; j < x; j++){ ret[i][j] = src[i, j]; } } return ret; } } public class Status : IComparable<Status>{ public int Hp; public int X; public int Y; public Status(int hp, int x, int y){ Hp = hp; X = x; Y = y; } public int CompareTo(Status stat){ return -(Hp - stat.Hp); } } public class PriorityQueue<T> : IEnumerable<T> where T : IComparable<T>{ private readonly List<T> _list = new List<T>(); public int Count => _list.Count; IEnumerator<T> IEnumerable<T>.GetEnumerator(){ return _list.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator(){ return _list.GetEnumerator(); } public void Clear(){ _list.Clear(); } public bool Contains(T value){ return _list.Contains(value); } public T Peek(){ return _list[0]; } public void Enqueue(T value){ _list.Add(value); PushHeap(); } public T Dequeue(){ var ret = _list[0]; _list[0] = _list[_list.Count - 1]; _list.RemoveAt(_list.Count - 1); PopHeap(); return ret; } private void PushHeap(){ var i = _list.Count - 1; while(i != 0){ var p = (i - 1) / 2; if(_list[i].CompareTo(_list[p]) > 0) return; SwapIndex(i, i = p); } } private void PopHeap(){ var i = 0; while(true){ var l = 2 * i + 1; var r = l + 1; var maxi = i; if(l < _list.Count && _list[maxi].CompareTo(_list[l]) > 0) maxi = l; if(r < _list.Count && _list[maxi].CompareTo(_list[r]) > 0) maxi = r; if(maxi == i) return; SwapIndex(i, i = maxi); } } private void SwapIndex(int left, int right){ var tmp = _list[left]; _list[left] = _list[right]; _list[right] = tmp; } } 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; } } }