This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
const int mxn=1e5+5;
const ll inf=1e18;
int t[mxn],l[mxn],r[mxn],c[mxn];
vector<pair<int,int>> adj[mxn];
vector<ll> dij(int n){
vector<ll> d(n,inf);
d[0]=0;
priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> pq;
pq.push({0,0});
while(!pq.empty()){
auto tmp=pq.top();
pq.pop();
int v=tmp.s;
if(tmp.f!=d[v]) continue;
for(auto u:adj[v]){
if(d[v]+u.s<d[u.f]){
d[u.f]=d[v]+u.s;
pq.push({d[u.f],u.f});
}
}
}
return d;
}
int main() {_
int n,m;
cin>>n>>m;
for(int i=1;i<=m;i++){
cin>>t[i]>>l[i]>>r[i]>>c[i];
}
for(int i=1;i<=m;i++){
for(int j=1;j<=m;j++){
if(i==j) continue;
int x=i,y=j;
if(t[x]<=t[y]){
if(r[x]+t[x]>=l[y]+t[y]-1) adj[x].push_back({y,c[y]});
}
else{
if(r[x]-t[x]>=l[y]-t[y]-1) adj[x].push_back({y,c[y]});
}
}
}
for(int i=1;i<=m;i++){
if(l[i]==1) adj[0].push_back({i,c[i]});
if(r[i]==n) adj[i].push_back({m+1,0});
}
vector<ll> d=dij(m+2);
cout<<(d[m+1]==inf?-1:d[m+1])<<'\n';
return 0;
}
//maybe its multiset not set
//yeeorz
//laborz
Compilation message (stderr)
treatment.cpp: In function 'void setIO(std::string)':
treatment.cpp:15:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | freopen((s + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
treatment.cpp:16:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
16 | freopen((s + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |