#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[j] + (t[i] - t[j]) <= r[i]) {
g[i].push_back(j);
}
} else {
if (r[i] - (t[j] - t[i]) >= l[j]) {
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1458 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 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 |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 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 |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
219 ms |
68588 KB |
Output is correct |
21 |
Correct |
218 ms |
68172 KB |
Output is correct |
22 |
Correct |
111 ms |
2132 KB |
Output is correct |
23 |
Correct |
127 ms |
1996 KB |
Output is correct |
24 |
Correct |
146 ms |
50600 KB |
Output is correct |
25 |
Correct |
103 ms |
35416 KB |
Output is correct |
26 |
Correct |
87 ms |
33980 KB |
Output is correct |
27 |
Correct |
89 ms |
40900 KB |
Output is correct |
28 |
Correct |
139 ms |
50424 KB |
Output is correct |
29 |
Correct |
97 ms |
34864 KB |
Output is correct |
30 |
Correct |
82 ms |
39252 KB |
Output is correct |
31 |
Correct |
79 ms |
41740 KB |
Output is correct |
32 |
Correct |
231 ms |
64896 KB |
Output is correct |
33 |
Correct |
230 ms |
102068 KB |
Output is correct |
34 |
Correct |
237 ms |
64184 KB |
Output is correct |
35 |
Correct |
230 ms |
64856 KB |
Output is correct |
36 |
Correct |
234 ms |
102108 KB |
Output is correct |
37 |
Correct |
220 ms |
63880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1458 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |