#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3039 ms |
7900 KB |
Time limit exceeded |
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 |
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 |
1 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 |
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 |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 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 |
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 |
1 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 |
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 |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
230 ms |
41404 KB |
Output is correct |
21 |
Correct |
228 ms |
41476 KB |
Output is correct |
22 |
Correct |
142 ms |
992 KB |
Output is correct |
23 |
Correct |
141 ms |
848 KB |
Output is correct |
24 |
Correct |
108 ms |
15196 KB |
Output is correct |
25 |
Correct |
76 ms |
2336 KB |
Output is correct |
26 |
Correct |
63 ms |
848 KB |
Output is correct |
27 |
Correct |
66 ms |
744 KB |
Output is correct |
28 |
Correct |
116 ms |
15024 KB |
Output is correct |
29 |
Correct |
77 ms |
2380 KB |
Output is correct |
30 |
Correct |
41 ms |
1096 KB |
Output is correct |
31 |
Correct |
58 ms |
676 KB |
Output is correct |
32 |
Correct |
244 ms |
36824 KB |
Output is correct |
33 |
Correct |
228 ms |
44392 KB |
Output is correct |
34 |
Correct |
181 ms |
1356 KB |
Output is correct |
35 |
Correct |
249 ms |
36696 KB |
Output is correct |
36 |
Correct |
227 ms |
44288 KB |
Output is correct |
37 |
Correct |
181 ms |
1324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3039 ms |
7900 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |