Submission #678389

# Submission time Handle Problem Language Result Execution time Memory
678389 2023-01-05T17:44:35 Z Ahmed57 Bootfall (IZhO17_bootfall) C++17
0 / 100
0 ms 212 KB
#include <bits/stdc++.h>

using namespace std;
long long dp[2*500*500+1];
long long mod = int(1e9+7);
bitset<2*500*500+1> su;
int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    int arr[n] , sum = 0;
    for(int i = 0;i<n;i++){
        cin>>arr[i];sum+=arr[i];
    }
    dp[0] = 1;
    for(int i = 0;i<n;i++){
        for(int j = 2*sum;j>=arr[i];j--){
            dp[j]+=dp[j-arr[i]];
            if(dp[j]>=1e18)dp[j]%=mod;
        }
    }
    if(sum%2||(!dp[sum/2])){
        cout<<"0";
        return 0;
    }
    for(int i = 1;i<=sum;i++){su[i] = 1;}
    for(int it = 0;it<n;it++){
        for(int j = arr[it];j<=2*sum;j++){
            dp[j]-=dp[j-arr[it]];
            dp[j]%=mod;
            if(dp[j]<0){dp[j]%=mod;dp[j]+=mod;dp[j]%=mod;}
        }
        for(int j = (arr[0]%2?1:2);j<=sum;j+=2){
            if((sum-arr[it]+j)%2){
                su[j] = 0;
                continue;
            }
            int ne = sum-arr[it]+j;
            int d = (dp[ne/2]>0);
            if(j<=ne/2)d|=(dp[(ne/2)-j]>0);
            if(d==0)su[j] = 0;
        }
        for(int j = 2*sum;j>=arr[it];j--){
            dp[j]+=dp[j-arr[it]];
            if(dp[j]>=1e18)dp[j]%=mod;
        }
    }
    cout<<su.count()<<"\n";
    for(int i = 1;i<=sum;i++)if(su[i])cout<<i<<" ";
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -