Submission #869866

#TimeUsernameProblemLanguageResultExecution timeMemory
86986612345678Pinball (JOI14_pinball)C++17
51 / 100
3 ms860 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int nx=1e3+5; ll dpl[nx], dpr[nx], n, m, a[nx], b[nx], c[nx], d[nx], ml, mr, res=1e17; int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>m>>n; for (int i=1; i<=m; i++) cin>>a[i]>>b[i]>>c[i]>>d[i]; for (int i=1; i<=m; i++) { dpl[i]=dpr[i]=ml=mr=1e17; if (a[i]==1) dpl[i]=d[i], ml=0; if (b[i]==n) dpr[i]=d[i], mr=0; for (int j=1; j<i; j++) { if (a[i]<=c[j]&&c[j]<=b[i]) { dpl[i]=min(dpl[i], dpl[j]+d[i]); dpr[i]=min(dpr[i], dpr[j]+d[i]); ml=min(ml, dpl[j]); mr=min(mr, dpr[j]); } } res=min(res, ml+mr+d[i]); //cout<<i<<' '<<dpl[i]<<' '<<dpr[i]<<' '<<ml<<' '<<mr<<' '<<res<<'\n'; } cout<<((res==1e17)?-1:res); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...