Submission #55159

# Submission time Handle Problem Language Result Execution time Memory
55159 2018-07-06T07:14:21 Z 윤교준(#1528) None (JOI14_ho_t4) C++11
50 / 100
2000 ms 17564 KB
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[sz(V)-2])
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define upmax(a,b) (a)=max((a),(b))
#define upmin(a,b) (a)=min((a),(b))
#define rb(x) ((x)&(-(x)))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
void fuk() { exit(-1); }

const int MAXN = 100005;
const int MAXM = 300005;

vector<pii> G[MAXN];

ll D[MAXN]; int DI[MAXN];

int A[MAXM], B[MAXM], C[MAXM];

int H[MAXN];

ll Ans = INFLL;
int N, M, X, MXH;

ll f(int h) {
	priority_queue<pli, vector<pli>, greater<pli>> PQ;

	fill(D, D+N+1, INFLL);
	D[1] = 0;
	PQ.push(pli(0, 1));

	for(; !PQ.empty();) {
		int idx; ll dst; tie(dst, idx) = PQ.top(); PQ.pop();
		if(D[idx] < dst) continue;

		for(pii e : G[idx]) {
			int nidx = e.first; ll ndst = dst + e.second;
			if(H[nidx] < ll(h) - ndst) continue;
			if(D[nidx] <= ndst) continue;
			D[nidx] = ndst;
			PQ.push(pli(ndst, nidx));
			DI[nidx] = idx;
		}
	}

	return D[N]*2 + abs(X - h) + H[N] - h;
}

void g(vector<int> &V) {
	V.clear();
	for(int i = N; 1 < i; i = DI[i])
		V.pb(i);
	V.pb(1);
	revv(V);
}

int main() {
    //freopen("input.txt", "r", stdin);
	ios::sync_with_stdio(false);

	cin >> N >> M >> X;
	for(int i = 1; i <= N; i++) cin >> H[i];
	for(int i = 1; i <= M; i++) cin >> A[i] >> B[i] >> C[i];

	for(int i = 1, a, b, c; i <= M; i++) {
		a = A[i]; b = B[i]; c = C[i];
		if(c <= H[a]) G[a].eb(b, c);
		if(c <= H[b]) G[b].eb(a, c);
	}

	if(INFLL <= f(0)) {
		puts("-1");
		return 0;
	}

	upmin(Ans, f(X));
	
	for(int h = 0; h < X;) {
		ll t = f(h); upmin(Ans, t);
		if(INFLL <= t) break;
		
		vector<int> V; g(V);
		
		ll mnh = INFLL;
		for(int v : V) upmin(mnh, H[v] + D[v]);
		if(X <= mnh) break;
		
		upmin(Ans, f(mnh));
		h = mnh+1;
	}

	cout << Ans << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2808 KB Output is correct
2 Correct 7 ms 3020 KB Output is correct
3 Correct 9 ms 3020 KB Output is correct
4 Correct 5 ms 3020 KB Output is correct
5 Correct 4 ms 3032 KB Output is correct
6 Correct 4 ms 3032 KB Output is correct
7 Correct 4 ms 3032 KB Output is correct
8 Correct 8 ms 3032 KB Output is correct
9 Correct 6 ms 3148 KB Output is correct
10 Correct 9 ms 3148 KB Output is correct
11 Correct 5 ms 3148 KB Output is correct
12 Correct 9 ms 3148 KB Output is correct
13 Correct 6 ms 3148 KB Output is correct
14 Correct 4 ms 3148 KB Output is correct
15 Correct 10 ms 3148 KB Output is correct
16 Correct 7 ms 3148 KB Output is correct
17 Correct 6 ms 3148 KB Output is correct
18 Correct 5 ms 3148 KB Output is correct
19 Correct 5 ms 3148 KB Output is correct
20 Correct 5 ms 3148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 196 ms 11048 KB Output is correct
2 Correct 241 ms 16712 KB Output is correct
3 Correct 222 ms 16712 KB Output is correct
4 Correct 338 ms 17564 KB Output is correct
5 Correct 208 ms 17564 KB Output is correct
6 Correct 10 ms 17564 KB Output is correct
7 Correct 132 ms 17564 KB Output is correct
8 Correct 381 ms 17564 KB Output is correct
9 Correct 188 ms 17564 KB Output is correct
10 Correct 157 ms 17564 KB Output is correct
11 Correct 38 ms 17564 KB Output is correct
12 Correct 153 ms 17564 KB Output is correct
13 Correct 59 ms 17564 KB Output is correct
14 Correct 110 ms 17564 KB Output is correct
15 Correct 9 ms 17564 KB Output is correct
16 Correct 154 ms 17564 KB Output is correct
17 Correct 22 ms 17564 KB Output is correct
18 Correct 33 ms 17564 KB Output is correct
19 Correct 58 ms 17564 KB Output is correct
20 Correct 31 ms 17564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2808 KB Output is correct
2 Correct 7 ms 3020 KB Output is correct
3 Correct 9 ms 3020 KB Output is correct
4 Correct 5 ms 3020 KB Output is correct
5 Correct 4 ms 3032 KB Output is correct
6 Correct 4 ms 3032 KB Output is correct
7 Correct 4 ms 3032 KB Output is correct
8 Correct 8 ms 3032 KB Output is correct
9 Correct 6 ms 3148 KB Output is correct
10 Correct 9 ms 3148 KB Output is correct
11 Correct 5 ms 3148 KB Output is correct
12 Correct 9 ms 3148 KB Output is correct
13 Correct 6 ms 3148 KB Output is correct
14 Correct 4 ms 3148 KB Output is correct
15 Correct 10 ms 3148 KB Output is correct
16 Correct 7 ms 3148 KB Output is correct
17 Correct 6 ms 3148 KB Output is correct
18 Correct 5 ms 3148 KB Output is correct
19 Correct 5 ms 3148 KB Output is correct
20 Correct 5 ms 3148 KB Output is correct
21 Correct 196 ms 11048 KB Output is correct
22 Correct 241 ms 16712 KB Output is correct
23 Correct 222 ms 16712 KB Output is correct
24 Correct 338 ms 17564 KB Output is correct
25 Correct 208 ms 17564 KB Output is correct
26 Correct 10 ms 17564 KB Output is correct
27 Correct 132 ms 17564 KB Output is correct
28 Correct 381 ms 17564 KB Output is correct
29 Correct 188 ms 17564 KB Output is correct
30 Correct 157 ms 17564 KB Output is correct
31 Correct 38 ms 17564 KB Output is correct
32 Correct 153 ms 17564 KB Output is correct
33 Correct 59 ms 17564 KB Output is correct
34 Correct 110 ms 17564 KB Output is correct
35 Correct 9 ms 17564 KB Output is correct
36 Correct 154 ms 17564 KB Output is correct
37 Correct 22 ms 17564 KB Output is correct
38 Correct 33 ms 17564 KB Output is correct
39 Correct 58 ms 17564 KB Output is correct
40 Correct 31 ms 17564 KB Output is correct
41 Correct 132 ms 17564 KB Output is correct
42 Correct 55 ms 17564 KB Output is correct
43 Correct 116 ms 17564 KB Output is correct
44 Correct 906 ms 17564 KB Output is correct
45 Execution timed out 2057 ms 17564 KB Time limit exceeded
46 Halted 0 ms 0 KB -