結果

問題 No.1 道のショートカット
コンテスト
ユーザー kurenai3110
提出日時 2016-09-10 18:24:18
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,193 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 307 ms
コンパイル使用メモリ 76,716 KB
最終ジャッジ日時 2026-04-03 01:23:59
合計ジャッジ時間 631 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:38:36: error: 'INT32_MAX' was not declared in this scope
   38 |                         DP[i][j] = INT32_MAX;
      |                                    ^~~~~~~~~
main.cpp:6:1: note: 'INT32_MAX' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
    5 | #include <cstring>
  +++ |+#include <cstdint>
    6 | using namespace std;
main.cpp:50:41: error: 'INT32_MAX' was not declared in this scope
   50 |                         if (DP[i][j] == INT32_MAX) continue;
      |                                         ^~~~~~~~~
main.cpp:50:41: note: 'INT32_MAX' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
main.cpp:59:18: error: 'INT32_MAX' was not declared in this scope
   59 |         int mn = INT32_MAX;
      |                  ^~~~~~~~~
main.cpp:59:18: note: 'INT32_MAX' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define MAX_N 51

int N, C, V;

struct Edge {
	int to, cost, time;
};

vector<Edge> E[MAX_N];
int DP[301][51];

void add_edge(int a, int b, int c,int t) {
	E[a].push_back({ b,c,t });
}

int main()
{
	cin >> N >> C >> V;
	vector<int> S(V), T(V), Y(V), M(V);
	rep(i, V)cin >> S[i];
	rep(i, V)cin >> T[i];
	rep(i, V)cin >> Y[i];
	rep(i, V)cin >> M[i];

	for (int i = 1; i <= N; i++) {

	}
	for (int i = 0; i <= C; i++) {
		for (int j = 1; j <= N; j++) {
			DP[i][j] = INT32_MAX;
		}
	}

	for (int i = 0; i < V; i++) {
		add_edge(S[i], T[i], Y[i], M[i]);
	}

	DP[C][1] = 0;

	for (int i = C; i >= 0; i--) {
		for (int j = 1; j <= N; j++) {
			if (DP[i][j] == INT32_MAX) continue;

			for (int k = 0; k < E[j].size(); k++) {
				if (i - E[j][k].cost < 0)continue;
				DP[i - E[j][k].cost][E[j][k].to] = min(DP[i - E[j][k].cost][E[j][k].to], DP[i][j] + E[j][k].time);
			}
		}
	}

	int mn = INT32_MAX;
	for (int i = 0; i <= C; i++) {
		mn = min(mn, DP[i][N]);
	}
	if (mn == INT32_MAX) cout << -1 << endl;
	else cout << mn << endl;

	return 0;
}
0