結果

問題 No.496 ワープクリスタル (給料日前編)
ユーザー 👑 jupirojupiro
提出日時 2020-02-01 16:37:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,212 bytes
コンパイル時間 1,353 ms
コンパイル使用メモリ 129,548 KB
実行使用メモリ 13,832 KB
最終ジャッジ日時 2023-10-19 00:07:08
合計ジャッジ時間 2,923 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 4 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 18 ms
13,820 KB
testcase_09 AC 19 ms
13,832 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 3 ms
4,348 KB
testcase_14 AC 7 ms
4,836 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 5 ms
4,860 KB
testcase_19 WA -
testcase_20 AC 4 ms
4,436 KB
testcase_21 AC 3 ms
4,348 KB
testcase_22 WA -
testcase_23 AC 11 ms
7,640 KB
testcase_24 AC 11 ms
7,384 KB
testcase_25 AC 10 ms
6,904 KB
testcase_26 AC 11 ms
7,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long MAX = 5100000;
const long long INF = 1LL << 60;
const long long mod = 1000000007LL;
//const long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

void dijkstra(ll start, vector<vector<pair<ll, ll>>>& graph, vector<ll>& dist) {
	dist[start] = 0;
	priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
	vector<bool> used(dist.size(), false);
	pq.push(make_pair(0, start));
	while (!pq.empty()) {
		ll d, node;
		tie(d, node) = pq.top();
		pq.pop();
		if (used[node]) continue;
		used[node] = true;
		for (pair<ll, ll> element : graph[node]) {
			ll new_d, new_node;
			tie(new_node, new_d) = element;
			new_d += d;
			if (new_d < dist[new_node]) {
				dist[new_node] = new_d;
				pq.push(make_pair(dist[new_node], new_node));
			}
		}
	}
}
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/

	ll gh, gw, n, f; scanf("%lld %lld %lld %lld", &gh, &gw, &n, &f);
	vector<ll> x(n), y(n), c(n);
	for (ll i = 0; i < n; i++) scanf("%lld %lld %lld", &x[i], &y[i], &c[i]);
	x.push_back(1); x.push_back(0);
	y.push_back(0); y.push_back(1);
	c.push_back(f); c.push_back(f);
	n += 2;
	ll H = gh + 1;
	ll W = gw + 1;
	vector<vector<pair<ll, ll>>> g(H * W);
	for (ll i = 0; i < H; i++) {
		for (ll j = 0; j < W; j++) {
			for (ll k = 0; k < n; k++) {
				ll nh = i + x[k];
				ll nw = j + y[k];
				if (nh >= H || nw >= W) continue;
				g[i * W + j].emplace_back(nh * W + nw, c[k]);
			}
		}
	}
	vector<ll> d(H * W, INF);
	dijkstra(0, g, d);
	cout << d[gh * W + gw] << endl;
	return 0;
}
0