Submission #331988

#TimeUsernameProblemLanguageResultExecution timeMemory
331988YJUTreatment Project (JOI20_treatment)C++14
35 / 100
1121 ms524288 KiB
#include<bits/stdc++.h> #pragma GCC optimize("unroll-loops,no-stack-protector") using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> pll; const ll MOD=1e9+7; const ll MOD2=998244353; const ll N=1e5+5; const ll K=350; const ld pi=acos(-1); const ll INF=(1LL<<60); #define SQ(i) ((i)*(i)) #define REP(i,n) for(ll i=0;i<n;i++) #define REP1(i,n) for(ll i=1;i<=n;i++) #define pb push_back #define mp make_pair #define X first #define Y second #define setp setprecision #define lwb lower_bound #define SZ(_a) (ll)_a.size() ll n,m,dis[N],C[N],T[N],L[N],R[N],ans=INF; vector<ll> v[N]; priority_queue<pll,vector<pll>,greater<pll> > pq; int main(){ ios_base::sync_with_stdio(0);cin.tie(0); cin>>n>>m; REP1(i,m){ cin>>T[i]>>L[i]>>R[i]>>C[i]; } REP1(i,m)REP1(j,m){ if(T[i]>=T[j]&&R[i]-T[i]>=L[j]-T[j]-1){ v[i].pb(j); }else if(T[i]<T[j]&&R[i]+T[i]>=L[j]+T[j]-1){ v[i].pb(j); } } REP1(i,m){ if(L[i]==1)pq.push(mp(dis[i]=C[i],i)); else dis[i]=INF; } while(SZ(pq)){ ll x=pq.top().Y,y=pq.top().X;pq.pop(); if(y>dis[x])continue; //cout<<dis[x]<<" "<<x<<"\n"; for(auto i:v[x]){ if(dis[i]>y+C[i]){ //cout<<x<<"->"<<i<<"\n"; pq.push(mp(dis[i]=y+C[i],i)); } } } REP1(i,m)if(R[i]==n)ans=min(ans,dis[i]); cout<<(ans==INF?-1:ans)<<"\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...