結果
| 問題 |
No.134 走れ!サブロー君
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2021-05-19 15:55:02 |
| 言語 | Java (openjdk 23) |
| 結果 |
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 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 |
ソースコード
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();
}
}
tenten