結果
問題 | No.1 道のショートカット |
ユーザー | 14番 |
提出日時 | 2016-03-30 02:12:16 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 3,084 bytes |
コンパイル時間 | 733 ms |
コンパイル使用メモリ | 112,644 KB |
実行使用メモリ | 23,960 KB |
最終ジャッジ日時 | 2024-07-08 04:26:12 |
合計ジャッジ時間 | 3,438 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 26 ms
18,048 KB |
testcase_01 | AC | 25 ms
18,048 KB |
testcase_02 | AC | 25 ms
18,176 KB |
testcase_03 | AC | 26 ms
18,048 KB |
testcase_04 | AC | 26 ms
18,176 KB |
testcase_05 | AC | 26 ms
17,920 KB |
testcase_06 | AC | 27 ms
18,048 KB |
testcase_07 | AC | 26 ms
18,176 KB |
testcase_08 | AC | 35 ms
20,352 KB |
testcase_09 | RE | - |
testcase_10 | AC | 34 ms
19,968 KB |
testcase_11 | AC | 53 ms
22,528 KB |
testcase_12 | AC | 67 ms
23,424 KB |
testcase_13 | AC | 61 ms
23,168 KB |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | AC | 30 ms
18,560 KB |
testcase_17 | AC | 26 ms
18,048 KB |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | AC | 30 ms
18,688 KB |
testcase_22 | AC | 26 ms
18,304 KB |
testcase_23 | AC | 103 ms
22,732 KB |
testcase_24 | AC | 102 ms
22,656 KB |
testcase_25 | AC | 42 ms
22,912 KB |
testcase_26 | AC | 35 ms
20,352 KB |
testcase_27 | AC | 83 ms
23,040 KB |
testcase_28 | RE | - |
testcase_29 | AC | 39 ms
21,888 KB |
testcase_30 | AC | 32 ms
18,944 KB |
testcase_31 | AC | 38 ms
21,376 KB |
testcase_32 | AC | 39 ms
21,992 KB |
testcase_33 | AC | 33 ms
19,840 KB |
testcase_34 | AC | 71 ms
22,932 KB |
testcase_35 | AC | 31 ms
18,944 KB |
testcase_36 | AC | 33 ms
19,200 KB |
testcase_37 | AC | 31 ms
19,200 KB |
testcase_38 | AC | 26 ms
18,176 KB |
testcase_39 | AC | 31 ms
18,560 KB |
testcase_40 | AC | 32 ms
18,688 KB |
testcase_41 | AC | 32 ms
18,688 KB |
testcase_42 | AC | 28 ms
18,304 KB |
testcase_43 | RE | - |
コンパイルメッセージ
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.Text; public class Program { public void Proc(){ Reader.IsDebug = false; int matiCount = int.Parse(Reader.ReadLine()); this.Money = int.Parse(Reader.ReadLine()); int roadCount = int.Parse(Reader.ReadLine()); int[] inpt = Reader.GetInt(); for(int i=0; i<inpt.Length; i++) { Road r = new Road(); r.From = inpt[i]; RoadList.Add(r); if(!RoadDic.ContainsKey(r.From)) { RoadDic.Add(r.From, new List<Road>()); } RoadDic[r.From].Add(r); } inpt = Reader.GetInt(); for(int i=0; i<inpt.Length; i++) { RoadList[i].To = inpt[i]; } inpt = Reader.GetInt(); for(int i=0; i<inpt.Length; i++) { RoadList[i].Cost = inpt[i]; } inpt = Reader.GetInt(); for(int i=0; i<inpt.Length; i++) { RoadList[i].Time = inpt[i]; } int ans = this.GetAns(1, matiCount, this.Money); Console.WriteLine(ans); } private Dictionary<int, List<Road>> RoadDic = new Dictionary<int, List<Road>>(); private Dictionary<string, int> dic = new Dictionary<string, int>(); private int GetAns(int fromMati, int ToMati, int remain) { string key = fromMati + "#" + ToMati + "#" + remain; if(dic.ContainsKey(key)) { return dic[key]; } if(fromMati == ToMati) { return 0; } if(remain < 0) { return -1; } int ans = int.MaxValue; foreach(Road r in RoadDic[fromMati]) { if(r.Cost <= remain) { int subAns = this.GetAns(r.To, ToMati, remain - r.Cost); if(subAns >= 0) { ans = Math.Min(ans, subAns + r.Time); } } } if(ans == int.MaxValue) { ans = -1; } dic.Add(key, ans); return ans; } private List<Road> RoadList = new List<Road>(); public class Road { public int From; public int To; public int Cost; public int Time; } private int Money = 0; public static void Main(string[] args) { Program prg = new Program(); prg.Proc(); } } class Reader { public static bool IsDebug = true; private static System.IO.StringReader sr; public static string ReadLine() { if(IsDebug) { if(sr == null) { sr = new System.IO.StringReader(initStr.Trim()); } return sr.ReadLine(); } else { return Console.ReadLine(); } } public static int[] GetInt(char delimiter = ' ') { string[] inpt = ReadLine().Split(delimiter); int[] ret = new int[inpt.Length]; for(int i=0; i<inpt.Length; i++) { ret[i] = int.Parse(inpt[i]); } return ret; } private static string initStr = @" "; }