結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
keroberotte
|
| 提出日時 | 2014-11-20 21:22:05 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,108 bytes |
| コンパイル時間 | 130 ms |
| コンパイル使用メモリ | 24,192 KB |
| 実行使用メモリ | 6,784 KB |
| 最終ジャッジ日時 | 2024-07-08 03:35:37 |
| 合計ジャッジ時間 | 6,653 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 WA * 1 |
| other | AC * 4 TLE * 1 -- * 35 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:63:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
63 | scanf("%d %d %d", &n, &c, &v);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:67:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
67 | scanf("%d", &tmp[i][j]);
| ~~~~~^~~~~~~~~~~~~~~~~~
ソースコード
#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