結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
FF256grhy
|
| 提出日時 | 2015-05-06 15:40:41 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 12 ms / 5,000 ms |
| コード長 | 1,255 bytes |
| コンパイル時間 | 266 ms |
| コンパイル使用メモリ | 23,680 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-20 16:13:21 |
| 合計ジャッジ時間 | 1,431 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:12:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
12 | scanf("%d%d%d", &n, &money, &path);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:14:42: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
14 | for(i = 0; i < path; i++) { scanf("%d", &s[i]); s[i]--; } // 一応番号は0からにしておく
| ~~~~~^~~~~~~~~~~~~
main.cpp:15:42: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
15 | for(i = 0; i < path; i++) { scanf("%d", &g[i]); g[i]--; }
| ~~~~~^~~~~~~~~~~~~
main.cpp:16:42: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
16 | for(i = 0; i < path; i++) { scanf("%d", &cost[i]); }
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:17:42: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
17 | for(i = 0; i < path; i++) { scanf("%d", &time[i]); }
| ~~~~~^~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>
// 前回のやつよりだいぶシンプルになったはず
int search();
int n, money, path;
int s[1500], g[1500], cost[1500], time[1500];
int list[49][50][301];
int main(void) {
scanf("%d%d%d", &n, &money, &path);
int i;
for(i = 0; i < path; i++) { scanf("%d", &s[i]); s[i]--; } // 一応番号は0からにしておく
for(i = 0; i < path; i++) { scanf("%d", &g[i]); g[i]--; }
for(i = 0; i < path; i++) { scanf("%d", &cost[i]); }
for(i = 0; i < path; i++) { scanf("%d", &time[i]); }
printf("%d\n", search());
return 0;
}
int search() {
int i, j, k, l;
for(i = 0; i < path; i++) {
int t = list[ s[i] ][ g[i] ][ cost[i] ];
if(t == 0 || time[i] < t) { list[ s[i] ][ g[i] ][ cost[i] ] = time[i]; }
}
for(i = 2; i < n; i++) { // goal
for(j = 1; j < i; j++) { // start
for(k = 0; k <= money; k++) { if(list[0][j][k]) {
for(l = 0; k + l <= money; l++) { if(list[j][i][l]) {
int t = list[0][i][k + l];
int sum = list[0][j][k] + list[j][i][l];
if(t == 0 || sum < t) { list[0][i][k + l] = sum; }
} }
} }
}
}
int min = 15000; // > 49 * 300
for(i = 0; i <= money; i++) {
int t = list[0][n - 1][i];
if(t != 0 && t < min) { min = t; }
}
if(min == 15000) { min = -1; }
return min;
}
FF256grhy