답안 #585511

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
585511 2022-06-29T03:26:20 Z amunduzbaev Building Bridges (CEOI17_building) C++17
30 / 100
68 ms 65228 KB
#include "bits/stdc++.h"
using namespace std;
 
#define ar array
typedef int64_t ll;
#define int ll

const int N = 1e5 + 5; 
const int M = 1e6 + 5;
const int inf = 1e9 + 7;

struct node{
	int m, b;
	double operator * (node x){
		return (b - x.b) * 1. / (x.m - m);
	}
	int get(int x){
		return m * x + b;
	}
};

struct LiChao{
	node tree[M << 2];
	LiChao(){
		for(int i=0;i<(M << 2);i++){
			tree[i] = {inf, inf};
		}
	}
	
	void add(node v, int lx = 0, int rx = M, int x = 1){
		if(lx == rx){
			if(v.get(lx) > tree[x].get(lx)) tree[x] = v;
			return;
		}
		if(v.m == tree[x].m){
			tree[x].b = min(tree[x].b, v.b);
			return;
		}
		
		double is = tree[x] * v;
		int m = (lx + rx) >> 1;
		if(is < m + 1){
			if(tree[x].get(m + 1) > v.get(m + 1)) swap(tree[x], v);
			add(v, lx, m, x << 1);
		} else {
			if(tree[x].get(m) > v.get(m)) swap(tree[x], v);
			add(v, m + 1, rx, x << 1 | 1);
		}
	} 
	
	int get(int i, int lx = 0, int rx = M, int x = 1){
		if(lx == rx){
			return tree[x].get(i);
		}
		
		int m = (lx + rx) >> 1;
		if(i <= m) return min(get(i, lx, m, x << 1), tree[x].get(i));
		else return min(get(i, m + 1, rx, x << 1 | 1), tree[x].get(i));
	}
}tree;

int h[N], w[N], dp[N];

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n; cin>>n;
	for(int i=1;i<=n;i++){
		cin>>h[i];
	}
	for(int i=1;i<=n;i++){
		cin>>w[i];
		w[i] += w[i-1];
	}
	
	tree.add({-2 * h[1], h[1] * h[1] - w[1]});
	for(int i=2;i<=n;i++){
		dp[i] = tree.get(h[i]) + h[i] * h[i] + w[i-1];
		tree.add({-2 * h[i], dp[i] + h[i] * h[i] - w[i]});
	}
	cout<<dp[n]<<"\n";
}

/*

6
3 8 7 1 6 6
0 -1 9 1 2 0

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 62932 KB Output is correct
2 Correct 25 ms 62932 KB Output is correct
3 Correct 26 ms 62932 KB Output is correct
4 Correct 31 ms 62844 KB Output is correct
5 Correct 27 ms 62932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 65156 KB Output is correct
2 Correct 65 ms 65148 KB Output is correct
3 Correct 68 ms 65228 KB Output is correct
4 Correct 66 ms 65208 KB Output is correct
5 Incorrect 55 ms 65216 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 62932 KB Output is correct
2 Correct 25 ms 62932 KB Output is correct
3 Correct 26 ms 62932 KB Output is correct
4 Correct 31 ms 62844 KB Output is correct
5 Correct 27 ms 62932 KB Output is correct
6 Correct 64 ms 65156 KB Output is correct
7 Correct 65 ms 65148 KB Output is correct
8 Correct 68 ms 65228 KB Output is correct
9 Correct 66 ms 65208 KB Output is correct
10 Incorrect 55 ms 65216 KB Output isn't correct
11 Halted 0 ms 0 KB -