Submission #211283

#TimeUsernameProblemLanguageResultExecution timeMemory
211283nouvo25Bootfall (IZhO17_bootfall)C++14
44 / 100
1039 ms1524 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 507; int n, a[maxn], cnt[maxn*maxn], s = 0; bitset<maxn*maxn> f, tmp; vector<int> ans; int main() { // freopen("test.INP","r",stdin); scanf("%d",&n); for (int i = 1; i <= n; ++i) scanf("%d",&a[i]), s += a[i]; if (s % 2) return puts("0"), 0; f[0] = 1; for (int i = 1; i <= n; ++i) tmp = f, tmp <<= a[i], f |= tmp; if (!f[s / 2]) return puts("0"), 0; for (int i = 1; i <= n; ++i) { s -= a[i]; for (int j = 1; j <= s; ++j) f[j] = 0; for (int j = 1; j <= n; ++j) if (j != i) tmp = f, tmp <<= a[j], f |= tmp; for (int j = 0; j <= s; ++j) if (f[j]) cnt[abs(s - 2*j)] += f[j]; s += a[i]; } for (int i = 0; i <= s; ++i) if (cnt[i] == 2*n) ans.push_back(i); printf("%d\n",ans.size()); for (auto v: ans) printf("%d ",v); return 0; }

Compilation message (stderr)

bootfall.cpp: In function 'int main()':
bootfall.cpp:36:29: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
     printf("%d\n",ans.size());
                   ~~~~~~~~~~^
bootfall.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
bootfall.cpp:15:51: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (int i = 1; i <= n; ++i) scanf("%d",&a[i]), s += 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...