답안 #144033

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
144033 2019-08-15T17:56:35 Z The_Wolfpack Bootfall (IZhO17_bootfall) C++14
0 / 100
7 ms 1272 KB
#include <bits/stdc++.h>
using namespace std;
const int NMAX=502;
const int KMAX=502*502;

int n,a[NMAX],dp[KMAX],moze[KMAX];

int main()
{
    ios_base::sync_with_stdio(false);
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    int sum=0;
    for(int i=1;i<=n;i++) sum+=a[i];
    dp[0]=1;
    for(int i=1;i<=n;i++)
    {
        for(int j=KMAX-1;j>=0;j--)
        {
            if(j-a[i]>=0) dp[j]+=dp[j-a[i]];
        }
    }
    //for(int i=0;i<20;i++) cout<<dp[i]<<endl;
    if(sum&1 || !dp[sum/2])
    {
        cout<<"0"<<endl;
        return 0;
    }
    vector<int> ans;
    for(int i=1;i<=n;i++)
    {
        for(int j=KMAX-1;j>=0;j--)
        {
            if(j-a[i]>=0) dp[j]-=dp[j-a[i]];
        }
        for(int j=1;j<=sum-a[i];j++)
        {
            if(!dp[j]) continue;
            if(sum-j-a[i] > j)
            {
                moze[sum-2*j-a[i]]++;
                //ans.push_back(sum-2*j-a[i]);
            }
            else
            {
                if(2*j+a[i]-sum>0) moze[2*j+a[i]-sum]++;
            }
        }
        for(int j=KMAX-1;j>=0;j--)
        {
            if(j-a[i]>=0) dp[j]+=dp[j-a[i]];
        }
    }
    /*sort(ans.begin(),ans.end());
    ans.erase(unique(ans.begin(), ans.end()), ans.end());*/
    for(int i=1;i<=KMAX-1;i++) if(moze[i]==n) ans.push_back(i);
    cout<<ans.size()<<endl;
    for(int i:ans) cout<<i<<" ";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 1272 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 1272 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 1272 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 1272 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 1272 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 1272 KB Output isn't correct
2 Halted 0 ms 0 KB -