답안 #566484

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
566484 2022-05-22T10:58:28 Z Uzouf Bootfall (IZhO17_bootfall) C++14
0 / 100
1 ms 512 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#include "xylophone.h"
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl "\n"
int mod=67289407956;//1e9+7;
const int N=505;//2e5+5;
const int M=250005;
template<class x>
using ordered_multiset = tree<x, null_type,less_equal<x>, rb_tree_tag,tree_order_statistics_node_update>;

int n,sum;
int v[N],dp[N],kk[N];
vector<int> ans;

void remove(int nm) {
  for (int j=nm;j<=M;j++) {
    dp[j]-=dp[j-nm];
    if (dp[j]>=mod) dp[j]%=mod;
  }
}

void add(int nm) {
  for (int j=M;j>=nm;j--) {
    dp[j]+=dp[j-nm];
    if (dp[j]>=mod) dp[j]%=mod;
  }
}

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen(".in", "r", stdin); freopen(".out", "w", stdout);

    cin>>n;
    for (int i=0;i<n;i++) {
      cin>>v[i];
      sum+=v[i];
    }

    dp[0]=1;
    for (int i=0;i<n;i++) {
      for (int j=M;j>=v[i];j--) {
        dp[j]+=dp[j-v[i]];
        if (dp[j]>=mod) dp[j]%=mod;
      }
    }

    if (dp[sum/2]==0 || sum%2!=0) {
      cout<<0;
      return 0;
    }

    for (int i=1;i<=sum;i++) {
      kk[i]=1;
    }

    for (int i=0;i<n;i++) {
      remove(v[i]);
      for (int j=1;j<=sum;j++) {
        int nw=sum-v[i]+j;
        if (nw/2<j) {kk[j]=0; continue;}
        if (dp[(nw/2)-j]==0 || (j+v[i])%2!=0) kk[j]=0;
      }
      add(v[i]);
    }

    for(int i=1;i<=M;i++) {
      if (kk[i]==1) ans.push_back(i);
    }

    cout<<ans.size()<<endl;
    for (int i:ans) cout<<i<<' ';
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 512 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 512 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 512 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 512 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 512 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 512 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -