結果
| 問題 |
No.134 走れ!サブロー君
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-01 14:23:53 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 202 ms / 5,000 ms |
| コード長 | 1,486 bytes |
| コンパイル時間 | 2,266 ms |
| コンパイル使用メモリ | 78,688 KB |
| 実行使用メモリ | 44,784 KB |
| 最終ジャッジ日時 | 2024-06-26 20:29:15 |
| 合計ジャッジ時間 | 5,510 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 |
ソースコード
import java.util.Arrays;
import java.util.Scanner;
class Main {
public static void main(String[] args) {
new Main().run();
}
void run() {
Scanner sc=new Scanner(System.in);
long X0=sc.nextLong();
long Y0=sc.nextLong();
int N=sc.nextInt();
long[] X=new long[N+1];
long[] Y=new long[N+1];
double[] W=new double[N+1];
for(int i=0;i<N;++i) {
X[i+1]=sc.nextLong();
Y[i+1]=sc.nextLong();
W[i+1]=sc.nextDouble();
X[i+1]-=X0;
Y[i+1]-=Y0;
}
N++;
double[] sumW=new double[1<<N];
Arrays.fill(sumW,Arrays.stream(W).sum());
for(int s=0;s<1<<N;++s) {
for(int shift=0;shift<N;++shift) {
if((s>>shift)%2==1)sumW[s]-=W[shift];
}
}
double[][] dp=new double[1<<N][N];
double INF=Double.MAX_VALUE/3;
for(int i=0;i<dp.length;++i)
for(int j=0;j<dp[i].length;++j)
dp[i][j]=INF;
dp[1][0]=0;
for(int s=0;s<(1<<N)-1;++s) {
for(int cur=0;cur<N;++cur) {
if((s>>cur)%2==0)continue;
for(int next=0;next<N;++next) {
if((s>>next)%2==1)continue;
int ns=s|1<<next;
double dist=Math.abs(X[cur]-X[next])+Math.abs(Y[cur]-Y[next]);
dp[ns][next]=Math.min(dp[ns][next], dp[s][cur]+dist*(sumW[s]+100)/120+W[next]);
}
}
}
double ans=Double.MAX_VALUE/3;
for(int i=1;i<N;++i) {
double dist=Math.abs(X[i])+Math.abs(Y[i]);
ans=Math.min(ans, dp[(1<<N)-1][i]+dist*100/120);
}
System.out.println(ans);
}
static void tr(Object... objects) {
System.out.println(Arrays.deepToString(objects));
}
}