Submission #1128046

#TimeUsernameProblemLanguageResultExecution timeMemory
1128046Noproblem29Bootfall (IZhO17_bootfall)C++20
100 / 100
620 ms17464 KiB
#include<bits/stdc++.h> using namespace std; #ifndef BADGNU #pragma GCC target("sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #endif #pragma GCC optimize("Ofast,unroll-loops,fast-math,O3") #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ll long long #define int ll #define ld long double #define y1 cheza mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; template<class T> using ordered_multiset = tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>; const int N=510; const int M=500*500+10; const int B=447; const int mod=998244353; const ll INF=1e18; const int dx[]={1,-1,0,0}; const int dy[]={0,0,1,-1}; const double eps=1e-6; int n; int a[N]; bitset<M>dp; bitset<M>f[N]; void test(){ cin>>n; int sum=0; for(int i=1;i<=n;i++){ cin>>a[i]; sum+=a[i]; } sort(a+1,a+n+1); dp[0]=1; for(int i=1;i<=n;i++){ f[i]=dp; for(int j=i+1;j<=n;j++){ f[i]|=(f[i]<<a[j]); } dp|=(dp<<a[i]); } int mask=0; for(int i=1;i<=n;i++){ if(a[i]%2){ mask|=1; } else{ mask|=2; } } if(sum%2||dp[sum/2]==0||mask==3){ cout<<0<<'\n'<<'\n'; return; } vector<int>v; for(int j=mask;j<=250000;j+=2){ v.push_back(j); for(int i=1;i<=n;i++){ int cur=(sum-a[i]+j); if(cur%2){ v.pop_back(); break; } cur/=2; if(f[i][cur]){ continue; } if(cur>=j&&f[i][cur-j]){ continue; } v.pop_back(); break; } } cout<<v.size()<<'\n'; for(auto i:v){ cout<<i<<' '; } cout<<'\n'; } /* */ signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); // cout.tie(nullptr); int t2=1; // cin>>t2; for(int i=1;i<=t2;i++){ test(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...