結果
問題 | No.134 走れ!サブロー君 |
ユーザー |
![]() |
提出日時 | 2016-04-18 03:05:29 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 162 ms / 5,000 ms |
コード長 | 4,439 bytes |
コンパイル時間 | 2,052 ms |
コンパイル使用メモリ | 107,648 KB |
実行使用メモリ | 24,832 KB |
最終ジャッジ日時 | 2024-10-14 17:15:16 |
合計ジャッジ時間 | 2,538 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 |
コンパイルメッセージ
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.Text;using System.Linq;class Program{public void Proc(){Reader.IsDebug = false;string[] inpt = Reader.ReadLine().Split(' ');this.StartX = int.Parse(inpt[0]);this.StartY = int.Parse(inpt[1]);double nimotsuTotal = 0;int cnt = int.Parse(Reader.ReadLine());this.TargetList.Add(new Haitatsusaki(StartX, StartY, 0));for(int i=0; i<cnt; i++) {inpt = Reader.ReadLine().Split(' ');this.TargetList.Add(new Haitatsusaki(int.Parse(inpt[0]), int.Parse(inpt[1]), double.Parse(inpt[2])));nimotsuTotal += double.Parse(inpt[2]);}int num = 1<<TargetList.Count;num--;double ans = this.GetAns(0, num, nimotsuTotal);Console.WriteLine(ans);}private Dictionary<int, Dictionary<int, double>> dic = new Dictionary<int, Dictionary<int, double>>();public double GetAns(int point, int target, double nimotsu) {if(!dic.ContainsKey(point)) {dic.Add(point, new Dictionary<int, double>());}if(dic[point].ContainsKey(target)) {return dic[point][target];}bool isTargetLast = false;int idx = 0;for(int i=0; i<TargetList.Count; i++) {if((target & 1<<i) == target) {isTargetLast = true;idx = i;break;}}if(isTargetLast) {double tmp1 = this.GetDeliverCost(point, idx, nimotsu);tmp1 += this.GetMoveCost(TargetList[idx].X, TargetList[idx].Y, StartX, StartY, 0);dic[point].Add(target, tmp1);return tmp1;}double ans = double.MaxValue;for(int i=0; i<TargetList.Count; i++) {int key = 1<<i;if((target & key) == key) {double ret = this.GetDeliverCost(point, i, nimotsu);double tmp = this.GetAns(i, target - key, nimotsu - this.TargetList[i].Nimotsu);if(tmp >= 0) {ans = Math.Min(ans, ret + tmp);}}}dic[point].Add(target, ans);return ans;}private double GetDeliverCost(int fromPos, int toPos, double nimotsu) {int x1 = this.TargetList[fromPos].X;int y1 = this.TargetList[fromPos].Y;int x2 = this.TargetList[toPos].X;int y2 = this.TargetList[toPos].Y;double ans = GetMoveCost(x1, y1, x2, y2, nimotsu);ans += this.TargetList[toPos].Nimotsu;return ans;}private double GetMoveCost(int x1, int y1, int x2, int y2, double nimotsu) {double ans = (Math.Abs(x1-x2) + Math.Abs(y1-y2)) * ((nimotsu + 100) / 120d);return ans;}private List<Haitatsusaki> TargetList = new List<Haitatsusaki>();public int StartX;public int StartY;public class Haitatsusaki {public int X;public int Y;public double Nimotsu;public Haitatsusaki(int x, int y, double nimotsu) {this.X = x;this.Y = y;this.Nimotsu = nimotsu;}}public class Reader{public static bool IsDebug = true;private static String PlainInput = @"10 10110 10 1.2";private static System.IO.StringReader Sr = null;public static string ReadLine(){if (IsDebug){if (Sr == null){Sr = new System.IO.StringReader(PlainInput.Trim());}return Sr.ReadLine();}else{return Console.ReadLine();}}public static int[] GetInt(char delimiter = ' ', bool trim = false){string inptStr = ReadLine();if (trim){inptStr = inptStr.Trim();}string[] inpt = inptStr.Split(delimiter);int[] ret = new int[inpt.Length];for (int i = 0; i < inpt.Length; i++){ret[i] = int.Parse(inpt[i]);}return ret;}}static void Main(){Program prg = new Program();prg.Proc();}}