답안 #1110264

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1110264 2024-11-09T03:50:35 Z ducanh0811 Building Bridges (CEOI17_building) C++14
100 / 100
36 ms 19536 KB
/***
 *        ___       ___       ___       ___
 *       /\__\     /\  \     /\__\     /\__\
 *      /:| _|_   _\:\  \   /:/ _/_   /::L_L_
 *     /::|/\__\ /\/::\__\ /:/_/\__\ /:/L:\__\
 *     \/|::/  / \::/\/__/ \:\/:/  / \/_/:/  /
 *       |:/  /   \:\__\    \::/  /    /:/  /
 *       \/__/     \/__/     \/__/     \/__/
 */

#define task ""
#include <bits/stdc++.h>
/**                         **/
typedef long long ll;
typedef long double db;
using namespace std;
/**                         **/
#define int long long
#define endl    '\n'
#define fi      first
#define se      second
#define pb      push_back
#define eb      emplace_back
#define pll     pair<ll,ll>
#define ALL(x)  x.begin(),x.end()
#define len(s)      ((int)(s.size()))
#define mask(i)     (1LL<<(i))
#define bit(i,j)    ((1LL<<(j))&(i))
#define on(i,j)     ((1LL<<(j))|(i))
#define off(i,j)    ((~(1LL<<(j)))&(i))
#define FOR(i,a,b)  for(ll i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(ll i = (a); i >= (b); --i)
/**                         **/

int N;
#define MAXN 100005
int h[MAXN];
int w[MAXN];
int pref[MAXN];
const int INF = 1e18;

struct line{
    int a, b;
    line() : a(0), b(0) {};
    line(const int &a, const int &b): a(a), b(b) {};
    int value(const int &x) {return a * x + b;};
    int slope() {return a;};
};

struct LCTopt{
    int n;
    vector<line> st;
    LCTopt(const int &_size) : n(_size), st(_size + 1, line(0, INF)) {};
    void update(int l, int r, line F){
        if (l > r) return;
        int mid = (l + r) >> 1;
        if (l == r) return st[mid] = (F.value(l) < st[mid].value(l) ? F : st[mid]), void();
        if (st[mid].value(mid) > F.value(mid)) swap(st[mid], F);
        if (F.value(l) < st[mid].value(l)) update(l, mid - 1, F);
        if (F.value(r) < st[mid].value(r)) update(mid + 1, r, F);
    }
    void update(line F){ return update(1, n, F); };
    int query(int l, int r, int p){
        int mid = (l + r) >> 1;
        int value = st[mid].value(p);
        if (p == mid) return value;
        if (p < mid) return min(query(l, mid - 1, p), value);
        return min(query(mid + 1, r, p), value);
    }
    int query(int p) {return query(1, n, p);};
};

/**
6
3 8 7 1 6 6
0 -1 9 1 2 0
**/

void solve(){
    cin >> N;
    int MAX = 0;
    FOR(i,1,N) cin >> h[i];
    FOR(i,1,N) MAX = max(MAX, h[i]);
    FOR(i,1,N) cin >> w[i];
    FOR(i,1,N) pref[i]=pref[i-1]+w[i];
    LCTopt tree(MAX);
    tree.update(line(-2*h[1], h[1]*h[1] - pref[1]));
    FOR(i,2,N){
        int dpi = tree.query(h[i]) + pref[i-1] + h[i]*h[i];
        if (i == N) return cout << dpi, void();
        tree.update(line(-2*h[i], h[i]*h[i] + dpi - pref[i]));
    }
}

/**                         **/
int32_t main(){
    if (fopen(task".inp","r"))
    {
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    solve();
    return 0;
}

Compilation message

building.cpp: In function 'int32_t main()':
building.cpp:100:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  100 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
building.cpp:101:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  101 |         freopen(task".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2556 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 4432 KB Output is correct
2 Correct 33 ms 5456 KB Output is correct
3 Correct 33 ms 5456 KB Output is correct
4 Correct 31 ms 5200 KB Output is correct
5 Correct 30 ms 6744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2556 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2552 KB Output is correct
6 Correct 32 ms 4432 KB Output is correct
7 Correct 33 ms 5456 KB Output is correct
8 Correct 33 ms 5456 KB Output is correct
9 Correct 31 ms 5200 KB Output is correct
10 Correct 30 ms 6744 KB Output is correct
11 Correct 32 ms 5568 KB Output is correct
12 Correct 32 ms 5200 KB Output is correct
13 Correct 21 ms 3920 KB Output is correct
14 Correct 36 ms 5456 KB Output is correct
15 Correct 33 ms 6736 KB Output is correct
16 Correct 31 ms 6736 KB Output is correct
17 Correct 18 ms 19536 KB Output is correct
18 Correct 16 ms 3664 KB Output is correct