#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=1e5+5;
const ll K=350;
const ld pi=acos(-1);
const ll INF=(1LL<<60);
#define SQ(i) ((i)*(i))
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(_a) (ll)_a.size()
ll n,m,dis[N];
vector<ll> v[N];
struct SRC{
ll T,L,R,C;
}plan[N];
priority_queue<pll,vector<pll>,greater<pll> > pq;
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>m;
REP1(i,m){
cin>>plan[i].T>>plan[i].L>>plan[i].R>>plan[i].C;
}
sort(plan+1,plan+m+1,[](SRC A,SRC B){
return A.L<B.L;
});
REP1(i,m){
if(plan[i].L==1)v[0].pb(i),v[i].pb(0);
if(plan[i].R==n)v[m+1].pb(i),v[i].pb(m+1);
dis[i]=INF;
}
REP1(i,m)REP1(j,m){
if(plan[j].R-plan[j].T>=plan[i].L-plan[i].T-1&&plan[j].R+plan[j].T>=plan[i].L+plan[i].T-1){
v[i].pb(j),v[j].pb(i);
}
}
plan[m+1].C=0;
pq.push(mp(dis[0]=0,0));
dis[m+1]=INF;
while(SZ(pq)){
ll x=pq.top().Y,y=pq.top().X;pq.pop();
if(y>dis[x])continue;
for(auto i:v[x]){
if(dis[i]>y+plan[i].C){
pq.push(mp(dis[i]=y+plan[i].C,i));
}
}
}
cout<<(dis[m+1]>=INF?-1:dis[m+1])<<"\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1462 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2668 KB |
Output is correct |
2 |
Incorrect |
3 ms |
2668 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2668 KB |
Output is correct |
2 |
Incorrect |
3 ms |
2668 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1462 ms |
524292 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |