Submission #315303

#TimeUsernameProblemLanguageResultExecution timeMemory
315303dolphingarlicBootfall (IZhO17_bootfall)C++14
44 / 100
1098 ms760 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, a[500], tot = 0;
    scanf("%d", &n);
    bitset<250001> base;
    base[0] = 1;
    for (int i = 0; i < n; i++) {
        scanf("%d", a + i);
        tot += a[i];
        base |= base << a[i];
    }
    if ((tot & 1) || !base[tot >> 1]) return printf("0"), 0;

    bitset<250001> ans;
    for (int i = 1; i <= tot; i++) ans[i] = 1;

    for (int i = 0; i < n; i++) {
        bitset<250001> possible, good;
        possible[0] = 1;
        for (int j = 0; j < n; j++) if (j != i) possible |= possible << a[j];
        for (int j = 1; j <= tot; j++) good[j] = !(tot - a[i] + j & 1) && (tot - a[i] + j >> 1) - j >= 0 && possible[(tot - a[i] + j >> 1) - j];
        ans &= good;
    }

    printf("%d\n", ans.count());
    for (int i = 0; i <= tot; i++) if (ans[i]) printf("%d ", i);
    return 0;
}

Compilation message (stderr)

bootfall.cpp: In function 'int main()':
bootfall.cpp:23:63: warning: suggest parentheses around '+' in operand of '&' [-Wparentheses]
   23 |         for (int j = 1; j <= tot; j++) good[j] = !(tot - a[i] + j & 1) && (tot - a[i] + j >> 1) - j >= 0 && possible[(tot - a[i] + j >> 1) - j];
      |                                                    ~~~~~~~~~~~^~~
bootfall.cpp:23:87: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   23 |         for (int j = 1; j <= tot; j++) good[j] = !(tot - a[i] + j & 1) && (tot - a[i] + j >> 1) - j >= 0 && possible[(tot - a[i] + j >> 1) - j];
      |                                                                            ~~~~~~~~~~~^~~
bootfall.cpp:23:130: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   23 |         for (int j = 1; j <= tot; j++) good[j] = !(tot - a[i] + j & 1) && (tot - a[i] + j >> 1) - j >= 0 && possible[(tot - a[i] + j >> 1) - j];
      |                                                                                                                       ~~~~~~~~~~~^~~
bootfall.cpp:27:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::size_t' {aka 'long unsigned int'} [-Wformat=]
   27 |     printf("%d\n", ans.count());
      |             ~^     ~~~~~~~~~~~
      |              |              |
      |              int            std::size_t {aka long unsigned int}
      |             %ld
bootfall.cpp:6:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    6 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
bootfall.cpp:10:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   10 |         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...