結果
問題 | No.134 走れ!サブロー君 |
ユーザー |
|
提出日時 | 2016-05-21 16:21:24 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 185 ms / 5,000 ms |
コード長 | 1,982 bytes |
コンパイル時間 | 3,895 ms |
コンパイル使用メモリ | 78,496 KB |
実行使用メモリ | 42,712 KB |
最終ジャッジ日時 | 2024-10-14 17:16:30 |
合計ジャッジ時間 | 6,756 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 15 |
ソースコード
import java.util.*;public class Main_yukicoder134 {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int x0 = sc.nextInt();int y0 = sc.nextInt();int n = sc.nextInt();int[] x = new int[n];int[] y = new int[n];double[] w = new double[n];double tw = 0;for (int i = 0; i < n; i++) {x[i] = sc.nextInt();y[i] = sc.nextInt();w[i] = sc.nextDouble();tw += w[i];}double[] ww = new double[0x1 << n];for (int i = 0; i < 0x1 << n; i++) {for (int j = 0; j < n; j++) {if ((i & 0x1 << j) != 0) {ww[i] += w[j];}}}final double INF = Double.MAX_VALUE / 2;double[][] dp = new double[n][0x1 << n];for (int j = 0; j < n; j++) {Arrays.fill(dp[j], INF);}// 最初の配達先for (int k = 0; k < n; k++) {double t = (tw + 100) / 120;double dtmp = t * (Math.abs(x0 - x[k]) + Math.abs(y0 - y[k])) + w[k];dp[k][0x1 << k] = dtmp;}for (int i = 1; i < 0x1 << n; i++) {for (int j = 0; j < n; j++) {if ((i & 0x1 << j) == 0) {continue;}for (int k = 0; k < n; k++) {if ((i & 0x1 << k) != 0) {continue;}double t = (tw - ww[i] + 100) / 120;double dtmp = t * (Math.abs(x[j] - x[k]) + Math.abs(y[j] - y[k])) + w[k];dp[k][i | 0x1 << k] = Math.min(dp[k][i | 0x1 << k], dp[j][i] + dtmp);}}}double min = INF;for (int i = 0; i < n; i++) {double t = (double)100 / 120;double dtmp = t * (Math.abs(x0 - x[i]) + Math.abs(y0 - y[i]));min = Math.min(min, dp[i][(0x1 << n) - 1] + dtmp);}System.out.printf("%.8f\n", min);sc.close();}}