Submission #46470

# Submission time Handle Problem Language Result Execution time Memory
46470 2018-04-21T02:46:45 Z 1Khan Building Bridges (CEOI17_building) C++14
0 / 100
3000 ms 564 KB
#include <bits/stdc++.h>

using namespace std;

#define Tupizm ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define ONE exit(0);
#define nl "\n"

#define fly return

#define ff first
#define ss second

#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()

#define pb push_back
#define ppb pop_back

typedef long long ll;
typedef double db;

const int N = 1e3 + 5;
const int M = 1e9 + 7;

int n, h[N], w[N];
ll ans = (ll)M;

void man(int t = 2, int p = 1, ll sum = 0){
    if(t >= n){
        sum += (ll)((h[t] - h[p]) * (h[t] - h[p]));
        ans = min(ans, sum);
        fly;
    }
    int q = t + 1;
    man(q, p, sum + w[t]);
    int w = t + 1;
    int e = t;
    man(w, e, sum + (ll)((h[t] - h[p]) * (h[t] - h[p])));
}
int main(){
      
    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> h[i];
    }
    for(int i = 1; i <= n; ++i){
        cin >> w[i];
    }
    man();
    cout << ans << nl;
    ONE
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Execution timed out 3059 ms 356 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 564 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Execution timed out 3059 ms 356 KB Time limit exceeded
3 Halted 0 ms 0 KB -