Submission #859350

# Submission time Handle Problem Language Result Execution time Memory
859350 2023-10-10T04:36:56 Z vjudge1 Pinball (JOI14_pinball) C++17
100 / 100
154 ms 14384 KB
#include <cstdio>
#include <cstring>
#include <cassert>
#include <string>
#include <deque>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <iostream>
#include <utility>
using namespace std;
using ll=long long;

#define N 200005
#define ALL(x) x.begin(), x.end()

int m, n;
struct pinball { ll a, b, c, d; } a[N];

int compress()
{
    vector<ll> crd = {1,n};
    for (int i = 1; i <= m; ++i) crd.push_back(a[i].a), crd.push_back(a[i].b), crd.push_back(a[i].c);
    sort(ALL(crd));
    crd.erase(unique(ALL(crd)), crd.end());
    for (int i = 1; i <= m; ++i) a[i].a = lower_bound(ALL(crd), a[i].a) - crd.begin(),
        a[i].b = lower_bound(ALL(crd), a[i].b) - crd.begin(),
        a[i].c = lower_bound(ALL(crd), a[i].c) - crd.begin();
    return crd.size();
}

struct min_segtree
{
    vector<ll> t;
    min_segtree(int n) : t(n<<1, 1e18) {};
    ll qry(int l, int r)
    {
        ll z = 1e18;
        for (l += n, r += n + 1; l < r; l/=2,r/=2)
        {
            if(l&1)z=min(z,t[l++]);
            if(r&1)z=min(t[--r],z);
        }
        return z;
    }
    void set(int p, ll k) { for (p+=n,t[p]=min(t[p],k);p/=2;)t[p]=min(t[p*2], t[p*2+1]); }
};

int main()
{
    cin.tie(0)->sync_with_stdio(0);
    cin >> m >> n;
    for (int i = 1; i <= m; ++i) cin >> a[i].a >> a[i].b >> a[i].c >> a[i].d;
    n = compress();

    min_segtree tl(n), tr(n);

    ll z = 1e18;

    tl.set(0, 0);
    tr.set(n-1, 0);

    for (int i = 1; i <= m; ++i)
    {
        z = min(z, tl.qry(a[i].a, a[i].b) + tr.qry(a[i].a, a[i].b) + a[i].d);
        tl.set(a[i].c, tl.qry(a[i].a, a[i].b) + a[i].d);
        tr.set(a[i].c, tr.qry(a[i].a, a[i].b) + a[i].d);
    }

    cout << (z < 1e18? z:-1);

    return 0;
}


# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 12 ms 3324 KB Output is correct
26 Correct 33 ms 4236 KB Output is correct
27 Correct 97 ms 5660 KB Output is correct
28 Correct 91 ms 10744 KB Output is correct
29 Correct 69 ms 5536 KB Output is correct
30 Correct 116 ms 10444 KB Output is correct
31 Correct 145 ms 9944 KB Output is correct
32 Correct 145 ms 9960 KB Output is correct
33 Correct 17 ms 4608 KB Output is correct
34 Correct 63 ms 7476 KB Output is correct
35 Correct 74 ms 14244 KB Output is correct
36 Correct 154 ms 14108 KB Output is correct
37 Correct 110 ms 14228 KB Output is correct
38 Correct 104 ms 14384 KB Output is correct