結果

問題 No.1 道のショートカット
ユーザー OnjuOnju
提出日時 2015-02-03 04:56:41
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,334 bytes
コンパイル時間 650 ms
コンパイル使用メモリ 65,104 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-22 11:55:46
合計ジャッジ時間 2,146 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

//No.1 道のショートカット

//メモ:
//  有効グラフの閉路はない
//  無効グラフの閉路はある

#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <climits>
#define N_MAX 50
#define V_MAX 1500
using namespace std;

typedef struct
{
	int S;
	int T;
	int Y;
	int M;
} Point;

int N, C, V;
int Si[N_MAX];
Point P[V_MAX];

bool compP(const Point& x, const Point& y)
{
	return x.S == y.S ? x.T < y.T : x.S < y.S;
}

int solve(int p, int c, int m)
{
	static int ans = INT_MAX;

	//時間オーバー、NOT最適解排除
	if (c > C || m >= ans)
		return INT_MAX;

	//ゴール
	if (p == N - 1)
	{
		return (ans = m);
	}

	for (int i = Si[p]; P[i].S == p + 1; ++i)
		solve(P[i].T - 1, c + P[i].Y, m + P[i].M);

	return ans == INT_MAX ? -1 : ans;
}

int main()
{
	memset(Si, 0, sizeof(int)*N_MAX);

	//N,C,V取得
	cin >> N >> C >> V;

	//S,T,Y,M取得
	for (int i = 0; i < V; ++i)
		cin >> P[i].S;
	for (int i = 0; i < V; ++i)
		cin >> P[i].T;
	for (int i = 0; i < V; ++i)
		cin >> P[i].Y;
	for (int i = 0; i < V; ++i)
		cin >> P[i].M;

	//ソート
	sort(P, P + V, compP);

	//各町の開始インデックスを調べておく
	for (int i = 1, n = 2; i < V; ++i)
		if (n == P[i].S)
		{
			Si[n - 1] = i;
			++n;
		}

	//出力
	cout << solve(0, 0, 0) << endl;

	return 0;
}
0