이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define N 1000005
bitset<501> in[250001];
bitset<250001> can;
int a[505];
int cnt[505];
int ans[250005];
vector<int> v;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, s = 0;
cin>>n;
for(int i = 1; i <= n; ++i){
cin>>a[i];
cnt[a[i]]++;
s += a[i];
}
can[0] = 1;
for(int i = 1; i <= 500; ++i){
for(int j = 1; j < cnt[i]; ++j){
can |= can << i;
}
}
for(int i = 1; i <= 500; ++i){
if(!cnt[i]) continue;
for(int j = s - i; j >= 0; --j){
if(can[j]){
bitset<501> t = in[j];
t[i] = 1;
if(!can[j + i]){
in[j + i] = t;
can[j + i] = 1;
} else {
in[j + i] &= t;
}
}
}
}
if((s & 1) || !can[s / 2]){
cout<<0;
return 0;
}
for(int i = 1; i <= 500; ++i){
if(cnt[i]){
for(int j = 1; j <= s; ++j){
if(can[j] && in[j][i] == 0){
int q = j * 2 + i - s;
if(q <= 0) continue;
ans[q] += cnt[i];
}
}
}
}
for(int i = 1; i <= 250000; i++){
if(ans[i] == n){
v.push_back(i);
}
}
cout<<v.size()<<'\n';
for(auto& x : v)
cout<<x<<' ';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |