Submission #1099935

#TimeUsernameProblemLanguageResultExecution timeMemory
1099935nnqwBootfall (IZhO17_bootfall)C++17
0 / 100
0 ms348 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...