#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> t(m), l(m), r(m), c(m);
for (int i = 0; i < m; i++) {
cin >> t[i] >> l[i] >> r[i] >> c[i];
--l[i];
}
vector<vector<int>> g(m);
for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++) {
if (i == j) {
continue;
}
if (t[i] >= t[j]) {
if (l[i] < l[j] + (t[i] - t[j]) && l[j] + (t[i] - t[j]) <= r[i]) {
g[i].push_back(j);
}
} else {
if (r[i] - (t[j] - t[i]) >= l[j] && l[j] > l[i] - (t[j] - t[i])) {
g[i].push_back(j);
}
}
}
}
const long long inf = (long long) 1e18;
vector<long long> dist(m, inf);
set<pair<long long, int>> st;
for (int i = 0; i < m; i++) {
if (l[i] == 0) {
dist[i] = c[i];
st.emplace(dist[i], i);
}
}
while (!st.empty()) {
auto it = st.begin();
int i = it->second;
st.erase(it);
for (int j : g[i]) {
if (dist[j] > dist[i] + c[j]) {
if (dist[j] != inf) {
st.erase(st.find({dist[j], j}));
}
dist[j] = dist[i] + c[j];
st.emplace(dist[j], j);
}
}
}
long long res = inf;
for (int i = 0; i < m; i++) {
if (r[i] == n) {
res = min(res, dist[i]);
}
}
cout << (res == inf ? -1 : res) << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3034 ms |
4992 KB |
Time limit exceeded |
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 |
1 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 |
348 KB |
Output is correct |
8 |
Correct |
0 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 |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 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 |
1 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 |
348 KB |
Output is correct |
8 |
Correct |
0 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 |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 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 |
226 ms |
37836 KB |
Output is correct |
21 |
Correct |
232 ms |
37852 KB |
Output is correct |
22 |
Correct |
139 ms |
852 KB |
Output is correct |
23 |
Correct |
143 ms |
1024 KB |
Output is correct |
24 |
Correct |
108 ms |
15036 KB |
Output is correct |
25 |
Correct |
54 ms |
2388 KB |
Output is correct |
26 |
Correct |
65 ms |
852 KB |
Output is correct |
27 |
Correct |
40 ms |
668 KB |
Output is correct |
28 |
Correct |
112 ms |
15068 KB |
Output is correct |
29 |
Correct |
77 ms |
2384 KB |
Output is correct |
30 |
Correct |
43 ms |
860 KB |
Output is correct |
31 |
Correct |
48 ms |
604 KB |
Output is correct |
32 |
Correct |
242 ms |
37368 KB |
Output is correct |
33 |
Correct |
241 ms |
44380 KB |
Output is correct |
34 |
Correct |
179 ms |
1252 KB |
Output is correct |
35 |
Correct |
243 ms |
36648 KB |
Output is correct |
36 |
Correct |
232 ms |
44260 KB |
Output is correct |
37 |
Correct |
177 ms |
1380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3034 ms |
4992 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |