답안 #964233

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
964233 2024-04-16T13:14:48 Z Pring Building Bridges (CEOI17_building) C++17
0 / 100
57 ms 11676 KB
#include <bits/stdc++.h>
using namespace std;

#ifdef MIKU
string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";
#define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x)
void dout() { cout << dbrs << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif

#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
using ll = long long;
typedef pair<int, int> pii;
typedef pair<string, int> psi;

const int MXN = 100005;
const ll INF = 3.9e18;
int n, h[MXN], w[MXN];
int scr[MXN], rnk[MXN];
ll dp[MXN], p[MXN];

struct MK {
    ll m, k;
    MK() : m(0), k(0) {}
    MK(ll _m, ll _k) : m(_m), k(_k) {}
    ll operator()(ll x) {
        return m * x + k;
    }
};

struct LCSMG {
    MK val[MXN * 4];
    void init(int n) {
        fill(val, val + n * 4, MK(0, INF));
    }
    void modify(int id, int l, int r, MK L_) {
        MK &L = val[id];
        if (L.m > L_.m) swap(L, L_);
        int mid = (l + r) >> 1;
        if (L(scr[mid]) > L_(scr[mid])) swap(L, L_);
        if (l + 1 == r) return;
        if (L.m < L_.m) modify(id * 2 + 1, l, mid, L_);
        else modify(id * 2 + 2, mid, r, L_);
    }
    ll query(int id, int l, int r, int p) {
        if (l + 1 == r) return val[id](scr[p]);
        int mid = (l + r) >> 1;
        if (mid < p) return min(val[id](scr[p]), query(id * 2 + 1, l, mid, p));
        else return min(val[id](scr[p]), query(id * 2 + 2, mid, r, p));
    }
} smg;

void DIST() {
    vector<pii> dist;
    FOR(i, 1, n + 1) dist.push_back(mp(h[i], i));
    sort(dist.begin(), dist.end());
    FOR(i, 0, n) {
        scr[i] = dist[i].fs;
        rnk[dist[i].sc] = i;
    }
}

void miku() {
    cin >> n;
    FOR(i, 1, n + 1) cin >> h[i];
    FOR(i, 1, n + 1) cin >> w[i];
    FOR(i, 1, n + 1) p[i] = p[i - 1] + w[i];
    DIST();
    smg.init(n);
    dp[1] = 0;
    smg.modify(0, 0, n, MK(-2 * h[1], h[1] * h[1] + dp[1] - p[1]));
    FOR(i, 2, n + 1) {
        dp[i] = h[i] * h[i] + p[i - 1] + smg.query(0, 0, n, rnk[i]);
        smg.modify(0, 0, n, MK(-2 * h[i], h[i] * h[i] + dp[i] - p[i]));
    }
    cout << dp[n] << '\n';
}

int32_t main() {
    cin.tie(0) -> sync_with_stdio(false);
    cin.exceptions(cin.failbit);
    miku();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8800 KB Output is correct
2 Incorrect 2 ms 8800 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 57 ms 11676 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8800 KB Output is correct
2 Incorrect 2 ms 8800 KB Output isn't correct
3 Halted 0 ms 0 KB -