#include <bits/stdc++.h>
using namespace std;
#define Tupizm ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define ONE exit(0);
#define nl "\n"
#define fly return
#define all(x) x.begin(0), x.end(0);
#define sz(x) (int)x.size();
#define pb push_back
#define ppb pop_back
typedef long long ll;
typedef double db;
const int N = 1e5 + 5;
const int M = 1e9 + 7;
int n, a[N], b[N];
int dp[N];
int sum(int l, int r){
int q = 0;
for(int i = l + 1; i < r; ++i){
q += b[i];
}
fly q;
}
int hello(){
for(int i = 2; i <= n; ++i){
dp[i] = M;
}
}
int pff(int l, int r){
return (a[l] - a[r]) * (a[l] - a[r]);
}
int main(){
Tupizm
cin >> n;
hello();
for(int i = 1; i <= n; ++i){
cin >> a[i];
}
for(int i = 1; i <= n; ++i){
cin >> b[i];
}
for(int i = 2; i <= n; ++i){
for(int j = i - 1; j >= 1; --j){
dp[i] = min(dp[i], dp[j] + sum(j, i) + (pff(i, j)));
}
}
cout << dp[n] << nl;
ONE
}
Compilation message
building.cpp: In function 'int hello()':
building.cpp:37:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
252 KB |
Output is correct |
2 |
Correct |
2 ms |
356 KB |
Output is correct |
3 |
Correct |
2 ms |
560 KB |
Output is correct |
4 |
Correct |
106 ms |
560 KB |
Output is correct |
5 |
Correct |
107 ms |
560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3053 ms |
1692 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
252 KB |
Output is correct |
2 |
Correct |
2 ms |
356 KB |
Output is correct |
3 |
Correct |
2 ms |
560 KB |
Output is correct |
4 |
Correct |
106 ms |
560 KB |
Output is correct |
5 |
Correct |
107 ms |
560 KB |
Output is correct |
6 |
Execution timed out |
3053 ms |
1692 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |