Submission #115207

# Submission time Handle Problem Language Result Execution time Memory
115207 2019-06-06T04:01:51 Z minhtung0404 Building Bridges (CEOI17_building) C++17
0 / 100
44 ms 4472 KB
//https://oj.uz/problem/view/CEOI17_building

#include<bits/stdc++.h>
const int N = 1e6 + 5;
const long long inf = 1e18;
using namespace std;

struct line {
    long long x, y;
    long long get(long long val) { return val * x + y; }
    line (long long x, long long y) : x(x), y(y) {}
    line() {}
} it[4 * N];

struct LiChaoTree {
    #define m ((l + r) >> 1)
    void init() {
        for(int i = 0; i < 4 * N; ++i) it[i].x = 0, it[i].y = inf;
    }
    void add_line(int node, int l, int r, line u) {
        bool lef = u.get(l) < it[node].get(l);
        bool mid = u.get(m) < it[node].get(m);
        if(mid) swap(it[node], u);
        if(l == r) return;
        if(lef != mid) add_line(node << 1, l, m, u);
        else add_line(node << 1 | 1, m + 1, r, u);
    }
    long long get(int node, int l, int r, int u) {
        if(l == r) return it[node].get(u);
        if(u <= m) return min(it[node].get(u), get(node << 1, l, m, u));
        return min(it[node].get(u), get(node << 1 | 1, m + 1, r, u));
    }
    #undef m
} A;

int n;
long long dp[N], h[N], w[N];

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> h[i];
    for (int i = 1; i <= n; i++) cin >> w[i];
    dp[1] = -w[1]; A.add_line(1, 0, N-1, line(-2*h[1], dp[1] + h[1] * h[1]));
    for (int i = 2; i <= n; i++){
        dp[i] = h[i] * h[i] - w[i] + A.get(1, 0, N-1, h[i]);
        A.add_line(1, 0, N-1, line(-2*h[i], dp[i] + h[i] * h[i]));
    }
    for (int i = 1; i <= n; i++) dp[n] += w[i];
    cout << dp[n];
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 3 ms 768 KB Output is correct
5 Incorrect 2 ms 768 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 3192 KB Output is correct
2 Correct 42 ms 3320 KB Output is correct
3 Correct 44 ms 3320 KB Output is correct
4 Correct 38 ms 3072 KB Output is correct
5 Incorrect 36 ms 4472 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 3 ms 768 KB Output is correct
5 Incorrect 2 ms 768 KB Output isn't correct