Submission #258689

#TimeUsernameProblemLanguageResultExecution timeMemory
258689fedoseevtimofeyPinball (JOI14_pinball)C++14
51 / 100
1066 ms2048 KiB
#include <iostream> #include <string> #include <vector> #include <queue> #include <deque> #include <stack> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <cstring> #include <cmath> #include <cstdlib> #include <algorithm> #include <random> #include <iomanip> #include <functional> #include <cassert> using namespace std; typedef long long ll; const ll Inf = 1e18; int main() { ios_base::sync_with_stdio(false); cin.tie(0); #ifdef LOCAL freopen("input.txt", "r", stdin); #endif int n, m; cin >> n >> m; vector <int> a(n), b(n), c(n), d(n); for (int i = 0; i < n; ++i) { cin >> a[i] >> b[i] >> c[i] >> d[i]; } vector <ll> dpL(n, Inf), dpR(n, Inf); for (int i = 0; i < n; ++i) { if (a[i] == 1) { dpL[i] = d[i]; } for (int j = i - 1; j >= 0; --j) { if (a[i] <= c[j] && c[j] <= b[i]) { dpL[i] = min(dpL[i], dpL[j] + d[i]); } } } for (int i = 0; i < n; ++i) { if (b[i] == m) { dpR[i] = d[i]; } for (int j = i - 1; j >= 0; --j) { if (a[i] <= c[j] && c[j] <= b[i]) { dpR[i] = min(dpR[i], dpR[j] + d[i]); } } } ll ans = Inf; for (int i = 0; i < n; ++i) { ll costL = Inf, costR = Inf; for (int j = i - 1; j >= 0; --j) { if (a[i] <= c[j] && c[j] <= b[i]) { costL = min(costL, dpL[j]); costR = min(costR, dpR[j]); } } if (a[i] == 1) costL = 0; if (b[i] == m) costR = 0; ans = min(ans, costL + costR + d[i]); } if (ans != Inf) cout << ans << '\n'; else cout << "-1\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...