Submission #43229

# Submission time Handle Problem Language Result Execution time Memory
43229 2018-03-11T06:55:28 Z 5ak0 Building Bridges (CEOI17_building) C++14
0 / 100
3000 ms 2784 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]);
}

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; ++i)
        for (int j = i + 1; j < n; ++j)
            res = min(res, pre[i - 1] - pre[1] + pre[j - 1] - pre[i] + pre[n - 1] - pre[j] + dist(1, i) + dist(i, j) + dist(j, n));
    cout << res;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3002 ms 2784 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 248 KB Output isn't correct
2 Halted 0 ms 0 KB -