結果
問題 | No.134 走れ!サブロー君 |
ユーザー | ぴろず |
提出日時 | 2015-01-23 09:43:34 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 208 ms / 5,000 ms |
コード長 | 1,323 bytes |
コンパイル時間 | 2,684 ms |
コンパイル使用メモリ | 77,548 KB |
実行使用メモリ | 43,900 KB |
最終ジャッジ日時 | 2024-04-22 18:01:19 |
合計ジャッジ時間 | 6,347 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 152 ms
41,592 KB |
testcase_01 | AC | 154 ms
41,752 KB |
testcase_02 | AC | 160 ms
41,660 KB |
testcase_03 | AC | 172 ms
41,592 KB |
testcase_04 | AC | 178 ms
41,908 KB |
testcase_05 | AC | 187 ms
42,120 KB |
testcase_06 | AC | 194 ms
42,192 KB |
testcase_07 | AC | 190 ms
42,680 KB |
testcase_08 | AC | 208 ms
43,900 KB |
testcase_09 | AC | 203 ms
43,592 KB |
testcase_10 | AC | 160 ms
41,780 KB |
testcase_11 | AC | 160 ms
41,760 KB |
testcase_12 | AC | 156 ms
41,800 KB |
testcase_13 | AC | 142 ms
41,500 KB |
testcase_14 | AC | 126 ms
41,260 KB |
ソースコード
package no134; import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[] x = new int[14]; int[] y = new int[14]; double[] w = new double[14]; x[0] = sc.nextInt(); y[0] = sc.nextInt(); int n = sc.nextInt(); for(int i=1;i<=n;i++) { x[i] = sc.nextInt(); y[i] = sc.nextInt(); w[i] = sc.nextDouble(); } n++; int[][] d = new int[n][n]; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { d[i][j] = Math.abs(x[i] - x[j]) + Math.abs(y[i] - y[j]); } } double[][] dp = new double[n][1<<n]; for(int i=0;i<n;i++) { Arrays.fill(dp[i], 1E10); } dp[0][0] = 0; for(int s=0;s<1<<n;s++) { double t = 0; for(int i=0;i<n;i++) { if ((s >> i & 1) == 0) { t += w[i]; } } t = (t + 100) / 120; for(int i=0;i<n;i++) { if (dp[i][s] >= 1E10) { continue; } for(int j=0;j<n;j++) { if (i == j || (s >> j & 1) == 1) { continue; } // System.out.println("(" + i + "," + Integer.toBinaryString(s) + ") -> (" + j + "," + Integer.toBinaryString(s | 1 << j) + ") : " + (dp[i][s] + d[i][j] * t)); dp[j][s | 1 << j] = Math.min(dp[j][s | 1 << j], dp[i][s] + (d[i][j] * t + w[j])); } } } System.out.println(dp[0][(1<<n)-1]); } }