# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
672421 | Cutebol | Bootfall (IZhO17_bootfall) | C++17 | 83 ms | 3752 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
void fopn(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
#define Scaramouche ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0);
#define int long long
#define itn int
#define endl "\n"
#define ff first
#define ss second
const int N = 2e5 + 5 ;
const int mod = 1e9 + 7 ;
const int inf = 1e12 ;
int n , sum ;
int a[N] , dp[N] , vis[N] ;
void solve(){
cin >> n ;
for ( int i = 0 ; i < n ; i ++ ){
cin >> a[i] ;
sum += a[i] ;
}
dp[0] ++ ;
for ( int i = 0 ; i < n ; i ++ )
for( int j = sum ; j - a[i] >= 0 ; j -- ) dp[j] += dp[j-a[i]] ;
if ( !dp[sum/2] || sum % 2 ){
cout << 0 ;
return ;
}
for ( int i = 0 ; i < n ; i ++ ){
int cur = sum - a[i] ;
for ( int j = a[i] ; j <= sum ; j ++ )
dp[j] -= dp[j-a[i]] ;
for ( int j = 0 ; j <= cur/2 ; j ++ )
if ( dp[j] ) vis[cur-j*2] ++ ;
for ( int j = sum ; j >= a[i] ;j -- ) dp[j] += dp[j-a[i]] ;
}vector <int> ans ;
for ( int i = 0 ; i < sum + 1 ; i ++ ) if ( vis[i] == n ) ans.push_back(i) ;
cout <<
ans.size() << '\n' ;
for ( auto ti : ans ) cout << ti << ' ' ;
}
signed main(){
// fopn("blocks") ;
// Scaramouche ;
int t = 1 ;
// cin >> t ;
while ( t -- ) solve() ;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |