Submission #173231

#TimeUsernameProblemLanguageResultExecution timeMemory
173231DeD_TihoNBootfall (IZhO17_bootfall)C++14
65 / 100
979 ms6692 KiB
#pragma GCC optimize ("O3") #include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #define ff first #define ss second #define pb push_back #define mp make_pair #define ll long long #define ld long double #define all(a) a.begin(),a.end() #define ull unsigned long long #define endl '\n' #define y1 yaumru #define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define iter vector<int>::iterator using namespace std; using namespace __gnu_pbds; 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>; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); mt19937_64 rnd1(chrono::steady_clock::now().time_since_epoch().count()); //find_by_order //order_of_key const int N=500+1; const int inf=1e9+1e9; const int mod=1e9+7; const ld eps=1e-9; const int M=200000; const int M1=195000; int a[N]; bool used[N]; bitset<M1>dp[N]; bitset<M>dp1[N]; main () { ios; int n; cin>>n; for (int i=1;i<=n;++i){ cin>>a[i]; } if (n<=350){ int sum=0; bool c1=false; bool c2=false; for (int i=1;i<=n;++i){ sum+=a[i]; if (a[i]%2==1){ c1=true; } else { c2=true; } } if (c1 && c2){ cout<<0<<endl; exit(0); } if (sum%2==1){ cout<<0<<endl; exit(0); } for (int i=0;i<=n;++i){ if (i==0){ dp1[i][0]=1; for (int j=1;j<=n;++j){ if (j==i)continue; bitset<M>f=(dp1[i]<<a[j]); dp1[i]=(dp1[i]|f); } if (dp1[0][sum/2]==0){ cout<<0<<endl; exit(0); } } else { if (!used[a[i]]){ used[a[i]]=true; dp1[a[i]][0]=1; for (int j=1;j<=n;++j){ if (j==i)continue; bitset<M>f=(dp1[a[i]]<<a[j]); dp1[a[i]]=(dp1[a[i]]|f); } } } } vector<int>ans; for (int i=1;i<=M;++i){ bool cc=true; for (int j=1;j<=n;++j){ if ((sum-a[j]+i)%2==1){ cc=false; break; } if ((sum-a[j]+i)%2==0){ if (dp1[a[j]][(sum-a[j]+i)/2]==0){ cc=false; break; } } } if (cc)ans.pb(i); } cout<<(int)ans.size()<<endl; for (int i=0;i<ans.size();++i){ cout<<ans[i]<<' '; } } else { int sum=0; bool c1=false; bool c2=false; for (int i=1;i<=n;++i){ sum+=a[i]; if (a[i]%2==1){ c1=true; } else { c2=true; } } if (c1 && c2){ cout<<0<<endl; exit(0); } if (sum%2==1){ cout<<0<<endl; exit(0); } for (int i=0;i<=n;++i){ if (i==0){ dp[i][0]=1; for (int j=1;j<=n;++j){ if (j==i)continue; bitset<M1>f=(dp[i]<<a[j]); dp[i]=(dp[i]|f); } if (dp[0][sum/2]==0){ cout<<0<<endl; exit(0); } } else { if (!used[a[i]]){ used[a[i]]=true; dp[a[i]][0]=1; for (int j=1;j<=n;++j){ if (j==i)continue; bitset<M1>f=(dp[a[i]]<<a[j]); dp[a[i]]=(dp[a[i]]|f); } } } } vector<int>ans; for (int i=1;i<=M1;++i){ bool cc=true; for (int j=1;j<=n;++j){ if ((sum-a[j]+i)%2==1){ cc=false; break; } if ((sum-a[j]+i)%2==0){ if (dp[a[j]][(sum-a[j]+i)/2]==0){ cc=false; break; } } } if (cc)ans.pb(i); } cout<<(int)ans.size()<<endl; for (int i=0;i<ans.size();++i){ cout<<ans[i]<<' '; } } }

Compilation message (stderr)

bootfall.cpp:44:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main ()
       ^
bootfall.cpp: In function 'int main()':
bootfall.cpp:116:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i=0;i<ans.size();++i){
                      ~^~~~~~~~~~~
bootfall.cpp:184:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i=0;i<ans.size();++i){
                      ~^~~~~~~~~~~
#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...