結果

問題 No.1 道のショートカット
コンテスト
ユーザー moyashi_senpai
提出日時 2016-08-17 15:29:26
言語 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
結果
WA  
実行時間 -
コード長 1,523 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 700 ms
コンパイル使用メモリ 105,280 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2026-03-29 21:36:54
合計ジャッジ時間 1,642 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 16 WA * 24
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;
typedef vector<int> Ivec;
typedef pair<int, int> pii;

int main() {
	int n,c,v;
	array<array<pii, 50>, 50> graph = {};
	scanf("%d %d %d", &n, &c, &v);
	vector<pii> roads(v, {0,0});
	for (int i = 0; v > i; i++) {
		int s;
		scanf("%d", &s);
		roads[i].first = s-1;
	}
	for (int i = 0; v > i; i++) {
		int s;
		scanf("%d", &s);
		roads[i].second = s-1;
	}
	for (int i = 0; v > i; i++) {
		int s;
		scanf("%d", &s);
		graph[roads[i].first][roads[i].second].first = s;
	}
	for (int i = 0; v > i; i++) {
		int s;
		scanf("%d", &s);
		graph[roads[i].first][roads[i].second].second = s;
	}

	array<array<int, 301>, 51> dp;
	for (auto itr = dp.begin(); itr != dp.end(); itr++) {
		fill(itr->begin(), itr->end(), INT_MAX);
	}
	dp[0][c] = 0;
	for (int i = 0; n-1 > i; i++) {
		for (int j = 0; c >= j; j++) {
			if (dp[i][j] != INT_MAX) {
				for (int k = i + 1; n > k; k++) {
					if (graph[i][k].first && j - graph[i][k].first >= 0) {
						dp[k][j - graph[i][k].first] = min(dp[k][j - graph[i][k].first], dp[i][j] + graph[i][k].second);
					}
				}
			}
		}
	}
	int ans = *min_element(dp[n - 1].begin(), dp[n - 1].end());
	if (ans == INT_MAX)
		ans = -1;
	printf("%d\n", ans);
	return 0;
}
0