Submission #65850

#TimeUsernameProblemLanguageResultExecution timeMemory
65850realityPinball (JOI14_pinball)C++17
29 / 100
1075 ms5376 KiB
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class P , class Q > ostream& operator<<(ostream& stream, pair < P , Q > v){ stream << "(" << v.fi << ',' << v.se << ")"; return stream;}
template < class T > ostream& operator<<(ostream& stream, const vector<T> v){ stream << "[ "; for (int i=0; i<(int)v.size(); i++) stream << v[i] << " "; stream << "]"; return stream;}
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
const int N = 1e6 + 5;
int a[N];
int b[N];
int c[N];
int d[N];
int dp[4096][4096];
int main(void) {
    int n,m;
    cin>>n>>m;
    vi w;
    w.pb(1);
    w.pb(m);
    for (int i = n;i > 0;--i) {
        cin>>a[i]>>b[i]>>c[i]>>d[i];
        w.pb(a[i]);
        w.pb(b[i]);
        w.pb(c[i]);
    }
    sort(all(w));
    w.resize(unique(all(w)) - w.begin());
    m = w.size();
    for (int i = 1;i <= n;++i) {
        a[i] = lower_bound(all(w),a[i]) - w.begin() + 1;
        b[i] = lower_bound(all(w),b[i]) - w.begin() + 1;
        c[i] = lower_bound(all(w),c[i]) - w.begin() + 1;
    }
    map < pii , ll > M;
    for (int i = 1;i <= n;++i) {
        auto it = M.lower_bound(mp(c[i],-c[i]));
        vector < vector < ll > > upd;
        upd.pb({b[i],-a[i],d[i]});
        while (it != M.end()) {
            if (-it->fi.se <= c[i] && c[i] <= it->fi.fi) {
                int nl = min(-it->fi.se,a[i]);
                int nr = max(it->fi.fi,b[i]);
                upd.pb({nr,-nl,it->se + d[i]});
            }
            ++it;
        }
        for (auto it : upd) {
            if (!M.count(mp(it[0],it[1])))
                M[mp(it[0],it[1])] = it[2];
            smin(M[mp(it[0],it[1])],it[2]);
        }
    }
    if (!M.count(mp(m,-1)))
        puts("-1");
    else
        cout << M[mp(m,-1)] << '\n';
    return 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...