#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mxm=100005,inf=1e17;
int t[mxm],l[mxm],r[mxm],c[mxm];
vector<int> adj[mxm];
int dist[mxm];bool vis[mxm];
void main1(int n,int m){
;
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(0);
int n,m;
cin>>n>>m;
//funny how subtasks 1-3 can be done with dijkstra, and ST4 is... 2d segtree with lazy nodes? idk
//if(m>5000)main1(n,m);
for(int i=0;i<m;i++){
cin>>t[i]>>l[i]>>r[i]>>c[i];
if(l[i]==1)adj[m].push_back(i);
if(r[i]==n)adj[i].push_back(m+1);
}c[m]=c[m+1]=0;
for(int i=0;i<m;i++){
for(int j=i+1;j<m;j++){
//cout<<"Iteration "<<i<<' '<<j<<'\n';
if(t[i]>t[j])swap(i,j);//ensures t[j]>=t[i]
int a,b;
a=l[i]+t[j]-t[i];
b=r[i]-t[j]+t[i];
if(l[i]==1)a=1;
if(r[i]==n)b=n;
//compare range [a,b] with [l[j],r[j]]
b++;r[j]++;
if(b>=l[j])adj[i].push_back(j);
if(r[j]>=a)adj[j].push_back(i);
b--;r[j]--;
if(i>j)swap(i,j);
}
}
for(int i=0;i<m+2;i++)dist[i]=inf;
dist[m]=0;
while(true){
int a=-1;
for(int i=0;i<m+2;i++){
if(vis[i])continue;
if(a==-1 || dist[i]<dist[a])a=i;
}
if(a==-1)break;
vis[a]=true;
for(int x:adj[a]){
dist[x]=min(dist[x],dist[a]+c[x]);
}
}
if(dist[m+1]==inf)cout<<"-1\n";
else cout<<dist[m+1]<<'\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2113 ms |
524292 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
3 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
2 ms |
2636 KB |
Output is correct |
7 |
Correct |
2 ms |
2636 KB |
Output is correct |
8 |
Correct |
3 ms |
2680 KB |
Output is correct |
9 |
Correct |
2 ms |
2680 KB |
Output is correct |
10 |
Correct |
2 ms |
2656 KB |
Output is correct |
11 |
Correct |
2 ms |
2636 KB |
Output is correct |
12 |
Correct |
3 ms |
2636 KB |
Output is correct |
13 |
Correct |
2 ms |
2680 KB |
Output is correct |
14 |
Correct |
2 ms |
2700 KB |
Output is correct |
15 |
Correct |
2 ms |
2636 KB |
Output is correct |
16 |
Correct |
2 ms |
2616 KB |
Output is correct |
17 |
Correct |
3 ms |
2668 KB |
Output is correct |
18 |
Correct |
2 ms |
2636 KB |
Output is correct |
19 |
Correct |
2 ms |
2636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
3 ms |
2636 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
2 ms |
2636 KB |
Output is correct |
6 |
Correct |
2 ms |
2636 KB |
Output is correct |
7 |
Correct |
2 ms |
2636 KB |
Output is correct |
8 |
Correct |
3 ms |
2680 KB |
Output is correct |
9 |
Correct |
2 ms |
2680 KB |
Output is correct |
10 |
Correct |
2 ms |
2656 KB |
Output is correct |
11 |
Correct |
2 ms |
2636 KB |
Output is correct |
12 |
Correct |
3 ms |
2636 KB |
Output is correct |
13 |
Correct |
2 ms |
2680 KB |
Output is correct |
14 |
Correct |
2 ms |
2700 KB |
Output is correct |
15 |
Correct |
2 ms |
2636 KB |
Output is correct |
16 |
Correct |
2 ms |
2616 KB |
Output is correct |
17 |
Correct |
3 ms |
2668 KB |
Output is correct |
18 |
Correct |
2 ms |
2636 KB |
Output is correct |
19 |
Correct |
2 ms |
2636 KB |
Output is correct |
20 |
Correct |
516 ms |
170016 KB |
Output is correct |
21 |
Correct |
512 ms |
170144 KB |
Output is correct |
22 |
Correct |
152 ms |
5908 KB |
Output is correct |
23 |
Correct |
151 ms |
6148 KB |
Output is correct |
24 |
Correct |
399 ms |
115768 KB |
Output is correct |
25 |
Correct |
250 ms |
75616 KB |
Output is correct |
26 |
Correct |
246 ms |
70468 KB |
Output is correct |
27 |
Correct |
272 ms |
84040 KB |
Output is correct |
28 |
Correct |
376 ms |
114784 KB |
Output is correct |
29 |
Correct |
267 ms |
74496 KB |
Output is correct |
30 |
Correct |
250 ms |
80116 KB |
Output is correct |
31 |
Correct |
278 ms |
86292 KB |
Output is correct |
32 |
Correct |
509 ms |
161908 KB |
Output is correct |
33 |
Correct |
598 ms |
216800 KB |
Output is correct |
34 |
Correct |
447 ms |
136372 KB |
Output is correct |
35 |
Correct |
512 ms |
162076 KB |
Output is correct |
36 |
Correct |
609 ms |
215032 KB |
Output is correct |
37 |
Correct |
440 ms |
136524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2113 ms |
524292 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |