# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
158584 | 2019-10-18T02:53:29 Z | PeppaPig | Building Bridges (CEOI17_building) | C++14 | 84 ms | 8552 KB |
#include <bits/stdc++.h> #define long long long #define pii pair<long, long> #define x first #define y second using namespace std; const int N = 1 << 17; vector<int> coord; pii t[N << 1]; long f(long x, pii l) { return l.x * x + l.y; } void add(pii k, int p = 1, int l = 1, int r = coord.size()) { int m = (l + r) >> 1; int L = coord[l-1], M = coord[m-1], R = coord[r-1]; bool lef = f(L, k) < f(L, t[p]); bool mid = f(M, k) < f(M, t[p]); if(mid) swap(k, t[p]); if(l == r) return; else if(lef != mid) add(k, p<<1, l, m); else add(k, p<<1|1, m+1, r); } long get(long x, int p = 1, int l = 1, int r = coord.size()) { if(l == r) return f(x, t[p]); int m = (l + r) >> 1; int L = coord[l-1], M = coord[m-1], R = coord[r-1]; if(x <= M) return min(f(x, t[p]), get(x, p<<1, l, m)); else return min(f(x, t[p]), get(x, p<<1|1, m+1, r)); } int n; long h[N], w[N], dp[N]; int main() { fill_n(t, N<<1, pii(1e12, 1e12)); scanf("%d", &n); for(int i = 1; i <= n; i++) { scanf("%lld", h+i); coord.emplace_back(h[i]); } for(int i = 1; i <= n; i++) { scanf("%lld", w+i); w[i] += w[i-1]; } sort(coord.begin(), coord.end()); coord.resize(unique(coord.begin(), coord.end()) - coord.begin()); add(pii(-2ll * h[1], h[1] * h[1] - w[1])); for(int i = 2; i <= n; i++) { dp[i] = get(h[i]) + h[i] * h[i] + w[i-1]; add(pii(-2ll * h[i], h[i] * h[i] - w[i] + dp[i])); } printf("%lld\n", dp[n]); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 4476 KB | Output is correct |
2 | Correct | 5 ms | 4472 KB | Output is correct |
3 | Correct | 5 ms | 4472 KB | Output is correct |
4 | Correct | 5 ms | 4472 KB | Output is correct |
5 | Correct | 6 ms | 4472 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 68 ms | 7304 KB | Output is correct |
2 | Correct | 69 ms | 7276 KB | Output is correct |
3 | Correct | 68 ms | 7280 KB | Output is correct |
4 | Correct | 62 ms | 7284 KB | Output is correct |
5 | Correct | 56 ms | 7364 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 4476 KB | Output is correct |
2 | Correct | 5 ms | 4472 KB | Output is correct |
3 | Correct | 5 ms | 4472 KB | Output is correct |
4 | Correct | 5 ms | 4472 KB | Output is correct |
5 | Correct | 6 ms | 4472 KB | Output is correct |
6 | Correct | 68 ms | 7304 KB | Output is correct |
7 | Correct | 69 ms | 7276 KB | Output is correct |
8 | Correct | 68 ms | 7280 KB | Output is correct |
9 | Correct | 62 ms | 7284 KB | Output is correct |
10 | Correct | 56 ms | 7364 KB | Output is correct |
11 | Correct | 84 ms | 8496 KB | Output is correct |
12 | Correct | 82 ms | 8340 KB | Output is correct |
13 | Correct | 59 ms | 8432 KB | Output is correct |
14 | Correct | 84 ms | 8552 KB | Output is correct |
15 | Correct | 55 ms | 8176 KB | Output is correct |
16 | Correct | 56 ms | 8304 KB | Output is correct |
17 | Correct | 33 ms | 8432 KB | Output is correct |
18 | Correct | 32 ms | 8432 KB | Output is correct |