結果

問題 No.1 道のショートカット
ユーザー hotpepsihotpepsi
提出日時 2015-02-15 01:08:51
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,474 bytes
コンパイル時間 592 ms
コンパイル使用メモリ 70,356 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-22 11:57:45
合計ジャッジ時間 2,502 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 1 ms
4,380 KB
testcase_16 WA -
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 2 ms
4,380 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 2 ms
4,380 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 1 ms
4,380 KB
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 AC 1 ms
4,380 KB
testcase_43 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <sstream>
#include <vector>
#include <queue>
#include <cstring>

using namespace std;

typedef pair<int, int> II;
typedef pair<int, II> III;
typedef vector<int> IntVec;
typedef vector<III> IIIVec;

int main(int argc, char *argv[])
{
	string s;
	getline(cin, s);
	int N = atoi(s.c_str());
	getline(cin, s);
	int C = atoi(s.c_str());
	getline(cin, s);
	int V = atoi(s.c_str());
	IntVec S(V), T(V), Y(V), M(V);
	{
		getline(cin, s);
		stringstream ss(s);
		for (int i = 0; i < V; ++i) {
			ss >> S[i];
		}
	}
	{
		getline(cin, s);
		stringstream ss(s);
		for (int i = 0; i < V; ++i) {
			ss >> T[i];
		}
	}
	{
		getline(cin, s);
		stringstream ss(s);
		for (int i = 0; i < V; ++i) {
			ss >> Y[i];
		}
	}
	{
		getline(cin, s);
		stringstream ss(s);
		for (int i = 0; i < V; ++i) {
			ss >> M[i];
		}
	}

	int road[50][50][2] = {};
	for (int i = 0; i < V; ++i) {
		road[S[i] - 1][T[i] - 1][0] = Y[i];
		road[S[i] - 1][T[i] - 1][1] = M[i];
	}
	int cost[50][301];
	memset(cost, 0x3f, sizeof(cost));
	cost[0][0] = 0;
	for (int i = 1; i < N; ++i) {
		for (int j = 0; j < i; ++j) {
			int c = road[j][i][0];
			if (c) {
				for (int k = 0; k <= C - c; ++k) {
					if (cost[j][k] <= C) {
						cost[i][k + c] = min(cost[i][k + c], cost[j][k] + road[j][i][1]);
					}
				}
			}
		}
	}

	int ans = 1 << 29;
	for (int i = 0; i <= C; ++i) {
		ans = min(ans, cost[N - 1][i]);
	}

	cout << (ans < (1<<29) ? ans : -1) << endl;
	return 0;
}
0