結果

問題 No.1449 新プロランド
ユーザー Example0911Example0911
提出日時 2021-03-31 14:59:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 1,386 bytes
コンパイル時間 2,840 ms
コンパイル使用メモリ 211,404 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-25 16:46:50
合計ジャッジ時間 3,426 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
#define int long long
using namespace std;
using ll = long long;
using P = pair<ll, pair<ll, ll>>;
const ll INF = (1LL << 61);
ll mod = 1000000007;
int N, M;
vector<pair<ll, ll>>edge[110];
int T[110];

vector<vector<ll>> dijkstra(int s) {
	priority_queue<P, vector<P>, greater<P>>pq;
	// しおむすびを合計t分食べているという情報を追加
	vector<vector<ll>>dist(N, vector<ll>(1010, INF));
	dist[s][T[s]] = T[s];
	pq.push({ dist[s][T[s]],{s, T[s] } });
	while (!pq.empty()) {
		P p = pq.top(); pq.pop();
		ll d = p.first, from = p.second.first, t = p.second.second;
		if (dist[from][t] < d)continue;
		for (auto nv : edge[from]) {
			ll to = nv.first; ll cost = nv.second;
			cost /= t;
			if (to != N)cost += T[to];
			if (dist[from][t] + cost < dist[to][min(1001LL, t + T[to])]) {
				dist[to][min(1001LL, t + T[to])] = dist[from][t] + cost;
				pq.push({ dist[to][min(1001LL, t + T[to])],{to, min(1001LL, t + T[to])} });
			}
		}
	}
	return dist;
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		int A, B, C; cin >> A >> B >> C; A--; B--;
		edge[A].push_back({ B,C });
		edge[B].push_back({ A,C });
	}
	for (int i = 0; i < N; i++)cin >> T[i];
	auto ans = dijkstra(0);
	int res = INF;
	for (int i = 0; i < 1010; i++)res = min(res, ans[N - 1][i]);
	cout << res << endl;
	return 0;
}
0