#include<bits/stdc++.h>
#define pb push_back
#define pli pair<ll,ll>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxn=2e5;
const ll inf=1e18;
const ll mod=1e9+7;
ll n,m,t[maxn],l[maxn],r[maxn],c[maxn],d[maxn];
priority_queue<pli,vector<pli>,greater<pli>>pq;
vector<ll>g[maxn];
void solve()
{
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++)
{
for(int j=1;j<=m;j++)
{
if(i==j) continue;
if(t[i]<=t[j])
{
if(l[j]<=r[i]-(t[j]-t[i])+1) g[i].pb(j);
}
else
{
if(r[i]>=l[j]+(t[i]-t[j])-1) g[i].pb(j);
}
}
}
for(int i=1;i<=m;i++)
{
d[i]=inf;
if(l[i]==1)
{
d[i]=c[i];
pq.push({d[i],i});
}
}
while(!pq.empty())
{
ll u=pq.top().se;
ll W=pq.top().fi;
pq.pop();
if(W>d[u]) continue;
if(r[u]==n) {cout << W;return;}
for(int v:g[u])
{
if(d[v]>d[u]+c[v])
{
d[v]=d[u]+c[v];
pq.push({d[v],v});
}
}
}
cout << -1;
}
int main()
{
fastio
//freopen(TASKNAME".INP","r",stdin);
//freopen(TASKNAME".OUT","w",stdout);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
665 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12888 KB |
Output is correct |
2 |
Correct |
2 ms |
13144 KB |
Output is correct |
3 |
Correct |
2 ms |
12892 KB |
Output is correct |
4 |
Correct |
2 ms |
12892 KB |
Output is correct |
5 |
Correct |
2 ms |
12888 KB |
Output is correct |
6 |
Correct |
2 ms |
12892 KB |
Output is correct |
7 |
Correct |
2 ms |
12892 KB |
Output is correct |
8 |
Correct |
2 ms |
12892 KB |
Output is correct |
9 |
Correct |
2 ms |
12892 KB |
Output is correct |
10 |
Correct |
2 ms |
12888 KB |
Output is correct |
11 |
Correct |
2 ms |
12892 KB |
Output is correct |
12 |
Correct |
2 ms |
12948 KB |
Output is correct |
13 |
Correct |
2 ms |
12892 KB |
Output is correct |
14 |
Correct |
2 ms |
12892 KB |
Output is correct |
15 |
Correct |
2 ms |
12892 KB |
Output is correct |
16 |
Correct |
2 ms |
12892 KB |
Output is correct |
17 |
Correct |
2 ms |
12892 KB |
Output is correct |
18 |
Correct |
2 ms |
12892 KB |
Output is correct |
19 |
Correct |
2 ms |
12888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12888 KB |
Output is correct |
2 |
Correct |
2 ms |
13144 KB |
Output is correct |
3 |
Correct |
2 ms |
12892 KB |
Output is correct |
4 |
Correct |
2 ms |
12892 KB |
Output is correct |
5 |
Correct |
2 ms |
12888 KB |
Output is correct |
6 |
Correct |
2 ms |
12892 KB |
Output is correct |
7 |
Correct |
2 ms |
12892 KB |
Output is correct |
8 |
Correct |
2 ms |
12892 KB |
Output is correct |
9 |
Correct |
2 ms |
12892 KB |
Output is correct |
10 |
Correct |
2 ms |
12888 KB |
Output is correct |
11 |
Correct |
2 ms |
12892 KB |
Output is correct |
12 |
Correct |
2 ms |
12948 KB |
Output is correct |
13 |
Correct |
2 ms |
12892 KB |
Output is correct |
14 |
Correct |
2 ms |
12892 KB |
Output is correct |
15 |
Correct |
2 ms |
12892 KB |
Output is correct |
16 |
Correct |
2 ms |
12892 KB |
Output is correct |
17 |
Correct |
2 ms |
12892 KB |
Output is correct |
18 |
Correct |
2 ms |
12892 KB |
Output is correct |
19 |
Correct |
2 ms |
12888 KB |
Output is correct |
20 |
Correct |
195 ms |
141904 KB |
Output is correct |
21 |
Correct |
195 ms |
141340 KB |
Output is correct |
22 |
Correct |
100 ms |
15956 KB |
Output is correct |
23 |
Correct |
92 ms |
15516 KB |
Output is correct |
24 |
Correct |
119 ms |
105580 KB |
Output is correct |
25 |
Correct |
77 ms |
76368 KB |
Output is correct |
26 |
Correct |
72 ms |
73300 KB |
Output is correct |
27 |
Correct |
81 ms |
87120 KB |
Output is correct |
28 |
Correct |
114 ms |
105024 KB |
Output is correct |
29 |
Correct |
74 ms |
75604 KB |
Output is correct |
30 |
Correct |
68 ms |
83356 KB |
Output is correct |
31 |
Correct |
76 ms |
88772 KB |
Output is correct |
32 |
Correct |
206 ms |
132888 KB |
Output is correct |
33 |
Correct |
196 ms |
201556 KB |
Output is correct |
34 |
Correct |
208 ms |
132108 KB |
Output is correct |
35 |
Correct |
201 ms |
132952 KB |
Output is correct |
36 |
Correct |
203 ms |
201296 KB |
Output is correct |
37 |
Correct |
208 ms |
131868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
665 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |