結果
| 問題 | No.1 道のショートカット |
| コンテスト | |
| ユーザー |
kuramu
|
| 提出日時 | 2016-01-29 17:34:58 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,115 bytes |
| 記録 | |
| コンパイル時間 | 2,381 ms |
| コンパイル使用メモリ | 77,720 KB |
| 実行使用メモリ | 53,276 KB |
| 最終ジャッジ日時 | 2024-07-08 04:22:23 |
| 合計ジャッジ時間 | 5,287 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 WA * 1 |
| other | AC * 16 WA * 24 |
ソースコード
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) {
BufferedReader stdReader =new BufferedReader(new InputStreamReader(System.in));
try {
int N = Integer.parseInt(stdReader.readLine());
int C = Integer.parseInt(stdReader.readLine());
int V = Integer.parseInt(stdReader.readLine());
String[] temp1 = stdReader.readLine().split(" ");
String[] temp2 = stdReader.readLine().split(" ");
String[] temp3 = stdReader.readLine().split(" ");
String[] temp4 = stdReader.readLine().split(" ");
int[] S = new int[V+1];
int[] T = new int[V+1];
int[] Y = new int[V+1];
int[] M = new int[V+1];
for(int i=1;i<V+1;i++){
S[i] = Integer.parseInt(temp1[i-1]);
T[i] = Integer.parseInt(temp2[i-1]);
Y[i] = Integer.parseInt(temp3[i-1]);
M[i] = Integer.parseInt(temp4[i-1]);
}
int[][] cost = new int[N+1][N+1];
int[][] money = new int[N+1][N+1];
for(int i=1;i<V+1;i++){
cost[S[i]][T[i]] = Y[i];
money[S[i]][T[i]] = M[i];
}
int[] costDP = new int[N+1];
int[] moneyDP = new int[N+1];
moneyDP[0] = 0;
for(int i=1;i<N+1;i++){
for(int j=i-1;j>=1;j--){
if(money[i-j][i]!=0){
if((i-j) != 1){
if(moneyDP[i-j]!=0 && (moneyDP[i] == 0 || moneyDP[i]>moneyDP[i-j]+money[i-j][i])){
if(costDP[i-j]+cost[i-j][i]<=C){
moneyDP[i] = moneyDP[i-j]+money[i-j][i];
costDP[i] = costDP[i-j]+cost[i-j][i];
}
}
}else{
if(costDP[i-j]+cost[i-j][i]<=C){
moneyDP[i] = moneyDP[i-j]+money[i-j][i];
costDP[i] = costDP[i-j]+cost[i-j][i];
}
}
}
}
}
System.out.println(moneyDP[N]!=0?moneyDP[N]:-1);
} catch (IOException e) {
e.printStackTrace();
}
}
}
kuramu