結果
問題 | No.134 走れ!サブロー君 |
ユーザー |
![]() |
提出日時 | 2015-01-22 23:50:28 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 48 ms / 5,000 ms |
コード長 | 3,730 bytes |
コンパイル時間 | 1,634 ms |
コンパイル使用メモリ | 111,104 KB |
実行使用メモリ | 20,096 KB |
最終ジャッジ日時 | 2024-10-14 17:10:57 |
合計ジャッジ時間 | 2,232 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.IO;using System.Text;using System.Linq;using System.Diagnostics;using System.Collections.Generic;using Enu = System.Linq.Enumerable;class Program{static readonly double INF = 1e100;int N;int[] X, Y;double[] W, Wsum;void Solve(){int SX = reader.Int(), SY = reader.Int();N = reader.Int();X = new int[N];Y = new int[N];W = new double[N];for (int i = 0; i < N; i++){X[i] = reader.Int(); Y[i] = reader.Int(); W[i] = reader.Double();}Wsum = new double[1 << N];for (int seen = 0; seen < (1 << N); seen++)for (int i = 0; i < N; i++)if ((seen >> i & 1) == 0)Wsum[seen] += W[i];var dp = new double[1 << N, N];Fill(dp, INF);for (int i = 0; i < N; i++)dp[1 << i, i] = Cost(SX, SY, i, Wsum[0], W[i]);for (int seen = 0; seen < (1 << N); seen++)for (int last = 0; last < N; last++)if ((seen >> last & 1) == 1)for (int next = 0; next < N; next++)if ((seen >> next & 1) == 0){double cost = dp[seen, last] + Cost(X[last], Y[last], next, Wsum[seen], W[next]);CheckMin(ref dp[seen | (1 << next), next], cost);}double ans = Enu.Range(0, N).Min(i => dp[(1 << N) - 1, i] + Cost(SX, SY, i, Wsum[(1 << N) - 1], 0));Console.WriteLine(ans);Console.ReadLine();}double Cost(int sx, int sy, int next, double wsum, double w){double d = Math.Abs(sx - X[next]) + Math.Abs(sy - Y[next]);return d * (wsum + 100) / 120.0 + w;}void CheckMin(ref double a, double b) { if (b < a) a = b; }void Fill<T>(T[,] a, T val){for (int i = 0; i < a.GetLength(0); i++)for (int j = 0; j < a.GetLength(1); j++)a[i, j] = val;}static void Main() { new Program().Solve(); }Reader reader = new Reader(Console.In);class Reader{private readonly TextReader reader;private readonly char[] separator = { ' ' };private readonly StringSplitOptions removeOp = StringSplitOptions.RemoveEmptyEntries;private string[] A = new string[0];private int i;public Reader(TextReader r) { reader = r; }public bool HasNext() { return Enqueue(); }public string String() { return Dequeue(); }public int Int() { return int.Parse(Dequeue()); }public long Long() { return long.Parse(Dequeue()); }public double Double() { return double.Parse(Dequeue()); }public int[] IntLine() { var s = Line(); return s == "" ? new int[0] : Array.ConvertAll(Split(s), int.Parse); }public int[] IntArray(int N) { return Enumerable.Range(0, N).Select(i => Int()).ToArray(); }public int[][] IntGrid(int H) { return Enumerable.Range(0, H).Select(i => IntLine()).ToArray(); }public string[] StringArray(int N) { return Enumerable.Range(0, N).Select(i => Line()).ToArray(); }public string Line() { return reader.ReadLine().Trim(); }private string[] Split(string s) { return s.Split(separator, removeOp); }private bool Enqueue(){if (i < A.Length) return true;string line = reader.ReadLine();if (line == null) return false;if (line == "") return Enqueue();A = Split(line);i = 0;return true;}private string Dequeue() { Enqueue(); return A[i++]; }}}