Submission #787728

# Submission time Handle Problem Language Result Execution time Memory
787728 2023-07-19T11:47:33 Z aymanrs Cyberland (APIO23_cyberland) C++17
Compilation error
0 ms 0 KB
#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);
      |                                                           ~^~
cyberland.cpp:35:1: error: expected '}' at end of input
   35 | }
      | ^
cyberland.cpp:3:123: note: to match this '{'
    3 | 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){
      |                                                                                                                           ^
cyberland.cpp:35:1: warning: control reaches end of non-void function [-Wreturn-type]
   35 | }
      | ^