Submission #36136

#TimeUsernameProblemLanguageResultExecution timeMemory
36136aomeBootfall (IZhO17_bootfall)C++14
100 / 100
376 ms6972 KiB
#include <bits/stdc++.h> using namespace std; const int N = 505; int n, a[N], sum[N]; int f[2][N * N]; int g[N * N]; int cnt[N * N]; vector<int> res; int main() { ios::sync_with_stdio(false); cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i], sum[i] = sum[i - 1] + a[i]; } f[0][0] = 1; for (int i = 0; i < n; ++i) { bool x = i & 1; for (int j = 0; j <= sum[i]; ++j) { f[x ^ 1][j + a[i + 1]] += f[x][j]; f[x ^ 1][j] += f[x][j]; f[x][j] = 0; } } if (sum[n] & 1 || !f[n & 1][sum[n] / 2]) { cout << 0; return 0; } for (int i = 1; i <= n; ++i) { for (int j = 0; j <= sum[n]; ++j) { g[j] = f[n & 1][j]; if (j >= a[i]) g[j] -= g[j - a[i]]; } for (int j = 0; sum[n] - a[i] - j - j >= 0; ++j) { if (g[j]) cnt[sum[n] - a[i] - j - j]++; } } for (int i = 1; i <= sum[n]; ++i) { if (cnt[i] == n) res.push_back(i); } printf("%d\n", res.size()); for (int i = 0; i < res.size(); ++i) printf("%d ", res[i]); }

Compilation message (stderr)

bootfall.cpp: In function 'int main()':
bootfall.cpp:41:27: 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", res.size()); 
                           ^
bootfall.cpp:42:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < res.size(); ++i) printf("%d ", res[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...