Submission #674054

#TimeUsernameProblemLanguageResultExecution timeMemory
674054AmirElarbiPinball (JOI14_pinball)C++14
51 / 100
1076 ms3540 KiB
#include <bits/stdc++.h> #define vi vector<int> #define ve vector #define ll long long #define vf vector<float> #define vll vector<pair<ll,ll>> #define ii pair<int,int> #define pll pair<ll,ll> #define vvi vector<vi> #define vii vector<ii> #define gii greater<ii> #define pb push_back #define mp make_pair #define fi first #define se second #define INF 1e18 #define eps 1e-7 #define eps1 1e-2 #define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define MAX_A 2e5+5 using namespace std; int MOD = 1e9+7; const int nax = 1e5+5; const int nax2 = 200+5; typedef complex<int> Point; using cd = complex<double>; const double PI = acos(-1); ll m,n; ll a[nax], b[nax], c[nax], d[nax], dp[nax], dp2[nax]; ll srch2(int j){ if(b[j] == n) return d[j]; if(j == -1) return INF; if(dp2[j] != -1) return dp2[j]; dp2[j] = INF; for (int i = j-1; i >= 0;--i) { if(c[i] <= b[j] && b[i] > b[j]){ dp2[j] = min(dp2[j], srch2(i)+d[j]); } } return dp2[j]; } ll srch(int j){ if(b[j] == n) return d[j]; if(j == m) return INF; if(dp[j] != -1) return dp[j]; dp[j] = INF; dp[j] = min(dp[j], srch2(j)); for (int i = j+1; i < m; ++i) { if(a[i] <= c[j] && b[i] > b[j]){ dp[j] = min(dp[j], srch(i)+d[j]); } } return dp[j]; } int main(){ optimise; cin >> m >> n; for (int i = 0; i < m; ++i) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } c[m] = 1; memset(dp,-1, sizeof dp); memset(dp2,-1, sizeof dp2); ll cur = INF; for (int i = 0; i < m; ++i) { if(a[i] == 1){ cur = min(cur,srch(i)); } } if(cur == INF) cout << -1 << endl; else cout << cur << 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...