結果
問題 | No.134 走れ!サブロー君 |
ユーザー | htensai |
提出日時 | 2020-02-10 10:05:45 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 106 ms / 5,000 ms |
コード長 | 1,830 bytes |
コンパイル時間 | 2,945 ms |
コンパイル使用メモリ | 77,464 KB |
実行使用メモリ | 56,908 KB |
最終ジャッジ日時 | 2024-04-08 12:49:42 |
合計ジャッジ時間 | 5,034 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 58 ms
54,240 KB |
testcase_01 | AC | 58 ms
54,252 KB |
testcase_02 | AC | 61 ms
54,356 KB |
testcase_03 | AC | 62 ms
54,264 KB |
testcase_04 | AC | 67 ms
54,376 KB |
testcase_05 | AC | 70 ms
54,496 KB |
testcase_06 | AC | 90 ms
55,512 KB |
testcase_07 | AC | 93 ms
55,784 KB |
testcase_08 | AC | 103 ms
54,840 KB |
testcase_09 | AC | 106 ms
56,908 KB |
testcase_10 | AC | 60 ms
54,248 KB |
testcase_11 | AC | 61 ms
54,248 KB |
testcase_12 | AC | 59 ms
54,356 KB |
testcase_13 | AC | 67 ms
54,324 KB |
testcase_14 | AC | 62 ms
54,240 KB |
ソースコード
import java.util.*; import java.io.*; public class Main { static int x0; static int y0; static int n; static Place[] places; static double[][] dp; public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] first = br.readLine().split(" ", 2); x0 = Integer.parseInt(first[0]); y0 = Integer.parseInt(first[1]); n = Integer.parseInt(br.readLine()); places = new Place[n]; for (int i = 0; i < n; i++) { places[i] = new Place(br.readLine().split(" ", 3)); } dp = new double[1 << n][n + 1]; System.out.println(dfw((1 << n) - 1, n, x0, y0)); } static double dfw(int key, int idx, int x, int y) { if (key == 0) { return (Math.abs(x - x0) + Math.abs(y - y0)) * 100.0 / 120.0; } if (dp[key][idx] != 0.0) { return dp[key][idx]; } double total = 0; for (int i = 0; i < n; i++) { if (((1 << i) & key) != 0) { total += places[i].weight; } } double min = Double.MAX_VALUE; for (int i = 0; i < n; i++) { if (((1 << i) & key) != 0) { double time = (Math.abs(x - places[i].x) + Math.abs(y - places[i].y)) * (total + 100.0) / 120.0 + places[i].weight; min = Math.min(min, dfw(key ^ (1 << i), i, places[i].x, places[i].y) + time); } } dp[key][idx] = min; return min; } static class Place { int x; int y; double weight; public Place(String[] args) { x = Integer.parseInt(args[0]); y = Integer.parseInt(args[1]); weight = Double.parseDouble(args[2]); } } }