Submission #938340

# Submission time Handle Problem Language Result Execution time Memory
938340 2024-03-05T04:55:46 Z WendidIask0303 Building Bridges (CEOI17_building) C++17
Compilation error
0 ms 0 KB
#include <iostream>
#include <set>

using namespace std;
 
struct Line {
    mutable long long k, m, p;
    bool operator<(const Line& o) const {
        return k < o.k; 
    }
    bool operator<(long long x) const {
        return p < x; 
    }
};
 
struct LineContainer : multiset<Line, less<>> {
    // (for doubles, use inf = 1/.0, div(a,b) = a/b)
    static const long long inf = LLONG_MAX;
    long long div(long long a, long long b){
        return a/b-((a^b) < 0 && a%b);
    }
    bool isect(iterator x, iterator y) {
        if (y == end()) return x->p = inf, 0;
        if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
        else x->p = div(y->m-x->m, x->k-y->k);
        return x->p >= y->p;
    }
    void add(long long k, long long m) {
        auto z = insert({k, m, 0}), y = z++, x = y;
        while (isect(y, z)) z = erase(z);
        if (x != begin() && isect(--x, y)) isect(x, y = erase(y));
        while ((y = x) != begin() && (--x)->p >= y->p){
            isect(x, erase(y));
        }
    }
    long long query(long long x) {
        auto l = *lower_bound(x);
        return l.k * x + l.m;
    }
};
 
long long h[100001];
long long w[100001];
long long dp[100001];
 
int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> h[i];
    }
    for (int i = 1; i <= n; ++i) {
        cin >> w[i];
        w[i] += w[i-1];
    }
    LineContainer hull;
    hull.add(h[1]*2, -1*h[1]*h[1]+w[1]);
    for (int i=2; i<=n; ++i) {
        dp[i] = w[i-1]+h[i]*h[i]-hull.query(h[i]);
        hull.add(h[i]*2, -1*h[i]*h[i]+w[i]-dp[i]);
    }
    cout << dp[n];
}

Compilation message

building.cpp:18:34: error: 'LLONG_MAX' was not declared in this scope
   18 |     static const long long inf = LLONG_MAX;
      |                                  ^~~~~~~~~
building.cpp:3:1: note: 'LLONG_MAX' is defined in header '<climits>'; did you forget to '#include <climits>'?
    2 | #include <set>
  +++ |+#include <climits>
    3 |