Submission #397418

# Submission time Handle Problem Language Result Execution time Memory
397418 2021-05-02T06:40:57 Z Nicholas_Patrick Building Bridges (CEOI17_building) C++17
30 / 100
3000 ms 4392 KB
#include <cstdio>
#include <queue>
using namespace std;

struct line{
	long long m, c;
	line(long long m, long long c):m(m), c(c){}
	long long eval(long long x){
		return m*x+c;
	}
};
int main(){
	int n;
	scanf("%d", &n);
	vector<int> h(n), w(n);
	for(int& i: h)
		scanf("%d", &i);
	long long sumw=0;
	for(int& i: w){
		scanf("%d", &i);
		sumw+=i;
		i=-i;
	}
	vector<line> ch;
	ch.emplace_back(-2*h[0], (long long)h[0]*h[0]+w[0]);
	for(int i=1; i+1<n; i++){
		long long cost=1e18;
		for(auto& j: ch)
			cost=min(cost, j.eval(h[i]));
		cost+=(long long)h[i]*h[i]+w[i];
		ch.emplace_back(-2*h[i], (long long)h[i]*h[i]+cost);
	}
	long long ans=1e18;
	for(auto& j: ch)
		ans=min(ans, j.eval(h[n-1]));
	ans+=(long long)h[n-1]*h[n-1]+w[n-1]+sumw;
	printf("%lld\n", ans);
}

Compilation message

building.cpp: In function 'int main()':
building.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
building.cpp:17:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   17 |   scanf("%d", &i);
      |   ~~~~~^~~~~~~~~~
building.cpp:20:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   20 |   scanf("%d", &i);
      |   ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 284 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3058 ms 4392 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 284 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Execution timed out 3058 ms 4392 KB Time limit exceeded
7 Halted 0 ms 0 KB -