結果

問題 No.1 道のショートカット
ユーザー FF256grhyFF256grhy
提出日時 2015-05-06 15:40:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 1,255 bytes
コンパイル時間 153 ms
コンパイル使用メモリ 26,996 KB
実行使用メモリ 4,588 KB
最終ジャッジ日時 2023-09-27 21:43:19
合計ジャッジ時間 1,796 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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