답안 #46495

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
46495 2018-04-21T04:13:59 Z 1Khan Building Bridges (CEOI17_building) C++14
0 / 100
3000 ms 1640 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 = 1e5 + 5;
const int M = 1e9 + 7;

int n, h[N], w[N];
ll ans = 1e10;
int a[N], b[N];
int main(){
    
    int z = CLOCKS_PER_SEC;
    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> h[i];
    }
    for(int i = 1; i <= n; ++i){
        cin >> w[i];
        a[i] = a[i - 1] + w[i];
    }
    for(int i = 2; i < n; ++i){
        int q = a[i - 1] + ((h[i] - h[1]) * (h[i] - h[1]));
        int e = a[n - 1] - a[i] + ((h[i] - h[n]) * (h[i] - h[n]));
        ans = min(ans, (ll)(q + e));
        for(int j = i + 1; j < n; ++j){
            int t = a[j - 1] - a[i] + ((h[j] - h[i]) * (h[j] - h[i]));
            int y = a[n - 1] - a[j] + ((h[n] - h[j]) * (h[n] - h[j]));
            ans = min(ans, (ll)(q + t + y));
        }
        if((db)clock() / CLOCKS_PER_SEC - z >= 2.30){
            break;
        }
    }
    ans = min(ans, (ll)((h[n] - h[1]) * (h[n] - h[1]) + a[n] - a[1]));
    cout << ans << nl;
    ONE
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3049 ms 1640 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -