#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pb push_back
const int N=100050;
const ll inf=9e18;
struct project{
int t,l,r,c;
project(){}
project(int a,int b,int d,int e):t(a),l(b),r(d),c(e){}
bool operator < (project b){return l+r<b.l+b.r||(l+r==b.l+b.r&&t<b.t);}
}pro[N];
vector<pii> E[N];
void AddEdge(int u,int v){E[u].pb({v,pro[v].c});E[v].pb({u,pro[u].c});}
ll dist[N];
void Dijkstra(int s,int t){
priority_queue<pair<ll,int>> pq;
pq.push({0,s});
for(int i=s+1;i<=t;i++)dist[i]=inf;
while(pq.size()){
ll d=-pq.top().first;
int u=pq.top().second;
pq.pop();
if(dist[u]!=d)continue;
for(auto e:E[u]){
int v,w;tie(v,w)=e;
if(dist[v]>dist[u]+w){
dist[v]=dist[u]+w;
pq.push({-dist[v],v});
}
}
}
}
int main(){
int n,m;
scanf("%i %i",&n,&m);
for(int i=1;i<=m;i++)scanf("%i %i %i %i",&pro[i].t,&pro[i].l,&pro[i].r,&pro[i].c);
for(int i=1;i<=m;i++){
if(pro[i].l==1)E[0].pb({i,pro[i].c});
for(int j=1;j<i;j++){
int delta_t=abs(pro[i].t-pro[j].t);
if(delta_t>min(pro[j].r,pro[i].r)+1-max(pro[i].l,pro[j].l))continue;
AddEdge(i,j);
}
if(pro[i].r==n)E[i].pb({m+1,0});
}
Dijkstra(0,m+1);
ll ans=dist[m+1];
printf("%lld\n",ans==inf?-1:ans);
return 0;
}
Compilation message
treatment.cpp: In function 'int main()':
treatment.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
37 | scanf("%i %i",&n,&m);
| ~~~~~^~~~~~~~~~~~~~~
treatment.cpp:38:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
38 | for(int i=1;i<=m;i++)scanf("%i %i %i %i",&pro[i].t,&pro[i].l,&pro[i].r,&pro[i].c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3065 ms |
5744 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3065 ms |
5744 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |