結果
問題 | No.134 走れ!サブロー君 |
ユーザー | tenten |
提出日時 | 2021-05-19 15:55:02 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 115 ms / 5,000 ms |
コード長 | 2,525 bytes |
コンパイル時間 | 3,035 ms |
コンパイル使用メモリ | 77,868 KB |
実行使用メモリ | 41,848 KB |
最終ジャッジ日時 | 2024-04-18 02:06:03 |
合計ジャッジ時間 | 4,778 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 57 ms
37,264 KB |
testcase_01 | AC | 56 ms
37,572 KB |
testcase_02 | AC | 56 ms
37,384 KB |
testcase_03 | AC | 60 ms
36,884 KB |
testcase_04 | AC | 60 ms
37,900 KB |
testcase_05 | AC | 67 ms
37,820 KB |
testcase_06 | AC | 84 ms
38,652 KB |
testcase_07 | AC | 93 ms
39,876 KB |
testcase_08 | AC | 115 ms
41,848 KB |
testcase_09 | AC | 108 ms
41,588 KB |
testcase_10 | AC | 57 ms
37,464 KB |
testcase_11 | AC | 55 ms
37,516 KB |
testcase_12 | AC | 58 ms
37,240 KB |
testcase_13 | AC | 56 ms
37,416 KB |
testcase_14 | AC | 57 ms
37,516 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { static Point[] points; static int count; static double[][] dp; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); Point start = new Point(sc.nextInt(), sc.nextInt(), 0); int n = sc.nextInt(); points = new Point[n + 1]; count = n + 1; points[0] = start; double total = 0; for (int i = 1; i <= n; i++) { points[i] = new Point(sc.nextInt(), sc.nextInt(), sc.nextDouble()); total += points[i].weight; } dp = new double[count][1 << count]; System.out.println(dfw(0, (1 << count) - 1) + total); } static double dfw(int idx, int mask) { if (dp[idx][mask] != 0) { return dp[idx][mask]; } if (mask == 1) { return dp[idx][mask] = points[0].getDistance(points[idx]) * 100 / 120; } double min = Double.MAX_VALUE; double weight = 0; for (int i = 1; i < count; i++) { if (((1 << i) & mask) != 0) { weight += points[i].weight; } } for (int i = 1; i < count; i++) { if (((1 << i) & mask) == 0) { continue; } min = Math.min(min, dfw(i, mask ^ (1 << i)) + points[idx].getDistance(points[i]) * (100 + weight) / 120); } return dp[idx][mask] = min; } static class Point { int x; int y; double weight; public Point(int x, int y, double weight) { this.x = x; this.y = y; this.weight = weight; } public double getDistance(Point p) { return Math.abs(p.x - x) + Math.abs(p.y - y); } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }