結果

問題 No.134 走れ!サブロー君
ユーザー GrenacheGrenache
提出日時 2016-05-21 16:21:24
言語 Java21
(openjdk 21)
結果
AC  
実行時間 169 ms / 5,000 ms
コード長 1,982 bytes
コンパイル時間 5,403 ms
コンパイル使用メモリ 79,752 KB
実行使用メモリ 42,828 KB
最終ジャッジ日時 2024-04-22 18:05:04
合計ジャッジ時間 6,813 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 136 ms
41,540 KB
testcase_01 AC 139 ms
41,676 KB
testcase_02 AC 137 ms
41,836 KB
testcase_03 AC 139 ms
41,832 KB
testcase_04 AC 143 ms
41,608 KB
testcase_05 AC 145 ms
42,060 KB
testcase_06 AC 162 ms
42,140 KB
testcase_07 AC 167 ms
42,612 KB
testcase_08 AC 167 ms
42,828 KB
testcase_09 AC 169 ms
42,392 KB
testcase_10 AC 138 ms
41,624 KB
testcase_11 AC 123 ms
40,464 KB
testcase_12 AC 133 ms
41,720 KB
testcase_13 AC 136 ms
41,696 KB
testcase_14 AC 130 ms
41,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
    }
}
0