結果
問題 |
No.1 道のショートカット
|
ユーザー |
![]() |
提出日時 | 2016-04-13 04:37:24 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 2,427 bytes |
コンパイル時間 | 1,144 ms |
コンパイル使用メモリ | 119,144 KB |
実行使用メモリ | 670,256 KB |
最終ジャッジ日時 | 2024-07-08 04:27:03 |
合計ジャッジ時間 | 7,977 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 7 MLE * 1 -- * 32 |
コンパイルメッセージ
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.Linq; namespace No1_3 { public class Program { public struct Input { public int Before { get; } public int After { get; } public int Cost { get; } public int Time { get; } public Input(int before, int t, int cost, int time) { Before = before; After = t; Cost = cost; Time = time; } } public struct Dp { public int Cost { get; } public int Time { get; } public Dp(int cost, int time) { Cost = cost; Time = time; } } public static void Main(string[] args) { var n = Read(Convert.ToInt32);//街の数 var c = Read(Convert.ToInt32);//所持金 var v = Read(Convert.ToInt32);//道の数 var sn = ReadList(Convert.ToInt32);//街A var tn = ReadList(Convert.ToInt32);//街B var yn = ReadList(Convert.ToInt32);//街A → B へのコスト var mn = ReadList(Convert.ToInt32);//街A → B への時間 var inputList = new List<Input>(); for(var i = 0; i < v; i++) { inputList.Add(new Input(sn[i], tn[i], yn[i], mn[i])); } inputList.Sort((x, y) => x.Before - y.Before); var dpList = new List<Dp>[n + 1]; for(var i = 0; i < dpList.Length; i++){ dpList[i] = new List<Dp>(); } dpList[1].Add(new Dp(0, 0)); foreach(var input in inputList){ foreach(var dp in dpList[input.Before].Where(dp => dp.Cost + input.Cost <= c)){ dpList[input.After].Add(new Dp(dp.Cost + input.Cost, dp.Time + input.Time)); } } var result = dpList[n].Select(dp => dp.Time).Concat(new []{int.MaxValue}).Min(); Console.WriteLine(result == int.MaxValue ? -1 : result); } public static TOutput Read<TOutput>(Converter<string, TOutput> converter) { return converter(Console.ReadLine()); } public static List<TOutput> ReadList<TOutput>(Converter<string, TOutput> converter, char c = ' ') { return Console.ReadLine()?.Split(c).ToList().ConvertAll(converter); } } }