Submission #668925

# Submission time Handle Problem Language Result Execution time Memory
668925 2022-12-05T08:10:56 Z stevancv Pinball (JOI14_pinball) C++14
0 / 100
6 ms 9716 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 1e5 + 2;
const ll linf = 1e18;
struct Segtree {
    ll st[12 * N];
    void Reset() {
        for (int i = 1; i < 12 * N; i++) st[i] = linf;
    }
    void Update(int node, int l, int r, int x, ll y) {
        smin(st[node], y);
        if (l == r) return;
        int mid = l + r >> 1;
        if (x <= mid) Update(2 * node, l, mid, x, y);
        else Update(2 * node + 1, mid + 1, r, x, y);
    }
    ll Get(int node, int l, int r, int ql, int qr) {
        if (r < ql || qr < l) return linf;
        if (ql <= l && r <= qr) return st[node];
        int mid = l + r >> 1;
        return min(Get(2 * node, l, mid, ql, qr), Get(2 * node + 1, mid + 1, r, ql, qr));
    }
}st;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(n), c(n), d(n);
    vector<int> all;
    all.push_back(1); all.push_back(m);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        all.push_back(a[i]);
        all.push_back(b[i]);
        all.push_back(c[i]);
    }
    sort(all.begin(), all.end());
    all.erase(unique(all.begin(), all.end()), all.end());
    int sz = all.size();
    map<int, int> mp;
    for (int i = 0; i < all.size(); i++) mp[all[i]] = i;
    for (int i = 0; i < n; i++) {
        a[i] = mp[a[i]];
        b[i] = mp[b[i]];
        c[i] = mp[c[i]];
    }
    vector<ll> dp1(n, linf), dp2(n, linf);
    st.Reset();
    for (int i = 0; i < n; i++) {
        if (a[i] == 0) smin(dp1[i], (ll)d[i]);
        else smin(dp1[i], st.Get(1, 0, sz - 1, a[i], b[i]) + d[i]);
        st.Update(1, 0, sz - 1, c[i], dp1[i]);
    }
    st.Reset();
    for (int i = 0; i < n; i++) {
        if (b[i] == sz - 1) smin(dp2[i], (ll)d[i]);
        else smin(dp2[i], st.Get(1, 0, sz - 1, a[i], b[i]) + d[i]);
        st.Update(1, 0, sz - 1, c[i], dp2[i]);
    }
    ll ans = linf;
    for (int i = 0; i < n; i++) smin(ans, dp1[i] + dp2[i] - d[i]);
    cout << ans << en;
    return 0;
}

Compilation message

pinball.cpp: In member function 'void Segtree::Update(int, int, int, int, long long int)':
pinball.cpp:19:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   19 |         int mid = l + r >> 1;
      |                   ~~^~~
pinball.cpp: In member function 'long long int Segtree::Get(int, int, int, int, int)':
pinball.cpp:26:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   26 |         int mid = l + r >> 1;
      |                   ~~^~~
pinball.cpp: In function 'int main()':
pinball.cpp:49:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |     for (int i = 0; i < all.size(); i++) mp[all[i]] = i;
      |                     ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Correct 6 ms 9716 KB Output is correct
5 Correct 6 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Incorrect 5 ms 9684 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Correct 6 ms 9716 KB Output is correct
5 Correct 6 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Incorrect 5 ms 9684 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Correct 6 ms 9716 KB Output is correct
5 Correct 6 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Incorrect 5 ms 9684 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Correct 6 ms 9716 KB Output is correct
5 Correct 6 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Incorrect 5 ms 9684 KB Output isn't correct
8 Halted 0 ms 0 KB -