結果

問題 No.1 道のショートカット
ユーザー Ysmr_Ry
提出日時 2014-12-12 09:59:41
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,059 bytes
コンパイル時間 381 ms
コンパイル使用メモリ 48,868 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-08 03:38:17
合計ジャッジ時間 2,531 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 3 WA * 33 RE * 4
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:34:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   34 |         scanf( "%d%d%d", &N, &C, &V );
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:36:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   36 |                 scanf( "%d", S+i );
      |                 ~~~~~^~~~~~~~~~~~~
main.cpp:38:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   38 |                 scanf( "%d", T+i );
      |                 ~~~~~^~~~~~~~~~~~~
main.cpp:40:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   40 |                 scanf( "%d", Y+i );
      |                 ~~~~~^~~~~~~~~~~~~
main.cpp:42:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   42 |                 scanf( "%d", M+i );
      |                 ~~~~~^~~~~~~~~~~~~

ソースコード

diff #

#include<cstdio>
#include<algorithm>
#include<limits>
#include<utility>
#include<vector>
#define rep(i,a) for(int i=0;i<(a);++i)

const int INF = std::numeric_limits<int>::max()>>2;

template<class T>
void chmin( T &a, T b )
{
	if( a > b )
		a = b;

	return;
}

struct edge
{
	int to, cost, tim;

	edge( int to, int cost, int tim )
	:	to(to), cost(cost), tim(tim)
	{}
};

int N, C, V;
std::vector<edge> G[50];
int S[50], T[50], Y[50], M[50];

int main()
{
	scanf( "%d%d%d", &N, &C, &V );
	rep( i, N )
		scanf( "%d", S+i );
	rep( i, N )
		scanf( "%d", T+i );
	rep( i, N )
		scanf( "%d", Y+i );
	rep( i, N )
		scanf( "%d", M+i );
	rep( i, N )
		G[S[i]-1].push_back( edge( T[i]-1, Y[i], M[i] ) );

	std::vector<std::vector<int> > dp( 50, std::vector<int>( C+1, INF ) );
	rep( j, C+1 )
		dp[0][j] = 0;

	rep( i, N ) rep( k, C+1 ) rep( j, G[i].size() ) if( k+G[i][j].cost <= C )
		chmin( dp[G[i][j].to][k+G[i][j].cost], dp[i][k]+G[i][j].tim ); 

	printf( "%d\n", dp[N-1][C]==INF?-1:dp[N-1][C] );

	return 0;
}
0