Submission #468984

# Submission time Handle Problem Language Result Execution time Memory
468984 2021-08-30T10:27:00 Z Josia Building Bridges (CEOI17_building) C++17
0 / 100
3000 ms 3020 KB
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")


#include <bits/stdc++.h>

#define int int64_t

using namespace std;


vector<int> pfs = {0};


int dp(vector<pair<int, int>>& pillars, int lenght) {
    if (lenght == 0) {
        return 0;
    }

    int res = 1e17;

    for (int i = 0; i<lenght; i++) {
        res = min(res, dp(pillars, i) + (pfs[lenght] - pfs[i+1]) + (pillars[i].first - pillars[lenght].first) * (pillars[i].first - pillars[lenght].first));
    }
    return res;
}




signed main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    int n; cin >> n;


    vector<pair<int, int>> pillars(n);

    for (int i = 0; i<n; i++) {
        cin >> pillars[i].first;
    }
    for (int i = 0; i<n; i++) {
        cin >> pillars[i].second;
        pfs.push_back(pfs.back() + pillars[i].second);
    }

    pillars[0].second = 0;

    pillars.back().second = 0;


    cout << dp(pillars, n-1) << "\n";


    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Execution timed out 3075 ms 204 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3071 ms 3020 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Execution timed out 3075 ms 204 KB Time limit exceeded
3 Halted 0 ms 0 KB -