#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N = (int)1e5 + 10;
const ll inf = (ll)1e18;
ll T[N];
ll L[N];
ll R[N];
ll C[N];
ll dist[N];
bool pro[N];
int main(){
fastIO;
int n, m;
cin >> n >> m;
for(int i = 1; i <= m; i ++ ){
cin >> T[i] >> L[i] >> R[i] >> C[i];
}
for(int i = 1; i <= m ; i ++ ){
dist[i] = inf;
if(L[i] == 1){
dist[i] = C[i];
}
}
int low = -1;
ll outp = inf;
for(int go = 1; go <= m ; go ++ ){
low = -1;
for(int i = 1; i <= m ; i ++ ){
if(pro[i]) continue;
if(dist[i] == inf) continue;
if(low == -1 || dist[i] < dist[low]){
low = i;
}
}
if(low == -1) break;
pro[low] = true;
if(R[low] == n){
outp = min(outp, dist[low]);
}
for(int nex = 1; nex <= m ; nex ++ ){
if(pro[nex]) continue;
if(T[nex] >= T[low]){
if(R[low] + 1 - (T[nex] - T[low]) >= L[nex]){
dist[nex] = min(dist[nex], dist[low] + C[nex]);
}
}
else{
if((L[nex] - 1) + (T[low] - T[nex]) <= R[low]){
dist[nex] = min(dist[nex], dist[low] + C[nex]);
}
}
}
}
if(outp == inf)
cout << "-1\n";
else
cout << outp << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3072 ms |
4292 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
320 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
320 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
172 ms |
588 KB |
Output is correct |
21 |
Correct |
172 ms |
636 KB |
Output is correct |
22 |
Correct |
138 ms |
696 KB |
Output is correct |
23 |
Correct |
104 ms |
632 KB |
Output is correct |
24 |
Correct |
194 ms |
720 KB |
Output is correct |
25 |
Correct |
81 ms |
836 KB |
Output is correct |
26 |
Correct |
54 ms |
608 KB |
Output is correct |
27 |
Correct |
51 ms |
800 KB |
Output is correct |
28 |
Correct |
188 ms |
732 KB |
Output is correct |
29 |
Correct |
76 ms |
716 KB |
Output is correct |
30 |
Correct |
4 ms |
692 KB |
Output is correct |
31 |
Correct |
3 ms |
716 KB |
Output is correct |
32 |
Correct |
224 ms |
716 KB |
Output is correct |
33 |
Correct |
199 ms |
716 KB |
Output is correct |
34 |
Correct |
182 ms |
588 KB |
Output is correct |
35 |
Correct |
230 ms |
588 KB |
Output is correct |
36 |
Correct |
197 ms |
684 KB |
Output is correct |
37 |
Correct |
175 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3072 ms |
4292 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |