結果

問題 No.1 道のショートカット
ユーザー iwashi31iwashi31
提出日時 2014-11-19 00:34:21
言語 C++11
(gcc 11.4.0)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,115 bytes
コンパイル時間 729 ms
コンパイル使用メモリ 84,152 KB
実行使用メモリ 729,244 KB
最終ジャッジ日時 2023-09-22 11:46:47
合計ジャッジ時間 8,427 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <deque>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>

using namespace std;

struct S_load {
	int pnext;
	int cost;
	int time;
};

class C_node {
public:
	long int scost;
	long int stime;
	bool operator<(const C_node& arg) const {
		if (this->stime < arg.stime) return true;
		if (this->stime > arg.stime) return false;
		if (this->scost > arg.scost) return false;
		return true;
	}
};

int N, C, V;
int S[1510], T[1510], Y[1510], M[1510];
bool qflag[1510];
vector<S_load> pnext[1510];
set<C_node> node[1510];
queue<int> ready;

int main() {
	int i;

	// input
	cin >> N;
	cin >> C;
	cin >> V;
	for (i = 0; i < V; i++) cin >> S[i];
	for (i = 0; i < V; i++) cin >> T[i];
	for (i = 0; i < V; i++) cin >> Y[i];
	for (i = 0; i < V; i++) cin >> M[i];

	for (i = 0; i < V; i++) {
		S_load tempload;
		tempload.pnext = T[i];
		tempload.cost = Y[i];
		tempload.time = M[i];
		pnext[S[i]].push_back(tempload);
	}
	for (i = 1; i <= N; i++) qflag[i] = false;

	// implement
	ready.push(1);
	C_node tempnode;
	tempnode.scost = C;
	tempnode.stime = 0;
	node[1].insert(tempnode);

	while (!ready.empty()) {

		int now = ready.front(); ready.pop();

		if (now == N) continue;

		qflag[now] = false;
		vector<S_load>::iterator it;

		for (it = pnext[now].begin(); it != pnext[now].end(); it++) {

			set<C_node>::iterator itc;

			for (itc = node[now].begin(); itc != node[now].end(); itc++) {

				C_node tempnode;
				tempnode.scost = (*itc).scost - (*it).cost;

				if (tempnode.scost >= 0) {
					tempnode.stime = (*itc).stime + (*it).time;
					node[(*it).pnext].insert(tempnode);
					if (!qflag[(*it).pnext]) {
						qflag[(*it).pnext] = true;
						ready.push((*it).pnext);
					}
				}

			}

		}
		node[now].clear();
	}

	if (!node[N].empty()) {
		set<C_node>::iterator it = node[N].begin();
		cout << (*it).stime << endl;
	} else {
		cout << "-1" << endl;
	}

	return 0;
}
0