답안 #39848

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
39848 2018-01-21T20:26:49 Z igzi Bootfall (IZhO17_bootfall) C++14
0 / 100
0 ms 3016 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];
vector <int> v,ans;
bool proveri(int x,int p){
if(s+x-3*a[p]<0) return b[(s+x-a[i])/2];
return b[(s+x-a[i])/2]>b[(s+x-3*a[i])/2];
}
bool moze(int x){
for(int i=0;i<n;i++){
    if((s+x-a[i])%2 || !proveri(x,i)) return false;
}
return true;
}

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;
    }
    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++){
            if(moze(i)) 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:42:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(i=0;i<ans.size();i++){
                  ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3016 KB Output is correct
2 Incorrect 0 ms 3016 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3016 KB Output is correct
2 Incorrect 0 ms 3016 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3016 KB Output is correct
2 Incorrect 0 ms 3016 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3016 KB Output is correct
2 Incorrect 0 ms 3016 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3016 KB Output is correct
2 Incorrect 0 ms 3016 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3016 KB Output is correct
2 Incorrect 0 ms 3016 KB Output isn't correct
3 Halted 0 ms 0 KB -