結果

問題 No.1 道のショートカット
ユーザー Luke LiLuke Li
提出日時 2022-03-28 04:02:36
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,534 bytes
コンパイル時間 1,059 ms
コンパイル使用メモリ 31,844 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 12:25:23
合計ジャッジ時間 2,533 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<stdio.h>
#include <string.h>
#include <stdlib.h>

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 = 1000;
	dp = (int **)malloc(sizeof(int * ) * V);
	for(int i = 0; i < V; i++){
		dp[i] = (int *)malloc(sizeof(int) * (C + 1));
	}
	for(int i = 0; i < V; i++){
		for(int j = 0; j < (C + 1); j++){
			dp[i][j] = 1000;
		}
	}
	dp[0][C] = 0;
	printf("%d",T[1393]);
	for(int i = 0; i < N; ++i){
		for(int j = C ; j >= 0; --j){
			if(dp[i][j] != 1000){
				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 == 1000){
		ans = -1;
	}
	printf("%d ", ans);
	// for(int i = 0; i < V; i++){
	// 	for(int j = 0; j < (C + 1); j++){
	// 		printf("%d ", dp[i][j]);
	// 	}
	// printf("\n");
	// }
}

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);
	printf("%d\n",T[1390]);
	printf("%d\n",S[1393]);
	printf("-----------------------\n");


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