結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-07-23 19:05:07 |
| 言語 | Java (openjdk 23) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 2,239 bytes |
| コンパイル時間 | 2,414 ms |
| コンパイル使用メモリ | 79,728 KB |
| 実行使用メモリ | 743,068 KB |
| 最終ジャッジ日時 | 2024-07-08 04:29:25 |
| 合計ジャッジ時間 | 10,784 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 7 MLE * 1 -- * 32 |
ソースコード
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ArrayList<ArrayList<tpl>> List = new ArrayList<>();
ArrayList<tpl> triple = new ArrayList<>();
int town = sc.nextInt();
int money = sc.nextInt();
int ru = sc.nextInt();
int[] from = new int[ru];
int[] to = new int[ru];
int[] cost = new int[ru];
int[] time = new int[ru];
for(int i=0; i<ru ;i++){//入力
from[i] = sc.nextInt();
}
for(int i=0; i<ru ;i++){//入力
to[i] = sc.nextInt();
}
for(int i=0; i<ru ;i++){//入力
cost[i] = sc.nextInt();
}
for(int i=0; i<ru ;i++){//入力
time[i] = sc.nextInt();
}
triple.add(new tpl(0,0,0));//初期位置 (from = 0)
List.add(new ArrayList<>(triple));
triple.clear();
for(int i=2; i<=town ;i++){//二番目の町から
for(int j=0; j<ru ;j++){
if(to[j] == i){
ArrayList<tpl> sub = new ArrayList<>(List.get(from[j]-1));
for(int t=0; t<sub.size(); t++){
if(cost[j] + sub.get(t).get_cost() <= money){
triple.add(new tpl(from[j], cost[j] + sub.get(t).get_cost(),
time[j] + sub.get(t).get_time()));
}
}
}
}
List.add(new ArrayList<>(triple));
triple.clear();
}
//最短経路を取り出す
triple = List.get(town-1);
if(triple.isEmpty()){
System.out.println(-1);
}else{
ArrayList<Integer> sort = new ArrayList<>();
for(int i=0; i<triple.size(); i++){
sort.add(triple.get(i).get_time());
}
if(sort.isEmpty()){
System.out.println(-1);
}else{
Collections.sort(sort);
System.out.println(sort.get(0));
}
}
}
public static class tpl{
int town_from;
int cost;
int time;
tpl(int from, int cost, int time){
this.town_from = from;
this.cost = cost;
this.time = time;
}
int get_cost(){
return cost;
}
int get_time(){
return time;
}
}
}