Submission #856314

# Submission time Handle Problem Language Result Execution time Memory
856314 2023-10-03T05:46:20 Z Cyanmond Building Bridges (CEOI17_building) C++17
30 / 100
3000 ms 5032 KB
#include <bits/stdc++.h>

using namespace std;

#define rep(i, l, r) for (int i = (l); i < (r); ++i)
#define per(i, l, r) for (int i = (r - 1); i >= l; --i)
#define ALL(x) (x).begin(), (x).end()

using i64 = long long;

struct CHT {
    // naive
    vector<pair<i64, i64>> v;

    void add(i64 x, i64 y) {
        v.push_back({x, y});
    }

    i64 calcMin(i64 x) {
        i64 ret = 1ll << 60;
        for (const auto &[a, b] : v) ret = min(ret, a * x + b);
        return ret;
    }
};

void main_() {
    int N;
    cin >> N;
    vector<i64> H(N), W(N);
    for (auto &e : H) cin >> e;
    for (auto &e : W) cin >> e;

    vector<i64> dp(N, 1ll << 60);
    dp[0] = 0;

    CHT cht;

    cht.add(-2 * H[0], -W[0] + dp[0] + H[0] * H[0]);
    i64 sumW = W[0];
    rep(i, 1, N) {
        const auto mn = cht.calcMin(H[i]);
        dp[i] = mn + H[i] * H[i] + sumW;
        sumW += W[i];
        cht.add(-2 * H[i], -sumW + dp[i] + H[i] * H[i]);
    }

    cout << dp[N - 1] << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    main_();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3057 ms 5032 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Execution timed out 3057 ms 5032 KB Time limit exceeded
7 Halted 0 ms 0 KB -