結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-06-28 15:56:22 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,598 bytes |
| コンパイル時間 | 846 ms |
| コンパイル使用メモリ | 113,836 KB |
| 実行使用メモリ | 216,972 KB |
| 最終ジャッジ日時 | 2024-07-08 04:09:15 |
| 合計ジャッジ時間 | 7,755 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 7 TLE * 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 YukiCoderNo1
{
class Program
{
private class RoadData
{
public int nextTown
{
get;
private set;
}
public int cost
{
get;
private set;
}
public int time
{
get;
private set;
}
public RoadData(int nextTown, int cost, int time)
{
this.nextTown = nextTown;
this.cost = cost;
this.time = time;
}
}
private static Dictionary<int, List<RoadData>> roadData = new Dictionary<int, List<RoadData>>();
static void Main()
{
int targetTown = int.Parse(Console.ReadLine());
int money = int.Parse(Console.ReadLine());
int roadCount = int.Parse(Console.ReadLine());
int[] townStart = (Console.ReadLine()).Split(' ').Select(value => int.Parse(value)).ToArray();
int[] townEnd = (Console.ReadLine()).Split(' ').Select(value => int.Parse(value)).ToArray();
int[] cost = (Console.ReadLine()).Split(' ').Select(value => int.Parse(value)).ToArray();
int[] time = (Console.ReadLine()).Split(' ').Select(value => int.Parse(value)).ToArray();
for (int i = 0; i < roadCount; i++)
{
roadData.Add(i, new List<RoadData>());
}
for (int i = 0; i < roadCount; i++)
{
roadData[townStart[i]].Add(new RoadData(townEnd[i], cost[i], time[i]));
}
List<int> timeList = GetTimeList(1, targetTown, money, 0);
if (timeList.Count == 0) { timeList.Add(-1); }
Console.WriteLine("{0}", timeList.Min());
}
private static List<int> GetTimeList(int nowTown, int targetTown, int nowMoney, int nowTime)
{
List<int> result = new List<int>();
if (nowTown == targetTown)
{
result.Add(nowTime);
}
else
{
foreach (RoadData buffer in roadData[nowTown])
{
if ((nowMoney - buffer.cost) >= 0)
{
result.AddRange(GetTimeList(buffer.nextTown, targetTown, (nowMoney - buffer.cost), (nowTime + buffer.time)));
}
}
}
return result;
}
}
}