#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 12, MOD = (int)1e9 + 7;
const ll inf = 1e18;
ll res = inf, d[N];
int n, m;
vector<array<int, 4>> a;
bool cmp(array<int, 4> x, array<int, 4> y) {
return make_pair(x[1], x[2]) < make_pair(y[1], y[2]);
}
vector<int> g[N];
void test() {
cin >> n >> m;
a.resize(m);
for(int i = 0; i < m; i++) {
cin >> a[i][0] >> a[i][1] >> a[i][2] >> a[i][3], d[i] = inf;
}
for(int i = 0; i < m; i++) {
for(int j = 0; j < m; j++) {
if(i == j) continue;
ll inter = a[i][2] - a[j][1] + 1, val = abs(a[i][0] - a[j][0]);
if(a[j][1] + val <= a[i][2] + 1) {
g[i].push_back(j);
}
}
}
set<pair<ll, int>> st;
for(int i = 0; i < m; i++) {
if(a[i][1] == 1) {
d[i] = a[i][3];
st.insert({d[i], i});
}
}
while(!st.empty()) {
auto [w, v] = (*st.begin());
st.erase(st.begin());
for(int to:g[v]) {
if(d[to] == inf) {
st.erase({d[to], to});
d[to] = d[v] + a[to][3];
st.insert({d[to], to});
}
}
}
for(int i = 0; i < m; i++) if(a[i][2] == n){
res = min(res, d[i] );
}
if(res == inf) {
res = -1;
}
cout << res << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1;
// cin >> t;
while(t--)
test();
return 0;
}
Compilation message
treatment.cpp: In function 'void test()':
treatment.cpp:27:20: warning: unused variable 'inter' [-Wunused-variable]
27 | ll inter = a[i][2] - a[j][1] + 1, val = abs(a[i][0] - a[j][0]);
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1627 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
5112 KB |
Output is correct |
8 |
Correct |
2 ms |
5204 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Correct |
2 ms |
4948 KB |
Output is correct |
11 |
Correct |
2 ms |
4948 KB |
Output is correct |
12 |
Correct |
2 ms |
4948 KB |
Output is correct |
13 |
Correct |
2 ms |
5168 KB |
Output is correct |
14 |
Correct |
2 ms |
4948 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
2 ms |
4948 KB |
Output is correct |
17 |
Correct |
2 ms |
4968 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
19 |
Correct |
2 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
5112 KB |
Output is correct |
8 |
Correct |
2 ms |
5204 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Correct |
2 ms |
4948 KB |
Output is correct |
11 |
Correct |
2 ms |
4948 KB |
Output is correct |
12 |
Correct |
2 ms |
4948 KB |
Output is correct |
13 |
Correct |
2 ms |
5168 KB |
Output is correct |
14 |
Correct |
2 ms |
4948 KB |
Output is correct |
15 |
Correct |
2 ms |
4948 KB |
Output is correct |
16 |
Correct |
2 ms |
4948 KB |
Output is correct |
17 |
Correct |
2 ms |
4968 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
19 |
Correct |
2 ms |
4948 KB |
Output is correct |
20 |
Correct |
197 ms |
73032 KB |
Output is correct |
21 |
Correct |
200 ms |
72780 KB |
Output is correct |
22 |
Correct |
49 ms |
6772 KB |
Output is correct |
23 |
Correct |
48 ms |
6736 KB |
Output is correct |
24 |
Correct |
149 ms |
55116 KB |
Output is correct |
25 |
Correct |
87 ms |
40032 KB |
Output is correct |
26 |
Correct |
78 ms |
37964 KB |
Output is correct |
27 |
Correct |
92 ms |
45476 KB |
Output is correct |
28 |
Correct |
140 ms |
54932 KB |
Output is correct |
29 |
Correct |
86 ms |
39768 KB |
Output is correct |
30 |
Correct |
95 ms |
43668 KB |
Output is correct |
31 |
Correct |
88 ms |
46168 KB |
Output is correct |
32 |
Correct |
210 ms |
69328 KB |
Output is correct |
33 |
Correct |
178 ms |
106636 KB |
Output is correct |
34 |
Correct |
171 ms |
68948 KB |
Output is correct |
35 |
Correct |
204 ms |
69452 KB |
Output is correct |
36 |
Correct |
204 ms |
106476 KB |
Output is correct |
37 |
Correct |
184 ms |
68684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1627 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |