Submission #1033542

#TimeUsernameProblemLanguageResultExecution timeMemory
1033542DucNguyen2007Pinball (JOI14_pinball)C++14
51 / 100
1008 ms2392 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pii pair<int,int> #define pll pair<ll,ll> #define fi first #define se second const int maxN=1e5+5; const ll inf=2e18; ll n,m,a[maxN+1],b[maxN+1],c[maxN+1],d[maxN+1],dp[maxN+1],f[maxN+1]; bool intersect(ll l,ll r,ll mid) { return (l<=mid&&mid<=r); } int main() { //freopen("","r",stdin); //freopen("","w",stdout); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>m>>n; for(int i=1;i<=m;i++) { cin>>a[i]>>b[i]>>c[i]>>d[i]; dp[i]=inf; f[i]=inf; } dp[0]=0; f[0]=0; for(int i=1;i<=m;i++) { for(int j=0;j<i;j++) { if(!j) { if(intersect(a[i],b[i],1)) { dp[i]=min(dp[i],dp[j]+d[i]); } if(intersect(a[i],b[i],n)) { f[i]=min(f[i],f[j]+d[i]); } } else { if(intersect(a[i],b[i],c[j])) { dp[i]=min(dp[i],dp[j]+d[i]); f[i]=min(f[i],f[j]+d[i]); } } } //cout<<i<<" "<<dp[i]<<" "<<f[i]<<'\n'; } ll ans=inf; for(int i=1;i<=m;i++) { ans=min(ans,dp[i]+f[i]-d[i]); } if(ans==inf) { cout<<-1; } else cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...