Submission #787784

# Submission time Handle Problem Language Result Execution time Memory
787784 2023-07-19T12:39:45 Z aymanrs Cyberland (APIO23_cyberland) C++17
0 / 100
3000 ms 12328 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){
    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-1));
                            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, 1, 3}, {1, 2, 1, 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-1));
      |                                                     ~^~
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-1));
      |                                                                         ~~~^~
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-1));
      |                                                                                      ~^~
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 340 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 340 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 360 KB Wrong Answer.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 3024 KB Correct.
2 Incorrect 16 ms 1236 KB Wrong Answer.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 492 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3051 ms 12328 KB Time limit exceeded
2 Halted 0 ms 0 KB -