#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<ll,ll>
#define fi first
#define se second
#define endl '\n'
#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define rep(x,s,e) for (auto x=s-(s>e);x!=e-(s>e);s<e?x++:x--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n,k;
struct E{
int l,r;
int t;
int c;
};
vector<E> v;
ll memo[5005];
vector<int> al[5005];
bool proc[5005];
ll w[5005];
int main(){
cin.tie(0);
cout.tie(0);
cin.sync_with_stdio(false);
cin>>n>>k;
int a,b,c,d;
rep(x,0,k){
cin>>a>>b>>c>>d;
v.pub({b,c+1,a,d});
}
rep(x,0,k){
rep(y,0,k){
if (v[x].t<=v[y].t && v[y].l+(v[y].t-v[x].t)<=v[x].r) al[x].pub(y);
if (v[y].t<v[x].t && v[y].l+(v[x].t-v[y].t)<=v[x].r) al[x].pub(y);
}
}
ll ans=1e18;
memset(w,63,sizeof(w));
rep(x,0,k) if (v[x].l==1) w[x]=0;
rep(x,0,k){
int curr=-1;
rep(y,0,k) if (!proc[y] && (curr==-1 || w[curr]>w[y])) curr=y;
//cout<<curr<<endl;
proc[curr]=true;
if (v[curr].r==n+1) ans=min(ans,w[curr]+v[curr].c);
for (auto &it:al[curr]){
if (w[it]>w[curr]+v[curr].c){
w[it]=w[curr]+v[curr].c;
}
}
}
if (ans==1e18) cout<<"-1"<<endl;
else cout<<ans<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2268 ms |
524292 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
460 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
1 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
460 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
20 |
Correct |
433 ms |
68428 KB |
Output is correct |
21 |
Correct |
404 ms |
68220 KB |
Output is correct |
22 |
Correct |
263 ms |
1852 KB |
Output is correct |
23 |
Correct |
283 ms |
1900 KB |
Output is correct |
24 |
Correct |
283 ms |
50480 KB |
Output is correct |
25 |
Correct |
241 ms |
35064 KB |
Output is correct |
26 |
Correct |
249 ms |
33880 KB |
Output is correct |
27 |
Correct |
206 ms |
40504 KB |
Output is correct |
28 |
Correct |
300 ms |
50244 KB |
Output is correct |
29 |
Correct |
227 ms |
34756 KB |
Output is correct |
30 |
Correct |
219 ms |
38972 KB |
Output is correct |
31 |
Correct |
219 ms |
41360 KB |
Output is correct |
32 |
Correct |
454 ms |
64724 KB |
Output is correct |
33 |
Correct |
402 ms |
101924 KB |
Output is correct |
34 |
Correct |
396 ms |
64196 KB |
Output is correct |
35 |
Correct |
419 ms |
64904 KB |
Output is correct |
36 |
Correct |
400 ms |
101836 KB |
Output is correct |
37 |
Correct |
446 ms |
64012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2268 ms |
524292 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |