답안 #115206

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
115206 2019-06-06T03:59:35 Z minhtung0404 Building Bridges (CEOI17_building) C++17
0 / 100
43 ms 5496 KB
//https://oj.uz/problem/view/CEOI17_building

#include<bits/stdc++.h>
const int N = 1e6 + 5;
const int inf = 1e9;
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] + 1LL * h[1] * h[1]));
    for (int i = 2; i <= n; i++){
        dp[i] = 1LL * 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] + 1LL * h[i] * h[i]));
    }
    for (int i = 1; i <= n; i++) dp[n] += w[i];
    cout << dp[n];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 3 ms 768 KB Output is correct
5 Incorrect 3 ms 768 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 4216 KB Output is correct
2 Correct 43 ms 4220 KB Output is correct
3 Correct 42 ms 4344 KB Output is correct
4 Correct 39 ms 4088 KB Output is correct
5 Incorrect 36 ms 5496 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 3 ms 768 KB Output is correct
5 Incorrect 3 ms 768 KB Output isn't correct