Submission #975349

#TimeUsernameProblemLanguageResultExecution timeMemory
97534912345678Bootfall (IZhO17_bootfall)C++17
65 / 100
1024 ms13540 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") const int nx=505, kx=250005; int n, a[nx], sm; bitset<kx> dp[nx]; vector<int> res; bool valid(int x) { for (int i=1; i<=n; i++) if (((sm-a[i]+x)%2)||(!dp[i][(sm-a[i]+x)/2])) return 0; return 1; } int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n; for (int i=1; i<=n; i++) cin>>a[i], sm+=a[i]; for (int i=0; i<=n; i++) dp[i][0]=1; for (int i=1; i<=n; i++) dp[0]=dp[0]|(dp[0]<<a[i]); for (int i=1; i<=n; i++) for (int j=1; j<=n; j++) if (j!=i) dp[i]=dp[i]|(dp[i]<<a[j]); if ((sm%2)||!dp[0][sm/2]) return cout<<0, 0; for (int i=1; i<kx; i++) if (valid(i)) res.push_back(i); cout<<res.size()<<'\n'; for (auto x:res) cout<<x<<' '; } /* 4 1 3 1 5 */
#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...