結果

問題 No.1 道のショートカット
ユーザー Luke LiLuke Li
提出日時 2022-03-28 04:35:40
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 14 ms / 5,000 ms
コード長 1,333 bytes
コンパイル時間 1,124 ms
コンパイル使用メモリ 32,256 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 12:48:05
合計ジャッジ時間 2,044 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<stdio.h>
#include <string.h>
#include <stdlib.h>
const int MAX_INT = 0X7fffffff;

int min(int a, int b)
{
	return a>b?b:a;
}
void getArray(int index, int *array){
	int num;
	int cnt = 0;
	memset(array, 0, index);
	while(cnt < index){
        scanf("%d",&num);
        char c=getchar();
        array[cnt++]=num;
        if(c =='\n'){
            break;
        }
   }
}

void findMinTime(int N, int C, int V, int *S, 
int *T, int *Y,int *M){
	int **dp;
	int ans = MAX_INT;
	dp = (int **)malloc(sizeof(int * ) * N);
	for(int i = 0; i < N; i++){
		dp[i] = (int *)malloc(sizeof(int) * (C + 1));
	}
	for(int i = 0; i < N; i++){
		for(int j = 0; j < (C + 1); j++){
			dp[i][j] = MAX_INT;
		}
	}
	dp[0][C] = 0;
	for(int i = 0; i < N; ++i){
		for(int j = C ; j >= 0; --j){
			if(dp[i][j] != MAX_INT){
				for (int k = 0; k < V ; ++k){
					if(i == S[k] - 1 && j - Y[k] >= 0){
						dp[T[k] - 1][j - Y[k]] = min(dp[i][j] + M[k], dp[T[k] - 1][j - Y[k]]);
					}
				}
			}
		}
	}

	for(int j = 0; j < (C + 1); j++)
	{
		ans = min(ans, dp[N-1][j]);
	}
	if(ans == MAX_INT){
		ans = -1;
	}
	printf("%d ", ans);
}

int main(){
	int N,C,V;
	int S[1500], T[1500], Y[1500], M[1500];

	scanf("%d", &N);
	scanf("%d", &C);
	scanf("%d", &V);

	getArray(V, S);
	getArray(V, T);
	getArray(V, Y);
	getArray(V, M);

	findMinTime(N,C,V,S,T,Y,M);
	
}
0