結果
問題 | No.1 道のショートカット |
ユーザー | AreTrash |
提出日時 | 2016-04-13 05:14:44 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 80 ms / 5,000 ms |
コード長 | 2,602 bytes |
コンパイル時間 | 2,557 ms |
コンパイル使用メモリ | 110,584 KB |
実行使用メモリ | 26,300 KB |
最終ジャッジ日時 | 2023-09-27 21:55:07 |
合計ジャッジ時間 | 7,238 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 61 ms
21,856 KB |
testcase_01 | AC | 61 ms
23,992 KB |
testcase_02 | AC | 63 ms
24,036 KB |
testcase_03 | AC | 61 ms
23,852 KB |
testcase_04 | AC | 61 ms
21,876 KB |
testcase_05 | AC | 60 ms
21,944 KB |
testcase_06 | AC | 62 ms
21,808 KB |
testcase_07 | AC | 60 ms
25,940 KB |
testcase_08 | AC | 69 ms
24,252 KB |
testcase_09 | AC | 70 ms
22,088 KB |
testcase_10 | AC | 70 ms
21,996 KB |
testcase_11 | AC | 69 ms
22,384 KB |
testcase_12 | AC | 72 ms
22,292 KB |
testcase_13 | AC | 71 ms
22,220 KB |
testcase_14 | AC | 62 ms
23,916 KB |
testcase_15 | AC | 57 ms
19,744 KB |
testcase_16 | AC | 68 ms
23,916 KB |
testcase_17 | AC | 61 ms
21,808 KB |
testcase_18 | AC | 63 ms
21,800 KB |
testcase_19 | AC | 61 ms
23,956 KB |
testcase_20 | AC | 68 ms
21,992 KB |
testcase_21 | AC | 69 ms
21,960 KB |
testcase_22 | AC | 62 ms
23,924 KB |
testcase_23 | AC | 76 ms
26,300 KB |
testcase_24 | AC | 74 ms
24,400 KB |
testcase_25 | AC | 69 ms
22,040 KB |
testcase_26 | AC | 67 ms
22,088 KB |
testcase_27 | AC | 73 ms
26,288 KB |
testcase_28 | AC | 62 ms
21,928 KB |
testcase_29 | AC | 70 ms
22,216 KB |
testcase_30 | AC | 69 ms
22,160 KB |
testcase_31 | AC | 69 ms
24,084 KB |
testcase_32 | AC | 68 ms
21,948 KB |
testcase_33 | AC | 69 ms
21,952 KB |
testcase_34 | AC | 80 ms
22,224 KB |
testcase_35 | AC | 68 ms
22,004 KB |
testcase_36 | AC | 70 ms
20,004 KB |
testcase_37 | AC | 70 ms
22,132 KB |
testcase_38 | AC | 61 ms
19,792 KB |
testcase_39 | AC | 68 ms
22,012 KB |
testcase_40 | AC | 69 ms
23,936 KB |
testcase_41 | AC | 66 ms
22,048 KB |
testcase_42 | AC | 61 ms
21,840 KB |
testcase_43 | AC | 60 ms
21,736 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.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)){ var tmp = new Dp(dp.Cost + input.Cost, dp.Time + input.Time); if(dpList[input.After].Count(d => (d.Cost <= tmp.Cost) && (d.Time <= tmp.Time)) == 0){ dpList[input.After].Add(tmp); } } }//(> <) 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); } } }