#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#define pb push_back
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define pii pair <int,int>
#define Pii pair< pii , pii >
#define int long long
using namespace std ;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 4e5 + 10 , maxq = 1e7 + 1 , inf = 1e8 + 10 , mod= 998244353 ,lg = 20 ;
int dp[maxn] , h[maxn] , w[maxn];
signed main(){
ios::sync_with_stdio(false); cin.tie(0) ;
int n ;
cin >> n;
for(int i =1 ; i<= n ;i++){
cin >> h[i] ;
}
int ans= 0 ;
for(int i = 1; i <= n ; i++){
cin >> w[i] ;
}
for(int i = 2; i <= n ; i++){
int sm =0 ;
dp[i] = inf ;
for(int j = i-1 ; j >= 1; j--){
dp[i] = min(sm + (h[i] - h[j]) * (h[i] - h[j]) + dp[j], dp[i]) ;
sm += w[j] ;
}
}
cout << dp[n] ;
}
/*
*/
Compilation message
building.cpp: In function 'int main()':
building.cpp:24:7: warning: unused variable 'ans' [-Wunused-variable]
24 | int ans= 0 ;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4856 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3036 ms |
9860 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4856 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Execution timed out |
3036 ms |
9860 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |