結果

問題 No.1 道のショートカット
ユーザー AreTrashAreTrash
提出日時 2016-04-13 03:48:27
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 2,632 bytes
コンパイル時間 5,935 ms
コンパイル使用メモリ 107,444 KB
実行使用メモリ 155,956 KB
最終ジャッジ日時 2023-09-22 12:42:33
合計ジャッジ時間 10,358 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
19,644 KB
testcase_01 AC 67 ms
23,808 KB
testcase_02 AC 67 ms
23,660 KB
testcase_03 AC 68 ms
23,668 KB
testcase_04 AC 66 ms
19,712 KB
testcase_05 AC 66 ms
21,808 KB
testcase_06 AC 67 ms
21,880 KB
testcase_07 AC 67 ms
23,740 KB
testcase_08 AC 97 ms
22,480 KB
testcase_09 AC 76 ms
21,796 KB
testcase_10 AC 119 ms
22,296 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;

namespace No1_1 {
    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 Town { get; }
            public int Cost { get; }
            public int Time { get; }

            public Dp(int town, int cost, int time){
                Town = town;
                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.After - y.After);

            var dpList = new List<Dp>{new Dp(1, 0, 0)};

            foreach(var input in inputList){
                var tmpList = new List<Dp>();
                foreach(var dp in dpList){
                    if((dp.Town == input.Before) && (dp.Cost + input.Cost <= c)){
                        tmpList.Add(new Dp(input.After, dp.Cost + input.Cost, dp.Time + input.Time));
                    }
                }
                dpList.AddRange(tmpList);
            }

            var reachList = dpList.Where(dp => dp.Town == n).ToList();

            var result = int.MaxValue;
            foreach(var reach in reachList){
                result = Math.Min(result, reach.Time);
            }

            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);
        }
    }
}
0