답안 #263255

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
263255 2020-08-13T14:43:43 Z alexandra_udristoiu Building Bridges (CEOI17_building) C++14
30 / 100
149 ms 5144 KB
#include<iostream>
#include<algorithm>
#define DIM 100005
#define x first
#define y second
using namespace std;
int n, i, m;
int h[DIM], w[DIM], a[DIM];
pair<int, int> aint[4 * DIM], p[DIM];
long long sum, d[DIM];
long long calc(pair<int, int> p, int i){
    return p.x * 1LL * i + p.y;
}
void build(int nod, int st, int dr){
    aint[nod] = p[1];
    if(st != dr){
        int mid = (st + dr) / 2;
        build(2 * nod, st, mid);
        build(2 * nod + 1, mid + 1, dr);
    }
}
void update(int nod, int st, int dr, pair<int, int> p){
    int mid = (st + dr) / 2;
    if( calc(aint[nod], a[mid]) > calc(p, a[mid]) ){
        swap(aint[nod], p);
    }
    if(st != dr){
        if( calc(aint[nod], a[st]) < calc(p, a[st]) ){
            update(2 * nod + 1, mid + 1, dr, p);
        }
        else{
            update(2 * nod, st, mid, p);
        }
    }
}
long long query(int nod, int st, int dr, int p){
    if(st == dr){
        return calc(aint[nod], p);
    }
    else{
        int mid = (st + dr) / 2;
        long long x;
        if(p <= a[mid]){
            x = query(2 * nod, st, mid, p);
        }
        else{
            x = query(2 * nod + 1, mid + 1, dr, p);
        }
        return min(x, calc(aint[nod], p) );
    }
}
int main(){
    cin>> n;
    for(i = 1; i <= n; i++){
        cin>> h[i];
        a[i] = h[i];
    }
    sort(a + 1, a + n + 1);
    for(i = 1; i <= n; i++){
        cin>> w[i];
        m = max(m, h[i]);
        sum += w[i];
        p[i].y = h[i] * 1LL * h[i] - w[i];
        p[i].x = -2 * h[i];
    }
    build(1, 1, n);
    for(i = 2; i <= n; i++){
        d[i] = query(1, 1, n, h[i]) - w[i] + h[i] * 1LL * h[i];
        p[i].y = d[i] + h[i] * 1LL * h[i];
        update(1, 1, n, p[i]);
    }
    cout<< d[n] + sum;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 149 ms 5144 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Incorrect 149 ms 5144 KB Output isn't correct
7 Halted 0 ms 0 KB -