답안 #472797

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
472797 2021-09-14T10:44:07 Z ogibogi2004 Bootfall (IZhO17_bootfall) C++14
0 / 100
15 ms 1228 KB
#include<bits/stdc++.h>
using namespace std;
const int MAXN=512;
int n,a[MAXN],sum=0;
bitset<2*MAXN*MAXN>b1,b2,b3,b4;
bitset<2*MAXN*MAXN>f;
bool check(int without,int with)
{
    f=0;
    f[0]=1;
    f[with]=1;
    int sum1=sum-a[without]+with;
    if(sum1%2==1)return false;
    for(int i=1;i<=n;i++)
    {
        if(i==without)continue;
        for(int j=sum1/2;j>=a[i];j--)
        {
            if(f[j-a[i]]==1)f[j]=1;
        }
        if(f[sum1/2])return true;
    }
    return false;
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++){cin>>a[i];sum+=a[i];}
    for(int i=0;i<MAXN*MAXN;i++)b1[i]=1;
    b1=0;
    b1[MAXN*MAXN]=1;
    for(int i=1;i<=n;i++)
    {
        b2=0;
        for(int j=0;j<2*MAXN*MAXN;j++)
        {
            if(b1[j]==0)continue;
            b2[j-a[i]]=1;
            b2[j+a[i]]=1;
        }
        b1=b2;
    }
    if(b1[MAXN*MAXN]==0)
    {
        cout<<"0\n";
        return 0;
    }
    b2=0;
    for(int i=0;i<2*MAXN*MAXN;i++)
    {
        if(b1[i]==0)continue;
        b2[abs(MAXN*MAXN-i)]=1;
    }
    b1=b2;
    /*for(int i=0;i<MAXN*MAXN;i++)
    {
        if(b1[i])cout<<i<<" ";
    }
    cout<<endl;
    cout<<endl;*/
    for(int i=0;i<MAXN*MAXN;i++)b3[i]=1;
    for(int i=1;i<=n;i++)
    {
        b4=0;
        for(int j=0;j<MAXN*MAXN;j++)
        {
            if(b1[j]==0)continue;
            int t=abs(j-a[i]);
            b4[t]=1;
        }
        /*for(int j=0;j<MAXN*MAXN;j++)
        {
            if(b4[j])cout<<j<<" ";
        }
        cout<<endl;*/
        b3&=b4;

        /*for(int j=0;j<MAXN*MAXN;j++)
        {
            if(b3[j])cout<<j<<" ";
        }
        cout<<endl;
        cout<<endl<<endl;*/
    }
    vector<int>ans,outp;
    for(int i=1;i<=sum;i++)
    {
        if(b3[i]==1)ans.push_back(i);
    }
    for(auto xd:ans)
    {
        bool flag=1;
        for(int i=1;i<=n;i++)
        {
            if(!check(i,xd))
            {
                flag=0;break;
            }
        }
        if(flag)outp.push_back(xd);
    }
    cout<<outp.size()<<endl;
    for(auto xd:outp)
    {
        cout<<xd<<" ";
    }
    cout<<endl;
    if(ans.size()>n)assert(false);
return 0;
}

Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:108:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  108 |     if(ans.size()>n)assert(false);
      |        ~~~~~~~~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 716 KB Output is correct
2 Runtime error 15 ms 1228 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 716 KB Output is correct
2 Runtime error 15 ms 1228 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 716 KB Output is correct
2 Runtime error 15 ms 1228 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 716 KB Output is correct
2 Runtime error 15 ms 1228 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 716 KB Output is correct
2 Runtime error 15 ms 1228 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 716 KB Output is correct
2 Runtime error 15 ms 1228 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -