Submission #1099935

# Submission time Handle Problem Language Result Execution time Memory
1099935 2024-10-12T07:06:12 Z nnqw Bootfall (IZhO17_bootfall) C++17
0 / 100
0 ms 348 KB
#include "bits/stdc++.h"
using namespace std;

const int N = 505;
int a[N];

int main() {
    int n;
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);

    int totalSum = accumulate(a + 1, a + n + 1, 0);
    vector<int> A;

    for(int x = 0; x <= totalSum; ++x) {
        a[n + 1] = x;  // Include Tima's strength
        int currentSum = totalSum + x;
        
        // If the total sum is odd, skip to the next x
        if (currentSum % 2 != 0) continue;

        int half = currentSum / 2;
        vector<bool> dp(half + 1, false);
        dp[0] = true;

        // Fill the DP table
        for(int i = 1; i <= n + 1; ++i) {
            int strength = a[i];
            for(int j = half; j >= strength; --j) {
                dp[j] = dp[j] || dp[j - strength];
            }
        }

        // Check if we can achieve the half-sum
        if (dp[half]) {
            A.push_back(x);
        }
    }

    printf("%d\n", (int)A.size());
    for(int i : A)
        printf("%d ", i);
    puts("");

    return 0;
}

Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
bootfall.cpp:11:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |         scanf("%d", &a[i]);
      |         ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -