#include <bits/stdc++.h>
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define mid ((l+r)>>1)
using namespace std;
typedef long long ll;
typedef pair<ll,ll>pll;
const ll oo= 1e5+9;
const ll inf=1e18;
struct node
{
ll t,l,r,c;
} a[oo];
bool cmp(const node&A,const node&B)
{
return A.r < B.r;
}
ll n,m,d[5009];
bool vis[5009];
void solve()
{
cin>>n>>m;
for(ll i=0; i<m; i++)
d[i]=inf;
for(ll i=0; i<m; i++)
{
cin>>a[i].t>>a[i].l>>a[i].r>>a[i].c;
if(a[i].l==1)
d[i]=0;
}
while(1)
{
ll id=-1;
for(ll i=0; i<m; i++)
{
if(id==-1)
{
if((!vis[i])&&d[i]<inf)
id=i;
}
else if(d[id]>d[i]&&!vis[i])
id=i;
}
if(id==-1)
break;
// cout<<id<<endl;
// cout<<d[id]<<"? "<<endl;
vis[id]=1;
for(ll i=0; i<m; i++)
{
if(a[i].l<=a[id].r-abs(a[id].t-a[i].t)+1)
d[i]=min(d[i],d[id]+a[id].c);
}
}
ll ans=inf;
for(ll i=0; i<m; i++)
if(a[i].r==n&&vis[i])
ans=min(ans,d[i]+a[i].c);
if(ans>=inf)
ans=-1;
cout<<ans;
}
int main()
{
ios::sync_with_stdio(0),cin.tie(0);
ll tt=1;
// cin>>tt;
while(tt--)
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
30 ms |
10064 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
84 ms |
2788 KB |
Output is correct |
21 |
Correct |
84 ms |
2648 KB |
Output is correct |
22 |
Correct |
57 ms |
2868 KB |
Output is correct |
23 |
Correct |
37 ms |
2648 KB |
Output is correct |
24 |
Correct |
79 ms |
2648 KB |
Output is correct |
25 |
Correct |
64 ms |
2872 KB |
Output is correct |
26 |
Correct |
54 ms |
2868 KB |
Output is correct |
27 |
Correct |
48 ms |
2648 KB |
Output is correct |
28 |
Correct |
78 ms |
2868 KB |
Output is correct |
29 |
Correct |
56 ms |
2876 KB |
Output is correct |
30 |
Correct |
3 ms |
2652 KB |
Output is correct |
31 |
Correct |
3 ms |
2692 KB |
Output is correct |
32 |
Correct |
129 ms |
2880 KB |
Output is correct |
33 |
Correct |
88 ms |
2652 KB |
Output is correct |
34 |
Correct |
68 ms |
2652 KB |
Output is correct |
35 |
Correct |
129 ms |
2832 KB |
Output is correct |
36 |
Correct |
85 ms |
2648 KB |
Output is correct |
37 |
Correct |
69 ms |
2648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
30 ms |
10064 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |