This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const ll INF=1e18+7;
const int LIM=1e5+7;
pair<pair<ll,ll>,pair<ll,ll>>T[LIM];
ll odl[LIM], odw[LIM];
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n, m;
cin >> n >> m;
rep(i, m) {
cin >> T[i].nd.st >> T[i].st.st >> T[i].st.nd >> T[i].nd.nd;
odl[i]=INF;
if(T[i].st.st==1) {
odl[i]=min(odl[i], T[i].nd.nd);
}
}
while(true) {
pair<ll,ll>mi={INF, INF};
rep(i, n) if(!odw[i]) mi=min(mi, {odl[i], i});
if(mi.st==INF) break;
ll o=mi.st, p=mi.nd;
odw[p]=1;
rep(i, m) {
if(T[p].st.nd-T[i].st.st+1>=abs(T[p].nd.st-T[i].nd.st)) {
odl[i]=min(odl[i], o+T[i].nd.nd);
}
}
}
ll ans=INF;
rep(i, m) if(T[i].st.nd==n) ans=min(ans, odl[i]);
if(ans==INF) ans=-1;
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |