結果

問題 No.1 道のショートカット
ユーザー 14番14番
提出日時 2016-03-30 02:12:16
言語 C#(csc)
(csc 3.9.0)
結果
RE  
実行時間 -
コード長 3,084 bytes
コンパイル時間 2,450 ms
コンパイル使用メモリ 108,104 KB
実行使用メモリ 27,516 KB
最終ジャッジ日時 2023-09-22 12:41:55
合計ジャッジ時間 7,812 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
20,616 KB
testcase_01 AC 64 ms
20,588 KB
testcase_02 AC 63 ms
22,632 KB
testcase_03 AC 66 ms
22,712 KB
testcase_04 AC 64 ms
22,644 KB
testcase_05 AC 64 ms
20,776 KB
testcase_06 AC 65 ms
20,524 KB
testcase_07 AC 67 ms
22,700 KB
testcase_08 AC 79 ms
21,236 KB
testcase_09 RE -
testcase_10 AC 82 ms
22,928 KB
testcase_11 AC 102 ms
25,104 KB
testcase_12 AC 118 ms
23,764 KB
testcase_13 AC 109 ms
25,652 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 AC 74 ms
20,888 KB
testcase_17 AC 65 ms
20,592 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 AC 74 ms
20,808 KB
testcase_22 AC 68 ms
20,532 KB
testcase_23 AC 158 ms
25,116 KB
testcase_24 AC 153 ms
25,132 KB
testcase_25 AC 86 ms
27,084 KB
testcase_26 AC 77 ms
20,880 KB
testcase_27 AC 137 ms
27,516 KB
testcase_28 RE -
testcase_29 AC 84 ms
23,012 KB
testcase_30 AC 74 ms
22,992 KB
testcase_31 AC 82 ms
22,960 KB
testcase_32 AC 84 ms
22,868 KB
testcase_33 AC 77 ms
20,828 KB
testcase_34 AC 122 ms
27,180 KB
testcase_35 AC 73 ms
23,000 KB
testcase_36 AC 80 ms
20,848 KB
testcase_37 AC 76 ms
22,876 KB
testcase_38 AC 67 ms
18,592 KB
testcase_39 AC 73 ms
22,896 KB
testcase_40 AC 75 ms
20,808 KB
testcase_41 AC 77 ms
20,808 KB
testcase_42 AC 65 ms
22,708 KB
testcase_43 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.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 = @"





";
}

0