Submission #309852

#TimeUsernameProblemLanguageResultExecution timeMemory
309852peuchBuilding Bridges (CEOI17_building)C++17
30 / 100
3079 ms3404 KiB
#include<bits/stdc++.h>
using namespace std;

const int MAXN = 1e5 + 10;
const long long INF = 1e18;

int n;
long long h[MAXN], sw[MAXN];
long long dp[MAXN];

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
		scanf("%d", &h[i]);
	for(int i = 1; i <= n; i++){
		int aux;
		scanf("%d", &aux);
		sw[i] = sw[i - 1] + aux;
	}
	for(int i = 2; i <= n; i++){
		dp[i] = INF;
		for(int j = 1; j < i; j++)
			dp[i] = min(dp[i], dp[j] + (h[i] - h[j]) * (h[i] - h[j]) + sw[i - 1] - sw[j]);
	}
	printf("%d\n", dp[n]);
}
/*
6
3 8 7 1 6 6
0 -1 9 1 2 0
*/

Compilation message (stderr)

building.cpp: In function 'int main()':
building.cpp:14:11: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   14 |   scanf("%d", &h[i]);
      |          ~^   ~~~~~
      |           |   |
      |           |   long long int*
      |           int*
      |          %lld
building.cpp:25:11: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
   25 |  printf("%d\n", dp[n]);
      |          ~^     ~~~~~
      |           |         |
      |           int       long long int
      |          %lld
building.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   12 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
building.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 |   scanf("%d", &h[i]);
      |   ~~~~~^~~~~~~~~~~~~
building.cpp:17:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   17 |   scanf("%d", &aux);
      |   ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...