#include <bits/stdc++.h>
using namespace std;
#define sz(v) int(v.size())
#define ar array
typedef long long ll;
const int N = 2e5+10, MOD = 998244353;
const ll INF = 1e18+10;
template <class T>
using min_pq = priority_queue<T, vector<T>, greater<T>>;
void solve() {
int n, m; cin >> n >> m;
vector<ar<int, 4>> a(m);
for (auto& [t, l, r, x] : a) cin >> t >> l >> r >> x, --l, --r;
min_pq<pair<ll, int>> q;
vector<ll> dist(m, INF);
for (int i = 0; i < m; i++) {
auto [t, l, r, x] = a[i];
if (l == 0) {
dist[i] = x;
q.push({dist[i], i});
}
}
while (!q.empty()) {
auto [d_c, c] = q.top(); q.pop();
if (dist[c] != d_c) continue;
for (int i = 0; i < m; i++) {
auto [t, l, r, x] = a[i];
int shrink = abs(t - a[c][0]);
if (l - a[c][2] + shrink > 1) continue;
if (dist[c] + x < dist[i]) {
dist[i] = dist[c] + x;
q.push({dist[i], i});
}
}
}
ll ans = INF;
for (int i = 0; i < m; i++) {
auto [t, l, r, x] = a[i];
if (r == n-1) {
ans = min(ans, dist[i]);
}
}
if (ans >= INF) {
cout << -1 << '\n';
return;
}
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
int T = 1;
// cin >> T;
while (T--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3011 ms |
5848 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
324 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
324 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
57 ms |
588 KB |
Output is correct |
21 |
Correct |
56 ms |
632 KB |
Output is correct |
22 |
Correct |
28 ms |
580 KB |
Output is correct |
23 |
Correct |
18 ms |
620 KB |
Output is correct |
24 |
Correct |
54 ms |
732 KB |
Output is correct |
25 |
Correct |
38 ms |
616 KB |
Output is correct |
26 |
Correct |
31 ms |
616 KB |
Output is correct |
27 |
Correct |
29 ms |
604 KB |
Output is correct |
28 |
Correct |
54 ms |
732 KB |
Output is correct |
29 |
Correct |
32 ms |
620 KB |
Output is correct |
30 |
Correct |
2 ms |
596 KB |
Output is correct |
31 |
Correct |
2 ms |
596 KB |
Output is correct |
32 |
Correct |
109 ms |
760 KB |
Output is correct |
33 |
Correct |
60 ms |
716 KB |
Output is correct |
34 |
Correct |
58 ms |
604 KB |
Output is correct |
35 |
Correct |
105 ms |
724 KB |
Output is correct |
36 |
Correct |
60 ms |
712 KB |
Output is correct |
37 |
Correct |
50 ms |
560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3011 ms |
5848 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |