結果
問題 | No.134 走れ!サブロー君 |
ユーザー | tenten |
提出日時 | 2021-05-19 15:55:02 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 101 ms / 5,000 ms |
コード長 | 2,525 bytes |
コンパイル時間 | 2,945 ms |
コンパイル使用メモリ | 77,732 KB |
実行使用メモリ | 55,492 KB |
最終ジャッジ日時 | 2024-10-09 19:47:44 |
合計ジャッジ時間 | 4,920 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 55 ms
50,668 KB |
testcase_01 | AC | 56 ms
50,780 KB |
testcase_02 | AC | 55 ms
50,656 KB |
testcase_03 | AC | 56 ms
50,136 KB |
testcase_04 | AC | 60 ms
50,324 KB |
testcase_05 | AC | 65 ms
50,788 KB |
testcase_06 | AC | 83 ms
51,632 KB |
testcase_07 | AC | 88 ms
51,912 KB |
testcase_08 | AC | 101 ms
55,492 KB |
testcase_09 | AC | 101 ms
55,292 KB |
testcase_10 | AC | 55 ms
50,568 KB |
testcase_11 | AC | 54 ms
50,660 KB |
testcase_12 | AC | 54 ms
50,640 KB |
testcase_13 | AC | 54 ms
50,664 KB |
testcase_14 | AC | 54 ms
50,716 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(); } }