結果

問題 No.134 走れ!サブロー君
ユーザー 14番14番
提出日時 2016-04-18 03:05:29
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 177 ms / 5,000 ms
コード長 4,439 bytes
コンパイル時間 906 ms
コンパイル使用メモリ 108,032 KB
実行使用メモリ 25,088 KB
最終ジャッジ日時 2024-04-22 18:04:12
合計ジャッジ時間 2,356 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
19,200 KB
testcase_01 AC 31 ms
18,816 KB
testcase_02 AC 30 ms
18,944 KB
testcase_03 AC 31 ms
18,924 KB
testcase_04 AC 33 ms
19,160 KB
testcase_05 AC 41 ms
19,584 KB
testcase_06 AC 57 ms
21,120 KB
testcase_07 AC 95 ms
24,576 KB
testcase_08 AC 177 ms
24,960 KB
testcase_09 AC 171 ms
25,088 KB
testcase_10 AC 27 ms
19,072 KB
testcase_11 AC 27 ms
18,944 KB
testcase_12 AC 28 ms
18,944 KB
testcase_13 AC 27 ms
19,072 KB
testcase_14 AC 29 ms
18,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
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 10
1
10 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();
    }
}
0