Submission #755990

# Submission time Handle Problem Language Result Execution time Memory
755990 2023-06-10T19:23:32 Z MohamedFaresNebili Pinball (JOI14_pinball) C++14
100 / 100
249 ms 20660 KB
#include <bits/stdc++.h>

        using namespace std;
        using ll = long long;

        #define int ll

        int M, N, st[1200005];
        array<int, 4> A[100005];
        void update(int v, int l, int r, int p, int val) {
            if(l == r) {
                st[v] = min(st[v], val);
                return;
            }
            int md = (l + r) / 2;
            if(p <= md) update(v * 2, l, md, p, val);
            else update(v * 2 + 1, md + 1, r, p, val);
            st[v] = min(st[v * 2], st[v * 2 + 1]);
        }
        int query(int v, int l, int r, int lo, int hi) {
            if(l > hi || r < lo) return 1e18;
            if(l >= lo && r <= hi) return st[v];
            return min(query(v * 2, l, (l + r) / 2, lo, hi),
                       query(v * 2 + 1, (l + r) / 2 + 1, r, lo, hi));
        }

        int32_t main() {
            ios_base::sync_with_stdio(0);
            cin.tie(0); cout.tie(0);
            cin >> M >> N;
            vector<int> comp; comp.push_back(1); comp.push_back(N);
            for(int l = 0; l < M; l++) {
                cin >> A[l][0] >> A[l][1] >> A[l][2] >> A[l][3];
                comp.push_back(A[l][0]);
                comp.push_back(A[l][1]);
                comp.push_back(A[l][2]);
            }
            sort(comp.begin(), comp.end());
            comp.erase(unique(comp.begin(), comp.end()), comp.end());
            for(int l = 0; l < M; l++) {
                A[l][0] = lower_bound(comp.begin(), comp.end(), A[l][0]) - comp.begin();
                A[l][1] = lower_bound(comp.begin(), comp.end(), A[l][1]) - comp.begin();
                A[l][2] = lower_bound(comp.begin(), comp.end(), A[l][2]) - comp.begin();
            }
            for(int l = 0; l < 1200005; l++) st[l] = 1e18;
            vector<int> L(M, 1e18);
            vector<int> R(M, 1e18);
            for(int l = 0; l < M; l++) {
                if(A[l][0] == 0)
                    L[l] = A[l][3];
                else L[l] = min(L[l], A[l][3] + query(1, 0, comp.size() - 1, A[l][0], A[l][1]));
                update(1, 0, comp.size() - 1, A[l][2], L[l]);
            }
            for(int l = 0; l < 1200005; l++) st[l] = 1e18;

            for(int l = 0; l < M; l++) {
                if(A[l][1] == comp.size() - 1)
                    R[l] = A[l][3];
                else R[l] = A[l][3] + query(1, 0, comp.size() - 1, A[l][0], A[l][1]);
                update(1, 0, comp.size() - 1, A[l][2], R[l]);
            }
            int res = 1e18;
            for(int l = 0; l < M; l++)
                res = min(res, L[l] + R[l] - A[l][3]);
            cout << (res == 1e18 ? -1 : res) << "\n";
        }

Compilation message

pinball.cpp: In function 'int32_t main()':
pinball.cpp:57:28: warning: comparison of integer expressions of different signedness: 'std::array<long long int, 4>::value_type' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |                 if(A[l][1] == comp.size() - 1)
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 6 ms 9684 KB Output is correct
5 Correct 6 ms 9684 KB Output is correct
6 Correct 7 ms 9684 KB Output is correct
7 Correct 6 ms 9644 KB Output is correct
8 Correct 6 ms 9640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 6 ms 9684 KB Output is correct
5 Correct 6 ms 9684 KB Output is correct
6 Correct 7 ms 9684 KB Output is correct
7 Correct 6 ms 9644 KB Output is correct
8 Correct 6 ms 9640 KB Output is correct
9 Correct 7 ms 9684 KB Output is correct
10 Correct 6 ms 9684 KB Output is correct
11 Correct 6 ms 9684 KB Output is correct
12 Correct 7 ms 9684 KB Output is correct
13 Correct 6 ms 9684 KB Output is correct
14 Correct 6 ms 9684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 6 ms 9684 KB Output is correct
5 Correct 6 ms 9684 KB Output is correct
6 Correct 7 ms 9684 KB Output is correct
7 Correct 6 ms 9644 KB Output is correct
8 Correct 6 ms 9640 KB Output is correct
9 Correct 7 ms 9684 KB Output is correct
10 Correct 6 ms 9684 KB Output is correct
11 Correct 6 ms 9684 KB Output is correct
12 Correct 7 ms 9684 KB Output is correct
13 Correct 6 ms 9684 KB Output is correct
14 Correct 6 ms 9684 KB Output is correct
15 Correct 6 ms 9684 KB Output is correct
16 Correct 6 ms 9684 KB Output is correct
17 Correct 7 ms 9812 KB Output is correct
18 Correct 7 ms 9812 KB Output is correct
19 Correct 7 ms 9812 KB Output is correct
20 Correct 7 ms 9752 KB Output is correct
21 Correct 6 ms 9684 KB Output is correct
22 Correct 8 ms 9812 KB Output is correct
23 Correct 7 ms 9812 KB Output is correct
24 Correct 7 ms 9812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 6 ms 9684 KB Output is correct
5 Correct 6 ms 9684 KB Output is correct
6 Correct 7 ms 9684 KB Output is correct
7 Correct 6 ms 9644 KB Output is correct
8 Correct 6 ms 9640 KB Output is correct
9 Correct 7 ms 9684 KB Output is correct
10 Correct 6 ms 9684 KB Output is correct
11 Correct 6 ms 9684 KB Output is correct
12 Correct 7 ms 9684 KB Output is correct
13 Correct 6 ms 9684 KB Output is correct
14 Correct 6 ms 9684 KB Output is correct
15 Correct 6 ms 9684 KB Output is correct
16 Correct 6 ms 9684 KB Output is correct
17 Correct 7 ms 9812 KB Output is correct
18 Correct 7 ms 9812 KB Output is correct
19 Correct 7 ms 9812 KB Output is correct
20 Correct 7 ms 9752 KB Output is correct
21 Correct 6 ms 9684 KB Output is correct
22 Correct 8 ms 9812 KB Output is correct
23 Correct 7 ms 9812 KB Output is correct
24 Correct 7 ms 9812 KB Output is correct
25 Correct 25 ms 10456 KB Output is correct
26 Correct 53 ms 11380 KB Output is correct
27 Correct 150 ms 17140 KB Output is correct
28 Correct 141 ms 20468 KB Output is correct
29 Correct 106 ms 15156 KB Output is correct
30 Correct 178 ms 20548 KB Output is correct
31 Correct 249 ms 20528 KB Output is correct
32 Correct 199 ms 20660 KB Output is correct
33 Correct 32 ms 11724 KB Output is correct
34 Correct 102 ms 15100 KB Output is correct
35 Correct 144 ms 20596 KB Output is correct
36 Correct 226 ms 20536 KB Output is correct
37 Correct 202 ms 20568 KB Output is correct
38 Correct 209 ms 20532 KB Output is correct