Submission #423749

#TimeUsernameProblemLanguageResultExecution timeMemory
423749errorgornTreatment Project (JOI20_treatment)C++17
0 / 100
1413 ms3968 KiB
#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]; 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}); } sort(all(v),[](E i,E j){ if (i.l==1) return true; if (j.l==1) return false; return i.l-i.t < j.l-j.t; }); //for (auto &it:v) cout<<it.l<<" "<<it.r<<" "<<it.t<<endl; memset(memo,63,sizeof(memo)); ll ans=1e18; rep(x,0,k){ if (v[x].l==1) memo[x]=0; memo[x]+=v[x].c; rep(y,x+1,k){ if (v[x].t<=v[y].t && v[x].r-(v[y].t-v[x].t)>=v[y].l) memo[y]=min(memo[y],memo[x]); if (v[y].t<v[x].t && v[y].l+(v[x].t-v[y].t)<=v[x].r) memo[y]=min(memo[y],memo[x]); } if (v[x].r==n+1) ans=min(ans,memo[x]); } if (ans==1e18) cout<<"-1"<<endl; else cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...