Submission #43230

# Submission time Handle Problem Language Result Execution time Memory
43230 2018-03-11T06:59:04 Z 5ak0 Building Bridges (CEOI17_building) C++14
0 / 100
22 ms 2660 KB
/*
ID: 5ak0
PROG:
LANG: C++11
*/

#include <bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define mpr make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e18 + 7;
const int MAXN = 1e5 + 10;

int n;
ll h[MAXN], w[MAXN], pre[MAXN], res = INF;

ll dist(int i, int j){
    return (h[i] - h[j]) * (h[i] - h[j]);
}

ll check(int i, int j){
    return pre[i - 1] - pre[1] + pre[j - 1] - pre[i] + pre[n - 1] - pre[j] + dist(1, i) + dist(i, j) + dist(j, n);
}

int main(){
    ios_base::sync_with_stdio(0);
    #ifndef SAKO
    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);
    #endif // SAKO
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> h[i];
    for (int i = 1; i <= n; ++i){
        cin >> w[i];
        pre[i] = pre[i - 1] + w[i];
    }
    for (int i = 2; i < n - 1; ++i)
        res = min(res, min(check(i, i + 1), check(i, n - 1)));
    cout << res;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 2660 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 248 KB Output isn't correct
2 Halted 0 ms 0 KB -