Loading...
Submission
# When Author Problem Language CPU Memory
20890 2024-06-29 10:17:26 Muntasir_Mahmud The Picky Penguins' Party C 1 ms 2012 kb Wrong Answer - 2
Test Cases
# CPU Memory Points
1 1 ms 2008 kb 1 Accepted
2 1 ms 2012 kb 0 Wrong Answer
3 0 ms 0 kb 0 Skipped
4 0 ms 0 kb 0 Skipped
5 0 ms 0 kb 0 Skipped
Source Code
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3. #include <stdlib.h>
  4.  
  5. void penguin_party(int T, int test_cases[][100000], int sizes[]) {
  6. for (int t = 0; t < T; t++) {
  7. int N = sizes[t];
  8. int* A = test_cases[t];
  9. long long total_sum = 0;
  10.  
  11. // Calculate the total sum
  12. for (int i = 0; i < N; i++) {
  13. total_sum += A[i];
  14. }
  15.  
  16. // Check if total sum is odd
  17. if (total_sum % 2 != 0) {
  18. printf("Party's Cancelled\n");
  19. continue;
  20. }
  21.  
  22. long long target_sum = total_sum / 2;
  23. bool* dp = (bool*)calloc(target_sum + 1, sizeof(bool));
  24. dp[0] = true;
  25.  
  26. // Dynamic programming to find if target_sum is achievable
  27. for (int i = 0; i < N; i++) {
  28. for (long long j = target_sum; j >= A[i]; j--) {
  29. if (dp[j - A[i]]) {
  30. dp[j] = true;
  31. }
  32. }
  33. }
  34.  
  35. if (dp[target_sum]) {
  36. printf("Party Time!\n");
  37. } else {
  38. printf("Party's Cancelled\n");
  39. }
  40.  
  41. free(dp);
  42. }
  43. }
  44.  
  45. int main() {
  46. int T = 2;
  47. int test_cases[2][100000] = {
  48. {2, 2},
  49. {1, 2, 4, 3}
  50. };
  51. int sizes[2] = {2, 4};
  52.  
  53. penguin_party(T, test_cases, sizes);
  54.  
  55. return 0;
  56. }
  57.