답안 #988658

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
988658 2024-05-25T12:01:01 Z Aviansh Building Bridges (CEOI17_building) C++17
30 / 100
70 ms 68456 KB
#include <bits/stdc++.h>

using namespace std;

struct line{
    double m,c;
    double eval(double x){
        return (m*x)+c;
    }
    double intersect(line l){
        return (l.c-c)/(m-l.m);
    }
};

template<class T> class liChaoTree{
    private:
        int n;
        line *st;
        line def = {0,INT_MAX};
    public:
        liChaoTree(int siz){
            int x = (int) pow(2,ceil(log2(siz)));
            n=siz-1;
            st=new line[2*x];
            realST(0,n,0);
        }
        void realST(int l, int r, int ind){
            st[ind]=def;
            if(l!=r){
                int mid = (l+r)/2;
                realST(l,mid,ind*2+1);
                realST(mid+1,r,ind*2+2);
            }
        }
        double realQuer(double x, int l, int r, int ind){
            int mid = (l+r)/2;
            if(r-l==1){
                return st[ind].eval(x);
            }
            else if(x<mid){
                return min(st[ind].eval(x),realQuer(x,l,mid,ind*2+1));
            }
            else{
                return min(st[ind].eval(x),realQuer(x,mid,r,ind*2+2));
            }
        }
        double quer(double x){
            return realQuer(x,0,n,0);
        }
        void realUpdate(int s, int e, line nw, int ind){
            int mid = (s+e)/2;
            bool lef = st[ind].eval(s) > nw.eval(s);
            bool mi = st[ind].eval(mid) > nw.eval(mid);
            if(mi){
                swap(st[ind],nw);
            }
            if(e-s==1){
                return;
            }
            else if(lef!=mi){
                realUpdate(s,mid,nw,ind*2+1);
            }
            else{
                realUpdate(mid,e,nw,ind*2+2);
            }
        }
        void addLine(line l){
            realUpdate(0,n,l,0);
        }
};

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long n;
    cin >> n;
    long long h[n],w[n];
    long long tot = 0;
    for(long long i = 0;i<n;i++){
        cin >> h[i];
    }
    for(long long i = 0;i<n;i++){
        cin >> w[i];
        tot+=w[i];
    }
    long long dp[n];
    dp[0]=-w[0];
    liChaoTree<long long> lct(2e6);
    for(long long i = 1;i<n;i++){
        line l;
        l.m=-2*h[i-1];
        l.c=dp[i - 1] + h[i - 1] * h[i - 1];
        lct.addLine(l);
        dp[i]=lct.quer(h[i]) - w[i]+h[i]*h[i];
    }
    cout << tot+dp[n-1];
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 65876 KB Output is correct
2 Correct 26 ms 65876 KB Output is correct
3 Correct 33 ms 65872 KB Output is correct
4 Correct 24 ms 66136 KB Output is correct
5 Correct 23 ms 65916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 68456 KB Output is correct
2 Correct 70 ms 68452 KB Output is correct
3 Correct 69 ms 68320 KB Output is correct
4 Correct 62 ms 68448 KB Output is correct
5 Incorrect 54 ms 68432 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 65876 KB Output is correct
2 Correct 26 ms 65876 KB Output is correct
3 Correct 33 ms 65872 KB Output is correct
4 Correct 24 ms 66136 KB Output is correct
5 Correct 23 ms 65916 KB Output is correct
6 Correct 66 ms 68456 KB Output is correct
7 Correct 70 ms 68452 KB Output is correct
8 Correct 69 ms 68320 KB Output is correct
9 Correct 62 ms 68448 KB Output is correct
10 Incorrect 54 ms 68432 KB Output isn't correct
11 Halted 0 ms 0 KB -