답안 #161613

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
161613 2019-11-03T09:59:53 Z Akashi Building Bridges (CEOI17_building) C++14
60 / 100
88 ms 7544 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 1e6 + 5;

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

struct node{
    long long a, b;
    node *left, *right;

    node(){
        a = b = 0;
        left = right = NULL;
    }
};

node *arb;
void update(long long a, long long b, int st = 1, int dr = 1e6, node *nod = arb){
    if(st == dr){
        if(a + 1LL * b * st < nod->a + 1LL * nod->b * st){
            nod->a = a; nod->b = b;
        }
        return ;
    }

    int mij = (st + dr) / 2;
    if(a + 1LL * b * mij < nod->a + 1LL * nod->b * mij) swap(a, nod->a), swap(b, nod->b);

    if(b == nod->b && a >= nod->a) return ;

    if(b < nod->b){
        if(nod->right == NULL){
            nod->right = new node;
            nod->right->a = a; nod->right->b = b;
            return ;
        }
        update(a, b, mij + 1, dr, nod->right);
    }
    else{
        if(nod->left == NULL){
            nod->left = new node;
            nod->left->a = a; nod->left->b = b;
        }
        update(a, b, st, mij, nod->left);
    }
}

void query(long long &val, long long x, int st = 1, int dr = 1e6, node *nod = arb){
    if(st > dr) return ;

    int mij = (st + dr) / 2;

    val = min(val, nod->a + 1LL * x * nod->b);

    if(x <= mij){
        if(nod->left == NULL) return ;
        query(val, x, st, mij, nod->left);
    }
    else{
        if(nod->right == NULL) return ;
        query(val, x, mij + 1, dr, nod->right);
    }
}

int main()
{
//    freopen("1.in", "r", stdin);

    scanf("%d", &n);
    for(int i = 1; i <= n ; ++i)
        scanf("%d", &h[i]), d[i] = -1e18;
    for(int i = 1; i <= n ; ++i)
        scanf("%d", &w[i]);

    d[1] = 0;
    arb = new node;
    arb->a = 1LL * h[1] * h[1] - w[1]; arb->b = -2LL * h[1];

    long long aux;
    for(int i = 2; i <= n ; ++i){
        w[i] += w[i - 1];

        aux = 1e18;
        query(aux, h[i]);

        d[i] = 1LL * h[i] * h[i] + w[i - 1] + aux;

        update(1LL * h[i] * h[i] + d[i] - w[i], -2LL * h[i]);
    }

    printf("%lld", d[n]);

    return 0;
}

Compilation message

building.cpp: In function 'int main()':
building.cpp:72:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
building.cpp:74:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &h[i]), d[i] = -1e18;
         ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
building.cpp:76:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &w[i]);
         ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 2688 KB Output is correct
2 Correct 65 ms 2720 KB Output is correct
3 Correct 63 ms 2680 KB Output is correct
4 Correct 54 ms 2184 KB Output is correct
5 Correct 46 ms 5596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 64 ms 2688 KB Output is correct
7 Correct 65 ms 2720 KB Output is correct
8 Correct 63 ms 2680 KB Output is correct
9 Correct 54 ms 2184 KB Output is correct
10 Correct 46 ms 5596 KB Output is correct
11 Correct 88 ms 7160 KB Output is correct
12 Correct 84 ms 6904 KB Output is correct
13 Correct 62 ms 3832 KB Output is correct
14 Correct 87 ms 7020 KB Output is correct
15 Correct 48 ms 7544 KB Output is correct
16 Correct 47 ms 6560 KB Output is correct
17 Incorrect 27 ms 3064 KB Output isn't correct
18 Halted 0 ms 0 KB -