結果
| 問題 | No.1 道のショートカット |
| コンテスト | |
| ユーザー |
keroberotte
|
| 提出日時 | 2014-11-20 21:22:05 |
| 言語 | C++11 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,108 bytes |
| 記録 | |
| コンパイル時間 | 206 ms |
| コンパイル使用メモリ | 42,664 KB |
| 実行使用メモリ | 11,556 KB |
| 最終ジャッジ日時 | 2026-03-29 19:38:45 |
| 合計ジャッジ時間 | 6,644 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 WA * 1 |
| other | AC * 4 TLE * 1 -- * 35 |
ソースコード
#include<stdio.h>
#define MAX 1500
#define A 51
typedef struct{
int exists;
int cost;
int time;
}cost_t;
typedef struct{
int exists;
cost_t costs[51];
}path_t;
int get_time(int cost_limit, int start, int via, int goal, cost_t total, path_t pathes[]){
int i;
int min = -1;
if(via == goal){
if(total.cost <= cost_limit){
return total.time;
}
else{
return -1;
}
}
for(i = 0;i < A;i++){
if(pathes[via].exists && pathes[via].costs[i].exists){
cost_t c;
c.cost = pathes[via].costs[i].cost + total.cost;
c.time = pathes[via].costs[i].time + total.time;
int tmp = get_time(cost_limit, via, i, goal, c, pathes);
if((min == -1) || ((tmp != -1) && (tmp < min))){
min = tmp;
}
}
}
return min;
}
int solve(int cost_limit, int goal, path_t pathes[]){
int i, ans = -1;
cost_t c = {0};
ans = get_time(cost_limit, 1, 1, goal, c, pathes);
return ans;
}
int main(){
int i, n, c, v;
int tmp[4][MAX];
path_t pathes[A];
for(i = 0;i < A;i++){
int j;
pathes[i].exists = 0;
for(j = 0;j < A;j++){
pathes[i].costs[j].exists = 0;
pathes[i].costs[j].cost = -1;
pathes[i].costs[j].time = -1;
}
}
scanf("%d %d %d", &n, &c, &v);
for(i = 0;i < 4;i++){
int j;
for(j = 0;j < v;j++){
scanf("%d", &tmp[i][j]);
}
}
for(i = 0;i < v;i++){
int start = tmp[0][i];
int goal = tmp[1][i];
int cost = tmp[2][i];
int time = tmp[3][i];
//printf("start=%d, goal=%d, cost=%d, time=%d\n", start, goal, cost, time);
pathes[start].exists = 1;
pathes[start].costs[goal].exists = 1;
pathes[start].costs[goal].cost = cost;
pathes[start].costs[goal].time = time;
}
printf("%d\n", solve(c, n, pathes));
return 0;
}
keroberotte