#include <bits/stdc++.h>
using namespace std;
double solve(int N, int M, int K, int H, std::vector<int> x, std::vector<int> y, std::vector<int> C, std::vector<int> arr){
long double c[M];
for(int i = 0;i < M;i++) c[i] = C[i];
long double dp[K+1];
fill(dp, dp+K+1, -1);
dp[0] = c[H-1];
long long f = LONG_LONG_MIN;
if(arr[H-1] == 2){
dp[1] = c[H-1];
long double mc = 0;
for(int i = 2;i <= K;i++) {
mc = mc*0.5 + c[H-2];
dp[i] = c[H-1]+mc;
}
f = 0;
}
for(int i = H-2;i >= 0;i--){
f += c[i];
if(arr[i] == 2){
int m = min(c[i-1], c[i]);
for(int j = K;j >= 0;j--){
long double ans = 1e20;
if(dp[j] != -1) ans = c[i]/(1<<j) + dp[j];
if(j && dp[j-1] != -1) ans = min(ans, c[i]/(1<<j-1) + dp[j-1]);
long double mc = 0, cc = 0;
for(int k = 2;k <= j;k++){
mc = mc*0.5+m;
if(dp[j-k] != -1) {
ans = min(ans, c[i]/(1<<j-k) + dp[j-k] + mc/(1<<j-k));
if(f >= 0){
if(k&1){
cc = cc*0.5+f;
ans = min(ans, c[i]/(1<<j-k)+dp[j-k]+cc/(1<<j-k+1));
} else {
ans = min(ans, c[i]/(1<<j-k)+dp[j-k]+cc/(1<<j-k+1)+m/(1<<j-2));
cc = cc*0.5+f;
}
}
}
}
if(ans < 1e20) dp[j] = ans;
else dp[j] = -1;
}
f = 0;
} else {
for(int j = 0;j <= K;j++) if(dp[j] != -1) dp[j] += c[i]/(1<<j);
if(!arr[i] || !i){
long double ans = dp[0];
for(int j = 1;j <= K;j++) if(dp[j] != -1) ans = min(ans, dp[j]);
return ans;
}
}
}
return c[0];
}
int main(){
// cout << solve(6, 5, 2, 5, {0, 1, 2, 3, 4}, {1, 2, 3, 4, 5}, {1, 2, 4, 8, 16}, {1, 2, 0, 2, 2, 1}) << '\n';
cout << solve(4, 3, 3, 3, {0, 1, 2}, {1, 2, 3}, {32, 2, 3}, {1, 2, 2, 1});
}
Compilation message
cyberland.cpp: In function 'double solve(int, int, int, int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
cyberland.cpp:26:61: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
26 | if(j && dp[j-1] != -1) ans = min(ans, c[i]/(1<<j-1) + dp[j-1]);
| ~^~
cyberland.cpp:31:46: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
31 | ans = min(ans, c[i]/(1<<j-k) + dp[j-k] + mc/(1<<j-k));
| ~^~
cyberland.cpp:31:70: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
31 | ans = min(ans, c[i]/(1<<j-k) + dp[j-k] + mc/(1<<j-k));
| ~^~
cyberland.cpp:35:54: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
35 | ans = min(ans, c[i]/(1<<j-k)+dp[j-k]+cc/(1<<j-k+1));
| ~^~
cyberland.cpp:35:76: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
35 | ans = min(ans, c[i]/(1<<j-k)+dp[j-k]+cc/(1<<j-k+1));
| ~~~^~
cyberland.cpp:37:54: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
37 | ans = min(ans, c[i]/(1<<j-k)+dp[j-k]+cc/(1<<j-k+1)+m/(1<<j-2));
| ~^~
cyberland.cpp:37:76: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
37 | ans = min(ans, c[i]/(1<<j-k)+dp[j-k]+cc/(1<<j-k+1)+m/(1<<j-2));
| ~~~^~
cyberland.cpp:37:87: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
37 | ans = min(ans, c[i]/(1<<j-k)+dp[j-k]+cc/(1<<j-k+1)+m/(1<<j-2));
| ~^~
/usr/bin/ld: /tmp/cc2O3UQK.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccQCEHFN.o:cyberland.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status