Submission #1034745

#TimeUsernameProblemLanguageResultExecution timeMemory
1034745vjudge1Pinball (JOI14_pinball)C++17
51 / 100
3 ms860 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define fi first #define se second #define pb push_back #define ep emplace_back #define lwb lower_bound #define upb upper_bound #define gcd(x, y) __gcd(x, y) #define lcm(x, y) x * y / __gcd(x, y) const int mod = 1e9 + 7; const ll inf = 1e18; const int mxN = 1e5 + 5; const int block = 450; const int base = 311; const int LOG = 19; struct pinball { ll a, b, c, d; } a[mxN]; int m, n; namespace sub3 { bool check() { return m <= 1000; } ll L[mxN], R[mxN]; void solve() { for (int i = 1; i <= m; i++) { L[i] = inf; R[i] = inf; } for (int i = 1; i <= m; i++) { if (a[i].a == 1) { L[i] = a[i].d; } if (a[i].b == n) { R[i] = a[i].d; } for (int j = 1; j < i; j++) { if (a[j].a < a[i].a && a[i].a <= a[j].c && a[j].c <= a[i].b) { L[i] = min(L[i], L[j] + a[i].d); } if (a[j].b > a[i].b && a[i].a <= a[j].c && a[j].c <= a[i].b) { R[i] = min(R[i], R[j] + a[i].d); } } } ll ans = inf; for (int i = 1; i <= m; i++) { ans = min(ans, L[i] + R[i] - a[i].d); } if (ans == inf) { cout << -1; } else { cout << ans; } } } //namespace sub4 { // bool //} int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> m >> n; for (int i = 1; i <= m; i++) { cin >> a[i].a >> a[i].b >> a[i].c >> a[i].d; } if (sub3::check()) return sub3::solve(), 0; } /* */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...