답안 #1078736

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1078736 2024-08-28T05:27:44 Z vjudge1 Building Bridges (CEOI17_building) C++17
0 / 100
53 ms 71252 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct {
    struct line{
        int K;
        ll B;
        line(int k,ll b){
            K=k,B=b;
        }
        line(){
            K=0;
            B=1e18;
        }
        inline ll operator()(int x){
            return K*x+B;
        }
    } T[1<<21];
    void update(int i,int l,int r,line s){
        if(s.B==1e18)return;
        if(l==r-1){
            if(s(l)<T[i](l))
                swap(s,T[i]);
            return;
        }
        if(s.K<T[i].K)
            swap(s,T[i]);
        if(s(l+r>>1) < T[i](l+r>>1))
            swap(s,T[i]),update(i*2+1,l+r>>1,r,s);
        else update(i*2,l,l+r>>1,s);
    }
    ll query(int i,int l,int r,int p){
        if(T[i].B==1e18)
            return 1e18;
        if(l==r-1)
            return T[i](p);
        if(p<l+r>>1)
            return min(T[i](p),query(i*2,l,l+r>>1,p));
        else return min(T[i](p),query(i*2+1,l+r>>1,r,p));
    }
    void add_line(int k,ll b){
        update(1,0,1e7,line(k,b));
    }
    ll calc_best(int pos){
        return query(1,0,1e7,pos);
    }
} lichao;
ll h[100100],w[100100],dp[100100];
void update_dp(int i){
    lichao.add_line(-2*h[i],h[i]*h[i]-w[i]+dp[i]);
}
int main(){
    cin.tie(0)->sync_with_stdio(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>h[i];
    for(int i=1;i<=n;i++)
        cin>>w[i];
    for(int i=2;i<=n;i++){
        update_dp(i-1);
        w[i]+=w[i-1];
        dp[i]=lichao.calc_best(h[i])+h[i]*h[i]+w[i-1];
    }
    cout<<dp[n]<<'\n';
}

Compilation message

building.cpp: In member function 'void<unnamed struct>::update(int, int, int, <unnamed struct>::line)':
building.cpp:28:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   28 |         if(s(l+r>>1) < T[i](l+r>>1))
      |              ~^~
building.cpp:28:30: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   28 |         if(s(l+r>>1) < T[i](l+r>>1))
      |                             ~^~
building.cpp:29:40: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   29 |             swap(s,T[i]),update(i*2+1,l+r>>1,r,s);
      |                                       ~^~
building.cpp:30:28: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   30 |         else update(i*2,l,l+r>>1,s);
      |                           ~^~
building.cpp: In member function 'll<unnamed struct>::query(int, int, int, int)':
building.cpp:37:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   37 |         if(p<l+r>>1)
      |              ~^~
building.cpp:38:45: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   38 |             return min(T[i](p),query(i*2,l,l+r>>1,p));
      |                                            ~^~
building.cpp:39:46: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   39 |         else return min(T[i](p),query(i*2+1,l+r>>1,r,p));
      |                                             ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 33372 KB Output is correct
2 Incorrect 14 ms 33112 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 53 ms 71252 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 33372 KB Output is correct
2 Incorrect 14 ms 33112 KB Output isn't correct
3 Halted 0 ms 0 KB -