이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include"bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class x>
using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
bool plc[300000];
long long occ[600000],a[505];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
long long n,sum=0;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>a[i];
sum+=a[i];
}
plc[0]=true;
set <long long> h;
vector <int> yes;
yes.push_back(0);
for(int i=0;i<n;i++)
{
for(int j=yes.size()-1;j>=0;j--)
{
if(plc[yes[j]+a[i]]!=true||(yes[j]+a[i])<=250000){
plc[yes[j]+a[i]]=true;
yes.push_back(yes[j]+a[i]);
}
}
}
//cout<<"HI"<<endl;
if(plc[sum/2])
{
for(int k=0;k<n;k++)
{
sum-=a[k];
for(int i=0;i<=250000;i++)
plc[i]=false;
plc[0]=true;
yes.clear();
yes.push_back(0);
for(int i=0;i<n;i++)
{
if(i==k)
continue;
for(int j=yes.size()-1;j>=0;j--)
{
if(plc[yes[j]+a[i]]!=true||(yes[j]+a[i])<=250000){
plc[yes[j]+a[i]]=true;
yes.push_back(yes[j]+a[i]);
}
}
}
//cout<<"HELLO"<<endl;
for(int i=0;i<=sum;i++)
{
long long oth=i-(sum-i);
if(oth<=0)
continue;
if(plc[i]){
occ[oth]++;
//cout<<oth<<" ";
}
}
//cout<<endl;
sum+=a[k];
}
}
for(int i=1;i<=500000;i++)
{
if(occ[i]==n){
//cout<<"???"<<endl;
h.insert(i);
}
}
h.erase(0);
cout<<h.size()<<"\n";
for(auto i : h)
cout<<i<<" ";
}
# | 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... |