Submission #39849

# Submission time Handle Problem Language Result Execution time Memory
39849 2018-01-21T21:03:40 Z igzi Bootfall (IZhO17_bootfall) C++14
0 / 100
2 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> v,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<=s;i++){
            for(j=0;j<=s;j++){
        tmp[j]=0;
    }
    for(j=0;j<=s;j++){
        tmp[j]+=b[j];
        tmp[j+a[i]]-=tmp[j];
    }
    int x;
    for(x=0;x<=s;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=0;i<=s;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++){
                  ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 4016 KB Output is correct
2 Correct 0 ms 4016 KB Output is correct
3 Correct 0 ms 4016 KB Output is correct
4 Runtime error 2 ms 4016 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 4016 KB Output is correct
2 Correct 0 ms 4016 KB Output is correct
3 Correct 0 ms 4016 KB Output is correct
4 Runtime error 2 ms 4016 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 4016 KB Output is correct
2 Correct 0 ms 4016 KB Output is correct
3 Correct 0 ms 4016 KB Output is correct
4 Runtime error 2 ms 4016 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 4016 KB Output is correct
2 Correct 0 ms 4016 KB Output is correct
3 Correct 0 ms 4016 KB Output is correct
4 Runtime error 2 ms 4016 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 4016 KB Output is correct
2 Correct 0 ms 4016 KB Output is correct
3 Correct 0 ms 4016 KB Output is correct
4 Runtime error 2 ms 4016 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 4016 KB Output is correct
2 Correct 0 ms 4016 KB Output is correct
3 Correct 0 ms 4016 KB Output is correct
4 Runtime error 2 ms 4016 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -