#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){
double dp[K+1];
fill(dp, dp+K+1, -1);
dp[0] = c[H-1];
if(arr[H-1] == 2){
dp[1] = c[H-1];
for(int i = 2;i <= K;i++) dp[i] = (dp[i-1]-c[H-1])/2 + c[H-2] + c[H-1];
}
for(int i = H-2;i >= 0;i--){
if(arr[i] == 2){
int m = min(c[i-1], c[i]);
for(int j = K;j >= 0;j--){
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]);
double mc = 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);
}
if(ans < 1e20) dp[j] = ans;
else dp[j] = -1;
}
} else {
for(int j = 0;j <= K;j++) if(dp[j] != -1) dp[j] += c[i]/(1<<j);
if(!arr[i] || !i){
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';
// }
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:17:61: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
17 | if(j && dp[j-1] != -1) ans = min(ans, c[i]/(1<<j-1) + dp[j-1]);
| ~^~
cyberland.cpp:21:60: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
21 | if(dp[j-k] != -1) ans = min(ans, c[i]/(1<<j-k) + dp[j-k] + mc);
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
364 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
384 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
2120 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
340 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
340 KB |
Wrong Answer. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
7 ms |
484 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3027 ms |
6312 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |