# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
430300 | Nicholas_Patrick | Treatment Project (JOI20_treatment) | C++17 | 3067 ms | 2620 KiB |
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 <cstdio>
#include <queue>
using namespace std;
template <typename T>
using eueuq_ytiroirp = priority_queue<T, vector<T>, greater<T>>;
struct node{
int l, r, t, c;
// node(int l, int r, int t, int c):l(l-1), r(r), t(t), c(c){}
bool connect(node rhs)const{
return t<rhs.t?
rhs.l<=r-rhs.t+t:
rhs.l<=r-t+rhs.t;
}
};
int main(){
int n, m;
scanf("%d%d", &n, &m);
long long ans=1000000000000000;
vector<node> nodes(m);
for(auto& i : nodes)
scanf("%d%d%d%d", &i.t, &i.l, &i.r, &i.c), i.l--;
vector<long long> dist(m, ans);
vector<bool> explored(m, false);
for(int i=0; i<m; i++){
if(nodes[i].l==0)
dist[i]=nodes[i].c;
}
for(int i=0; i<m; i++){
int from=-1;
for(int j=0; j<m; j++){
if(explored[j])
continue;
if(from==-1 or dist[from]>dist[j])
from=j;
}
explored[from]=true;
for(int j=0; j<m; j++){
if(explored[j])
continue;
if(nodes[from].connect(nodes[j]))
dist[j]=min(dist[j], dist[from]+nodes[j].c);
}
}
for(int i=0; i<m; i++){
if(nodes[i].r==n)
ans=min(ans, dist[i]);
}
if(ans==1000000000000000)
ans=-1;
printf("%lld\n", ans);
}
Compilation message (stderr)
# | 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... |