Submission #229887

#TimeUsernameProblemLanguageResultExecution timeMemory
229887pedroslreyBootfall (IZhO17_bootfall)C++14
65 / 100
794 ms3244 KiB
#pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; using lli = long long int; #define debug(args...) fprintf(stderr, args) #define pb push_back #define fi first #define se second #define all(xs) xs.begin(), xs.end() const int INF = 1e9; int dp[510*510]; int xs[510]; int marc[510*510]; inline void add(int i, int s) { for (int k = s; k >= 0; --k) { lli tmp = 1LL*dp[k + xs[i]] + dp[k]; dp[k + xs[i]] = tmp%INF; } } inline void sub(int i, int s) { for (int k = 0; k <= s; ++k) { lli tmp = 1LL*dp[k + xs[i]] - dp[k]; dp[k + xs[i]] = tmp%INF; } } void init_dp(int n, int s) { dp[0] = 1; for (int i = 1; i <= n; ++i) add(i, s); } void solve(int n) { int s = 0; for (int i = 1; i <= n; ++i) s += xs[i]; init_dp(n, s); if (dp[s/2] == 0 || s%2 == 1) { printf("0\n"); return; } for (int i = 1; i <= n; ++i) { sub(i, s); for (int k = 1; k <= s; ++k) { if ((s - xs[i] + k)%2 == 1) marc[k] = 0; if (dp[(s - xs[i] - k)/2]) ++marc[k]; } add(i, s); } vector<int> ans; for (int k = 1; k <= s; ++k) if (marc[k] == n) ans.pb(k); printf("%d\n", (int) ans.size()); for (int a: ans) printf("%d ", a); printf("\n"); } int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &xs[i]); solve(n); }

Compilation message (stderr)

bootfall.cpp:2:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("O3")
 
bootfall.cpp:3:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("unroll-loops")
 
bootfall.cpp: In function 'int main()':
bootfall.cpp:77:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
bootfall.cpp:80:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &xs[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...