Submission #1270428

#TimeUsernameProblemLanguageResultExecution timeMemory
1270428bobothenubchickBootfall (IZhO17_bootfall)C++20
100 / 100
235 ms5828 KiB
// Problem: B - first BRICK at stonewall // Contest: Virtual Judge - ABCDE4 // URL: https://vjudge.net/contest/748359#problem/B // Memory Limit: 1024 MB // Time Limit: 1000 ms // // Powered by CP Editor (https://cpeditor.org) # include <bits/stdc++.h> using namespace std; #define int long long int n,a[1000005],t,dp[1000005],cnt[1000005]; vector<int> res; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; t += a[i]; } dp[0] = 1; for (int i = 1; i <= n; i++) { for (int j = t; j >= a[i]; j--) { dp[j] += dp[j-a[i]]; } } // cout << t << " " << dp[t/2] << "\n"; if (t%2!=0 or !dp[t/2]) { cout << 0; return 0; } // cout << dp[3] << "\n"; for (int i = 1; i <= n; i++) { for (int j = a[i]; j <= t; j++) { dp[j] -= dp[j-a[i]]; } t -= a[i]; for (int j = 0; j <= t/2; j++) { // if (t-2*j==3) // { // cout << t << " "<<i << " " << j<< " " << dp[j] << "\n"; // } if (dp[j]) cnt[t-2*j]++; } t += a[i]; for (int j = t; j >= a[i]; j--) { dp[j] += dp[j-a[i]]; } } for (int i = 1; i <= t; i++) { if (cnt[i]==n) { res.push_back(i); } } cout << res.size() << "\n"; for (int i = 0; i < (int)res.size(); i++) { cout << 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...