#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pii pair<int,int>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define f first
#define int double
#define s second
#define pii pair<int,int>
template<class T>bool umax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T>bool umin(T &a,T b){if(b<a){a=b;return true;}return false;}
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
const int N=3e5 + 5 ;
const int inf = 3e18 + 7;
const int mod = 998244353;
void solve(){
int n,m,k;
cin>>n;
vector<int>h(n+1),w(n+1);
for(int i = 1;i<=n;i++){
cin>>h[i];
}
for(int i = 1;i<=n;i++){
cin>>w[i];
}
vector<int>dp(n + 1,inf);
dp[1] = 0;
for(int i = 2;i<=n;i++){
int cost = 0;
for(int j = i - 1;j >= 1;j--){
dp[i] = min(dp[i],(h[i]-h[j])*(h[i]-h[j])+cost+dp[j]);
cost += w[j];
//~ if(i == n)cout<<cost<<" ";
}
}
cout<<dp[n]<<"\n";
/*
6
3 8 7 1 6 6
0 -1 9 1 2 0
17
*/
}
signed main()
{
// freopen("seq.in", "r", stdin);
// freopen("seq.out", "w", stdout);
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int tt=1;//cin>>tt>>n;
while(tt--)solve();
}
Compilation message
building.cpp: In function 'void solve()':
building.cpp:25:8: warning: unused variable 'm' [-Wunused-variable]
25 | int n,m,k;
| ^
building.cpp:25:10: warning: unused variable 'k' [-Wunused-variable]
25 | int n,m,k;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3017 ms |
2648 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |