Submission #247437

# Submission time Handle Problem Language Result Execution time Memory
247437 2020-07-11T11:33:40 Z receed Pinball (JOI14_pinball) C++14
100 / 100
250 ms 17260 KB
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cassert>
#include <string>
#include <set>
#include <map>
#include <random>
#include <bitset>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using ul = unsigned long long;
using ld = long double;

const int N = 1 << 18;
ll tr[2][N * 2], inf = 1e16, a[N], b[N], c[N], d[N];

void add(int q, int p, ll x) {
    for (int i = N + p; i; i >>= 1)
        tr[q][i] = min(tr[q][i], x);
}

ll getm(int q, int cl, int cr, int v=1, int l=0, int r=N) {
    if (cr <= l || r <= cl)
        return inf;
    if (cl <= l && r <= cr)
        return tr[q][v];
    return min(getm(q, cl, cr, v * 2, l, (l + r) / 2), getm(q, cl, cr, v * 2 + 1, (l + r) / 2, r));
}

ll lb(vector<ll> &a, ll x) {
    return lower_bound(all(a), x) - a.begin();
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll m, n;
    cin >> m >> n;
    vector<ll> li {2, n};
    rep(i, m) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        li.push_back(a[i]);
        li.push_back(b[i] + 1);
    }
    sort(all(li));
    li.resize(unique(all(li)) - li.begin());
    if (li[0] != 1 || li.back() != n + 1) {
        cout << -1;
        return 0;
    }
    rep(i, N * 2)
        rep(j, 2)
            tr[j][i] = inf;
    add(0, 0, 0);
    add(1, li.size() - 2, 0);
    ll ans = inf;
    rep(i, m) {
        a[i] = lb(li, a[i]);
        b[i] = lb(li, b[i] + 1);
        c[i] = lb(li, c[i] + 1) - 1;
        ll m1 = getm(0, a[i], b[i]), m2 = getm(1, a[i], b[i]);
        ans = min(ans, m1 + m2 + d[i]);
        add(0, c[i], m1 + d[i]);
        add(1, c[i], m2 + d[i]);
    }
    if (ans == inf)
        ans = -1;
    cout << ans;
}

# Verdict Execution time Memory Grader output
1 Correct 9 ms 8576 KB Output is correct
2 Correct 9 ms 8576 KB Output is correct
3 Correct 10 ms 8576 KB Output is correct
4 Correct 9 ms 8576 KB Output is correct
5 Correct 9 ms 8576 KB Output is correct
6 Correct 9 ms 8576 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 8 ms 8576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8576 KB Output is correct
2 Correct 9 ms 8576 KB Output is correct
3 Correct 10 ms 8576 KB Output is correct
4 Correct 9 ms 8576 KB Output is correct
5 Correct 9 ms 8576 KB Output is correct
6 Correct 9 ms 8576 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 8 ms 8576 KB Output is correct
9 Correct 9 ms 8576 KB Output is correct
10 Correct 9 ms 8576 KB Output is correct
11 Correct 9 ms 8576 KB Output is correct
12 Correct 9 ms 8576 KB Output is correct
13 Correct 9 ms 8576 KB Output is correct
14 Correct 9 ms 8576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8576 KB Output is correct
2 Correct 9 ms 8576 KB Output is correct
3 Correct 10 ms 8576 KB Output is correct
4 Correct 9 ms 8576 KB Output is correct
5 Correct 9 ms 8576 KB Output is correct
6 Correct 9 ms 8576 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 8 ms 8576 KB Output is correct
9 Correct 9 ms 8576 KB Output is correct
10 Correct 9 ms 8576 KB Output is correct
11 Correct 9 ms 8576 KB Output is correct
12 Correct 9 ms 8576 KB Output is correct
13 Correct 9 ms 8576 KB Output is correct
14 Correct 9 ms 8576 KB Output is correct
15 Correct 9 ms 8576 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 10 ms 8704 KB Output is correct
18 Correct 10 ms 8704 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 10 ms 8704 KB Output is correct
21 Correct 9 ms 8576 KB Output is correct
22 Correct 10 ms 8704 KB Output is correct
23 Correct 10 ms 8704 KB Output is correct
24 Correct 11 ms 8704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8576 KB Output is correct
2 Correct 9 ms 8576 KB Output is correct
3 Correct 10 ms 8576 KB Output is correct
4 Correct 9 ms 8576 KB Output is correct
5 Correct 9 ms 8576 KB Output is correct
6 Correct 9 ms 8576 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 8 ms 8576 KB Output is correct
9 Correct 9 ms 8576 KB Output is correct
10 Correct 9 ms 8576 KB Output is correct
11 Correct 9 ms 8576 KB Output is correct
12 Correct 9 ms 8576 KB Output is correct
13 Correct 9 ms 8576 KB Output is correct
14 Correct 9 ms 8576 KB Output is correct
15 Correct 9 ms 8576 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 10 ms 8704 KB Output is correct
18 Correct 10 ms 8704 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 10 ms 8704 KB Output is correct
21 Correct 9 ms 8576 KB Output is correct
22 Correct 10 ms 8704 KB Output is correct
23 Correct 10 ms 8704 KB Output is correct
24 Correct 11 ms 8704 KB Output is correct
25 Correct 29 ms 9472 KB Output is correct
26 Correct 56 ms 10748 KB Output is correct
27 Correct 149 ms 14572 KB Output is correct
28 Correct 151 ms 17132 KB Output is correct
29 Correct 107 ms 13036 KB Output is correct
30 Correct 178 ms 17256 KB Output is correct
31 Correct 247 ms 17256 KB Output is correct
32 Correct 212 ms 17260 KB Output is correct
33 Correct 38 ms 10364 KB Output is correct
34 Correct 115 ms 12908 KB Output is correct
35 Correct 150 ms 17256 KB Output is correct
36 Correct 250 ms 17256 KB Output is correct
37 Correct 202 ms 17256 KB Output is correct
38 Correct 201 ms 17256 KB Output is correct