# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
158583 | 2019-10-18T02:43:48 Z | PeppaPig | Building Bridges (CEOI17_building) | C++14 | 71 ms | 8308 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(1e9, 1e9)); 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 | 4472 KB | Output is correct |
2 | Correct | 5 ms | 4472 KB | Output is correct |
3 | Correct | 6 ms | 4472 KB | Output is correct |
4 | Correct | 6 ms | 4472 KB | Output is correct |
5 | Correct | 6 ms | 4472 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 71 ms | 8300 KB | Output is correct |
2 | Correct | 69 ms | 8308 KB | Output is correct |
3 | Correct | 68 ms | 8308 KB | Output is correct |
4 | Correct | 62 ms | 8176 KB | Output is correct |
5 | Incorrect | 56 ms | 8176 KB | Output isn't correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 4472 KB | Output is correct |
2 | Correct | 5 ms | 4472 KB | Output is correct |
3 | Correct | 6 ms | 4472 KB | Output is correct |
4 | Correct | 6 ms | 4472 KB | Output is correct |
5 | Correct | 6 ms | 4472 KB | Output is correct |
6 | Correct | 71 ms | 8300 KB | Output is correct |
7 | Correct | 69 ms | 8308 KB | Output is correct |
8 | Correct | 68 ms | 8308 KB | Output is correct |
9 | Correct | 62 ms | 8176 KB | Output is correct |
10 | Incorrect | 56 ms | 8176 KB | Output isn't correct |