結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
Irmystp
|
| 提出日時 | 2014-11-26 20:39:51 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 8 ms / 5,000 ms |
| コード長 | 1,402 bytes |
| コンパイル時間 | 1,286 ms |
| コンパイル使用メモリ | 159,712 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 16:07:22 |
| 合計ジャッジ時間 | 2,586 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:23:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
23 | scanf("%d%d%d", &N, &C, &V);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
main.cpp:25:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
25 | scanf("%d", &G[x].from);
| ~~~~~^~~~~~~~~~~~~~~~~~
main.cpp:28:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
28 | scanf("%d", &G[x].to);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:31:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
31 | scanf("%d", &G[x].cost);
| ~~~~~^~~~~~~~~~~~~~~~~~
main.cpp:34:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
34 | scanf("%d", &G[x].dist);
| ~~~~~^~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
const int INF = 1<<29;
struct edge{
int from;
int to;
int dist;
int cost;
edge(){} ~edge(){}
edge(int a, int b, int c): to(a), dist(b), cost(c) {}
bool operator <(const edge& r) const {
return dist > r.dist;
}
};
int N, C, V;
vector<edge> G(1500);
int d[51][301];
int main(){
scanf("%d%d%d", &N, &C, &V);
for(int x = 0; x < V; x++){
scanf("%d", &G[x].from);
}
for(int x = 0; x < V; x++){
scanf("%d", &G[x].to);
}
for(int x = 0; x < V; x++){
scanf("%d", &G[x].cost);
}
for(int x = 0; x < V; x++){
scanf("%d", &G[x].dist);
}
for(int x = 0; x <= N; x++){
fill(d[x], d[x]+C+1, INF);
}
d[1][C] = 0;
for(int x = 0; x < N; x++){
bool updated = false;
for(auto& e : G){
for(int y = e.cost; y <= C; y++){
if(d[e.from][y] + e.dist < d[e.to][y - e.cost]){
updated = true;
d[e.to][y - e.cost] = d[e.from][y] + e.dist;
}
}
}
if(!updated) break;
}
int res = INF;
for(int x = 0; x <= C; x++){
res = min(res, d[N][x]);
}
if(res < INF){
printf("%d\n", res);
}else{
puts("-1");
}
return 0;
}
Irmystp