結果

問題 No.1 道のショートカット
ユーザー keroberottekeroberotte
提出日時 2014-11-20 21:22:05
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,108 bytes
コンパイル時間 183 ms
コンパイル使用メモリ 27,268 KB
実行使用メモリ 7,112 KB
最終ジャッジ日時 2023-09-22 11:46:24
合計ジャッジ時間 6,880 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0