Submission #675655

#TimeUsernameProblemLanguageResultExecution timeMemory
675655LucaIlieBootfall (IZhO17_bootfall)C++17
100 / 100
402 ms1948 KiB
#include <bits/stdc++.h> using namespace std; const int maxN = 500; const int maxS = maxN * maxN; int v[maxN + 1], dp[maxS + 1]; bitset<maxS + 1> tim, timTemp; int main() { int n, s = 0; cin >> n; for ( int i = 1; i <= n; i++ ) cin >> v[i], s += v[i]; dp[0] = 1; for ( int i = 1; i <= n; i++ ) { for ( int j = s; j >= v[i]; j-- ) dp[j] += dp[j - v[i]]; } if ( s % 2 != 0 || !dp[s / 2] ) { cout << 0; return 0; } for ( int i = 0; i <= s; i++ ) tim[i] = true; for ( int r = 1; r <= n; r++ ) { for ( int j = v[r]; j <= s; j++ ) dp[j] -= dp[j - v[r]]; timTemp.reset(); for ( int i = 0; i <= s; i++ ) { if ( dp[i] ) timTemp[abs( s - v[r] - i - i )] = true; } tim &= timTemp; for ( int j = s; j >= v[r]; j-- ) dp[j] += dp[j - v[r]]; } tim[0] = false; cout << tim.count() << "\n"; for ( int i = 0; i <= s; i++ ) { if ( tim[i] ) cout << i << " "; } return 0; }
#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...