Submission #39852

# Submission time Handle Problem Language Result Execution time Memory
39852 2018-01-21T21:12:17 Z igzi Bootfall (IZhO17_bootfall) C++14
0 / 100
5 ms 4016 KB
#include <bits/stdc++.h>
#define maxN 505
#define maxA 505

using namespace std;

int n,i,j,s=0,a[maxN],b[maxN*maxA],c[maxN*maxA],tmp[maxN];
vector <int> ans;

int main()
{
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a[i];
        s+=a[i];
    }
    for(i=0;i<=s;i++){
        b[i]=0;
        c[i]=0;
    }
    b[0]=1;
    for(i=0;i<n;i++){
        for(j=s;j>=0;j--){
            if(b[j]!=0) b[a[i]+j]+=b[j];
        }
    }
    if(s%2 || b[s/2]==0) cout<<0<<endl;
    else{
        for(i=0;i<n;i++){
            for(j=0;j<maxN*maxA;j++){
        tmp[j]=0;
    }
    for(j=0;j<maxN*maxA-a[i];j++){
        tmp[j]+=b[j];
        tmp[j+a[i]]-=tmp[j];
    }
    int x;
    for(x=0;x<=250000;x++){
    if(s-x-a[i]<0) break;
    if((s+x-a[i])%2==0 && tmp[(s-x-a[i])/2]>0) c[x]++;
        }
        }
        for(i=1;i<=250000;i++){
            if(c[i]==n) ans.push_back(i);
        }
        cout<<ans.size()<<endl;
        for(i=0;i<ans.size();i++){
            cout<<ans[i]<<" ";
        }
    }
    return 0;
}

Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:47:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(i=0;i<ans.size();i++){
                  ^
bootfall.cpp:31:17: warning: iteration 505u invokes undefined behavior [-Waggressive-loop-optimizations]
         tmp[j]=0;
                 ^
bootfall.cpp:30:22: note: containing loop
             for(j=0;j<maxN*maxA;j++){
                      ^
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 4016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 4016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 4016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 4016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 4016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 4016 KB Output isn't correct
2 Halted 0 ms 0 KB -