結果

問題 No.2739 Time is money
ユーザー PechiPechi
提出日時 2024-04-20 20:03:30
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 512 ms / 2,000 ms
コード長 2,794 bytes
コンパイル時間 2,541 ms
コンパイル使用メモリ 164,736 KB
実行使用メモリ 25,552 KB
最終ジャッジ日時 2024-04-20 20:03:42
合計ジャッジ時間 10,732 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 188 ms
16,128 KB
testcase_03 AC 417 ms
22,212 KB
testcase_04 AC 182 ms
15,616 KB
testcase_05 AC 283 ms
16,444 KB
testcase_06 AC 365 ms
21,004 KB
testcase_07 AC 512 ms
24,448 KB
testcase_08 AC 489 ms
24,960 KB
testcase_09 AC 493 ms
25,088 KB
testcase_10 AC 356 ms
24,192 KB
testcase_11 AC 492 ms
25,200 KB
testcase_12 AC 335 ms
23,552 KB
testcase_13 AC 339 ms
23,552 KB
testcase_14 AC 304 ms
23,592 KB
testcase_15 AC 320 ms
23,804 KB
testcase_16 AC 329 ms
21,604 KB
testcase_17 AC 441 ms
25,528 KB
testcase_18 AC 472 ms
25,552 KB
testcase_19 AC 339 ms
23,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
#include<unordered_set>
#include<random>
#include <array>
#include <complex>
#include<chrono>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
#define LP(I,S,G) for (long long int I = (S); I < (G); ++I)
#define IN(X) 	for (int in = 0; in < X.size(); in++)cin >> X[in]
#define OUT(X) 	for (int in = 0; in < X.size(); in++)cout << X[in]<<" "
#define SORT(X) sort((X).begin(), (X).end())
#define CSORT(X,Y) sort(X.begin(), X.end(),Y)
#define COPY(X,Y) copy(X.begin(), X.end(), Y.begin())
#define ALL(X,Y) for (auto &(X) :(Y))
#define FULL(a)  (a).begin(),(a).end()
#define BFS(Q,S) for(Q.push(S);Q.size()!=0;Q.pop())
typedef long long int ll;
typedef unsigned long long int ull;
long long int M = 998244353;

chrono::system_clock::time_point starttime;
using namespace std::chrono;

inline float getTime() {
	return duration_cast<milliseconds>(system_clock::now() - starttime).count();
}


int dx[] = { -1,0,1,0 }, dy[] = { 0,1,0,-1 };

ll MAX(ll A, ll B) { return ((A) > (B) ? (A) : (B)); }
ll MIN(ll A, ll B) { return ((A) < (B) ? (A) : (B)); }
inline long long int xor128() {
	static long long int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	long long int t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

int main() {
	ll n, m, x;
	cin >> n >> m >> x;
	vector<vector<array<ll, 3>>> g(n);
	LP(i, 0, m) {
		ll u, v, c, t;
		cin >> u >> v >> c >> t;
		--u, --v;
		g[u].push_back({ v,c,t });
		g[v].push_back({ u,c,t });
	}
	function<bool(array<ll, 3>, array<ll, 3>)> f= [x](array<ll, 3> a, array<ll, 3> b) {
		pair<ll, ll> l = { a[0] + (a[1] + x - 1) / x,a[0]+a[1] };
		pair<ll, ll> r = { b[0] + (b[1] + x - 1) / x,b[0]+b[1] };
		return l > r;
	};
	priority_queue<array<ll,3>,vector<array<ll,3>>, function<bool(array<ll,3>, array<ll,3>)>>pq(f);
	pq.push({ 0,0,0 });
	vector<array<ll, 2>> d(n, { -1,-1 });
	d[0] = { 0,0 };
	while (pq.size() != 0) {
		auto[nd, nc, now] = pq.top();
		pq.pop();
		if (nd != d[now][0] || nc != d[now][1])continue;
		ALL(next, g[now]) {
			if (d[next[0]][0] == -1) {
				d[next[0]] = { nd + next[2],nc + next[1] };
				pq.push({ nd + next[2],nc + next[1],next[0] });
			}
			else {
				pair<ll, ll> bc = { d[next[0]][0] + (d[next[0]][1] + x - 1) / x,d[next[0]][0] + d[next[0]][1] };
				pair<ll, ll> cp = { nd + next[2] + (nc + next[1] + x - 1) / x,nd + nc + next[1] + next[2] };
				if (bc > cp) {
					d[next[0]] = { nd + next[2],nc + next[1] };
					pq.push({ nd + next[2],nc + next[1],next[0] });
				}
			}
		}
	}
	if (d[n - 1][0] == -1)cout << -1;
	else {
		ll bc = d[n - 1][0] + (d[n - 1][1] + x - 1) / x;
		cout << bc;
	}
	return 0;
}
0