#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
const int mxM = (int)5e3+10;
const int LINF = (int)1e18;
using pii = pair<int,int>;
int n, m, ans=LINF;
int dis[mxM], vis[mxM];
vector<pii> adj[mxM];
struct Project{ int t, l, r, c; } a[mxM];
int dijkstra(int s){
priority_queue<pii,vector<pii>,greater<pii>> pq;
while(!pq.empty()) pq.pop();
fill(dis,dis+m,LINF); fill(vis,vis+m,0);
dis[s]=0; pq.push({0,s});
while(!pq.empty()){
auto [D,a] = pq.top(); pq.pop();
if(vis[a]) continue; vis[a]=1;
for(auto [b,w] : adj[a])
if(D+w<=dis[b]) dis[b] = D+w, pq.push({dis[b],b});
}
int d = LINF;
for(int i = 0; i < m; i++)
if(a[i].r==n) d=min(d,dis[i]);
return d;
}
int32_t main() {
cin >> n >> m;
for(int i = 0; i < m; i++)
cin >> a[i].t >> a[i].l >> a[i].r >> a[i].c;
for(int i = 0; i < m; i++){
for(int j = 0; j < m; j++){
if(a[i].r-abs(a[i].t-a[j].t)>=a[j].l-1 and i!=j)
adj[i].pb({j,a[j].c});
}
}
for(int i = 0; i < m; i++)
if(a[i].l==1) ans = min(ans, a[i].c+dijkstra(i));
cout << (ans==LINF?-1:ans);
}
Compilation message
treatment.cpp: In function 'long long int dijkstra(long long int)':
treatment.cpp:21:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
21 | if(vis[a]) continue; vis[a]=1;
| ^~
treatment.cpp:21:24: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
21 | if(vis[a]) continue; vis[a]=1;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
14 ms |
1108 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
436 KB |
Output is correct |
14 |
Correct |
1 ms |
432 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
432 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
428 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
436 KB |
Output is correct |
14 |
Correct |
1 ms |
432 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
432 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
428 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Execution timed out |
3038 ms |
245968 KB |
Time limit exceeded |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
14 ms |
1108 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |