Submission #1062416

# Submission time Handle Problem Language Result Execution time Memory
1062416 2024-08-17T06:33:07 Z TAhmed33 Treatment Project (JOI20_treatment) C++
35 / 100
266 ms 102864 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e16;
array <ll, 4> a[5001];
int n, m;
vector <int> adj[5001];
ll dist[5001];
void solve () {
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		for (int j = 0; j < 4; j++) {
			cin >> a[i][j];
		}
		a[i][1]--;
	}
	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= m; j++) {
			if (a[i][0] <= a[j][0]) {
				if (a[j][1] <= a[i][2] - (a[j][0] - a[i][0])) {
					adj[i].push_back(j);
				}
 			}
			if (a[i][0] >= a[j][0]) {
				if (a[i][2] >= a[j][1] + (a[i][0] - a[j][0])) {
					adj[i].push_back(j);
				}
			}
		}
	}
	for (int i = 1; i <= m; i++) {
		dist[i] = inf;
	}
	priority_queue <pair <ll, ll>, vector <pair <ll, ll>>, greater <>> pq;
	for (int i = 1; i <= m; i++) {
		if (a[i][1] == 0) {
			pq.push({0, i});
			dist[i] = 0;
		}
	}
	while (!pq.empty()) {
		auto k = pq.top();
		pq.pop();
		if (k.first > dist[k.second]) {
			continue;
		}
		for (auto j : adj[k.second]) {
			if (dist[j] > k.first + a[k.second][3]) {
				dist[j] = k.first + a[k.second][3];
				pq.push({dist[j], j});
			}
		}
	}
	ll mn = inf;
	for (int i = 1; i <= m; i++) {
		if (a[i][2] == n) {
			mn = min(mn, dist[i] + a[i][3]);	
		}
	}
	if (mn == inf) {
		cout << -1 << '\n';
	} else {
		cout << mn << '\n';
	}
}		
signed main () {

	ios::sync_with_stdio(0); cin.tie(0);
	int tc = 1; //cin >> tc;
	while (tc--) solve();
}
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 1372 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 584 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 856 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 584 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 856 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 239 ms 69136 KB Output is correct
21 Correct 240 ms 68872 KB Output is correct
22 Correct 135 ms 2644 KB Output is correct
23 Correct 135 ms 2644 KB Output is correct
24 Correct 169 ms 51028 KB Output is correct
25 Correct 114 ms 35668 KB Output is correct
26 Correct 100 ms 34072 KB Output is correct
27 Correct 127 ms 40788 KB Output is correct
28 Correct 159 ms 50772 KB Output is correct
29 Correct 104 ms 35156 KB Output is correct
30 Correct 94 ms 38740 KB Output is correct
31 Correct 100 ms 41752 KB Output is correct
32 Correct 255 ms 65744 KB Output is correct
33 Correct 266 ms 102864 KB Output is correct
34 Correct 252 ms 64340 KB Output is correct
35 Correct 263 ms 65536 KB Output is correct
36 Correct 227 ms 102528 KB Output is correct
37 Correct 245 ms 64340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 1372 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -