Submission #133275

# Submission time Handle Problem Language Result Execution time Memory
133275 2019-07-20T10:29:20 Z egorlifar Pinball (JOI14_pinball) C++17
100 / 100
214 ms 23656 KB
/*
ЗАПУСКАЕМ
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░
 */
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>

using namespace std;
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define left left224
#define right right224
#define next next224
#define rank rank224
#define prev prev224
#define y1 y1224
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define files(FILENAME) read(FILENAME), write(FILENAME)
#define pb push_back
#define mp make_pair
const string FILENAME = "input";
const int MAXN = 300228;


int m, n;
int a[MAXN], b[MAXN], c[MAXN], d[MAXN];

struct rmq
{
    vector<long long> d;
    int ss = 1;
    void init(int l) {
        while (ss < l) {
            ss <<= 1;
        }
        d.resize(2 * ss);
        for (int i = 0; i < 2 * ss; i++) {
            d[i] = 1e18;
        }
    }
    void upd(int i, long long val) {
        i += ss;
        chkmin(d[i], val);
        while (i >> 1 > 0) {
            i >>= 1;
            d[i] = min(d[i * 2], d[i * 2 + 1]);
        }
    }
    long long getmin(int l, int r) {
        long long res = 1e18;
        l += ss;
        r += ss;
        while (l <= r) {
            if (l & 1) {
                chkmin(res, d[l]);
                l++;
            }
            if (!(r & 1)) {
                chkmin(res, d[r]);
                r--;
            }
            l >>= 1;
            r >>= 1;
        }
        return res;
    }
};


rmq l, r;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //read(FILENAME);
    cin >> m >> n;
    vector<int> vx;
    vx.pb(1);
    vx.pb(n);
    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        vx.pb(a[i]);
        vx.pb(b[i]);
        vx.pb(c[i]);
    }
    sort(all(vx));
    vx.resize(distance(vx.begin(), unique(all(vx))));
    for (int i = 0; i < m; i++) {
        a[i] = lower_bound(all(vx), a[i]) - vx.begin();
         b[i] = lower_bound(all(vx), b[i]) - vx.begin();
          c[i] = lower_bound(all(vx), c[i]) - vx.begin();
    }
    l.init(sz(vx));
    r.init(sz(vx));
    l.upd(0, 0);
    r.upd(sz(vx) - 1, 0);
    long long ans = 4e18;
    for (int i = 0; i < m; i++) {
        long long f = l.getmin(a[i], b[i]);
        long long f1 = r.getmin(a[i], b[i]);
        chkmin(ans, f + f1 + d[i]);
        l.upd(c[i], f + d[i]);
        r.upd(c[i], f1 + d[i]);
    }
    if (ans > 1000000000000000000LL) {
        ans = -1;
    }
    cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 380 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 380 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Correct 3 ms 504 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 3 ms 504 KB Output is correct
20 Correct 3 ms 504 KB Output is correct
21 Correct 3 ms 504 KB Output is correct
22 Correct 3 ms 636 KB Output is correct
23 Correct 3 ms 632 KB Output is correct
24 Correct 3 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 380 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Correct 3 ms 504 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 3 ms 504 KB Output is correct
20 Correct 3 ms 504 KB Output is correct
21 Correct 3 ms 504 KB Output is correct
22 Correct 3 ms 636 KB Output is correct
23 Correct 3 ms 632 KB Output is correct
24 Correct 3 ms 504 KB Output is correct
25 Correct 17 ms 2040 KB Output is correct
26 Correct 43 ms 4084 KB Output is correct
27 Correct 124 ms 9072 KB Output is correct
28 Correct 125 ms 7536 KB Output is correct
29 Correct 91 ms 8148 KB Output is correct
30 Correct 150 ms 8036 KB Output is correct
31 Correct 198 ms 15336 KB Output is correct
32 Correct 197 ms 11264 KB Output is correct
33 Correct 26 ms 3832 KB Output is correct
34 Correct 90 ms 12016 KB Output is correct
35 Correct 140 ms 23656 KB Output is correct
36 Correct 214 ms 23644 KB Output is correct
37 Correct 182 ms 23628 KB Output is correct
38 Correct 208 ms 23644 KB Output is correct