Submission #292557

# Submission time Handle Problem Language Result Execution time Memory
292557 2020-09-07T09:22:32 Z davooddkareshki Pinball (JOI14_pinball) C++17
100 / 100
807 ms 47332 KB
// be name khoda
#include<bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define int long long
#define mpr make_pair 
typedef long long ll;
#pragma GCC optimize("Ofast")

const int maxn = 3e5+10;
const int mod = 1e9+7;
const ll inf = 1e18+10;

int n, m, k;
struct segment
{
    ll seg[maxn<<2];

    segment()
    {
        fill(seg, seg+maxn*4, inf);
    }

    void modify(int pos, int val, int v = 1, int tl = 1, int tr = n)
    {
        seg[v] = min(seg[v], val);
        if(tl == tr) return;
        
        int tm = (tl + tr) >> 1;
        if(pos <= tm) modify(pos, val, v<<1, tl, tm);
        else modify(pos, val, v<<1|1, tm+1, tr);
    }

    int qu(int l, int r, int v = 1, int tl = 1, int tr = n)
    {
        if(l > r) return inf;
        if(tl == l && tr == r) return seg[v];

        int tm = (tl + tr) >> 1;
        return min(qu(l, min(tm,r), v<<1, tl, tm),
                    qu(max(tm+1,l), r, v<<1|1, tm+1, tr));
    }   
} seg1, seg2;

int a[maxn], b[maxn], c[maxn], d[maxn];

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    cin>> m >> n;
    if(n == 1) return cout<< 0, 0;

    map<int,int> mp;
    vector<int> ve;
    for(int i = 1; i <= m; i++)
    {
        cin>> a[i] >> b[i] >> c[i] >> d[i];
        ve.push_back(a[i]);
        ve.push_back(b[i]);
        ve.push_back(c[i]);
    }
    sort(ve.begin(), ve.end());
    if(ve.back() < n) return cout<< -1, 0;
    if(ve[0] > 1) return cout<< -1, 0;

    int lst = 0; for(auto x : ve) if(!mp.count(x)) mp.insert({x,++lst});
    n = lst;

    seg1.modify(1,0); seg2.modify(n,0);
    ll ans = inf;
    for(int i = 1; i <= m; i++)
    {
        a[i] = mp[a[i]];
        b[i] = mp[b[i]];
        c[i] = mp[c[i]];

        int val1 = seg1.qu(a[i],b[i]);
        seg1.modify(c[i], val1+d[i]);
        
        int val2 = seg2.qu(a[i],b[i]);
        seg2.modify(c[i], val2+d[i]);

        ans = min(ans, seg1.qu(a[i],b[i]) + seg2.qu(a[i],b[i]) + d[i]);
    }

    if(ans < inf) cout<< ans;
    else cout<< -1;
}



# Verdict Execution time Memory Grader output
1 Correct 11 ms 19200 KB Output is correct
2 Correct 12 ms 19200 KB Output is correct
3 Correct 11 ms 19200 KB Output is correct
4 Correct 11 ms 19200 KB Output is correct
5 Correct 11 ms 19200 KB Output is correct
6 Correct 11 ms 19200 KB Output is correct
7 Correct 11 ms 19200 KB Output is correct
8 Correct 11 ms 19196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 19200 KB Output is correct
2 Correct 12 ms 19200 KB Output is correct
3 Correct 11 ms 19200 KB Output is correct
4 Correct 11 ms 19200 KB Output is correct
5 Correct 11 ms 19200 KB Output is correct
6 Correct 11 ms 19200 KB Output is correct
7 Correct 11 ms 19200 KB Output is correct
8 Correct 11 ms 19196 KB Output is correct
9 Correct 11 ms 19200 KB Output is correct
10 Correct 11 ms 19200 KB Output is correct
11 Correct 11 ms 19200 KB Output is correct
12 Correct 12 ms 19200 KB Output is correct
13 Correct 12 ms 19200 KB Output is correct
14 Correct 12 ms 19192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 19200 KB Output is correct
2 Correct 12 ms 19200 KB Output is correct
3 Correct 11 ms 19200 KB Output is correct
4 Correct 11 ms 19200 KB Output is correct
5 Correct 11 ms 19200 KB Output is correct
6 Correct 11 ms 19200 KB Output is correct
7 Correct 11 ms 19200 KB Output is correct
8 Correct 11 ms 19196 KB Output is correct
9 Correct 11 ms 19200 KB Output is correct
10 Correct 11 ms 19200 KB Output is correct
11 Correct 11 ms 19200 KB Output is correct
12 Correct 12 ms 19200 KB Output is correct
13 Correct 12 ms 19200 KB Output is correct
14 Correct 12 ms 19192 KB Output is correct
15 Correct 11 ms 19200 KB Output is correct
16 Correct 11 ms 19200 KB Output is correct
17 Correct 13 ms 19320 KB Output is correct
18 Correct 12 ms 19328 KB Output is correct
19 Correct 11 ms 19328 KB Output is correct
20 Correct 13 ms 19328 KB Output is correct
21 Correct 12 ms 19328 KB Output is correct
22 Correct 14 ms 19456 KB Output is correct
23 Correct 13 ms 19456 KB Output is correct
24 Correct 13 ms 19456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 19200 KB Output is correct
2 Correct 12 ms 19200 KB Output is correct
3 Correct 11 ms 19200 KB Output is correct
4 Correct 11 ms 19200 KB Output is correct
5 Correct 11 ms 19200 KB Output is correct
6 Correct 11 ms 19200 KB Output is correct
7 Correct 11 ms 19200 KB Output is correct
8 Correct 11 ms 19196 KB Output is correct
9 Correct 11 ms 19200 KB Output is correct
10 Correct 11 ms 19200 KB Output is correct
11 Correct 11 ms 19200 KB Output is correct
12 Correct 12 ms 19200 KB Output is correct
13 Correct 12 ms 19200 KB Output is correct
14 Correct 12 ms 19192 KB Output is correct
15 Correct 11 ms 19200 KB Output is correct
16 Correct 11 ms 19200 KB Output is correct
17 Correct 13 ms 19320 KB Output is correct
18 Correct 12 ms 19328 KB Output is correct
19 Correct 11 ms 19328 KB Output is correct
20 Correct 13 ms 19328 KB Output is correct
21 Correct 12 ms 19328 KB Output is correct
22 Correct 14 ms 19456 KB Output is correct
23 Correct 13 ms 19456 KB Output is correct
24 Correct 13 ms 19456 KB Output is correct
25 Correct 47 ms 21120 KB Output is correct
26 Correct 139 ms 24944 KB Output is correct
27 Correct 431 ms 31848 KB Output is correct
28 Correct 235 ms 29804 KB Output is correct
29 Correct 308 ms 29548 KB Output is correct
30 Correct 335 ms 29676 KB Output is correct
31 Correct 701 ms 39012 KB Output is correct
32 Correct 623 ms 36064 KB Output is correct
33 Correct 81 ms 24564 KB Output is correct
34 Correct 332 ms 33260 KB Output is correct
35 Correct 382 ms 47328 KB Output is correct
36 Correct 807 ms 47332 KB Output is correct
37 Correct 635 ms 47328 KB Output is correct
38 Correct 586 ms 47328 KB Output is correct