Submission #566335

#TimeUsernameProblemLanguageResultExecution timeMemory
566335Abdulmohsen1284Bootfall (IZhO17_bootfall)C++14
6 / 100
416 ms262144 KiB
#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[20000]; long long occ[20000],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; vector <int> 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])<=20000){ plc[yes[j]+a[i]]=true; yes.push_back(yes[j]+a[i]); } } } //cout<<"HI"<<endl; if(plc[sum/2]&&sum%2==0) { for(int k=0;k<n;k++) { sum-=a[k]; for(int i=0;i<=20000;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])<=20000){ 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||oth>=20000) continue; if(plc[i]){ occ[oth]++; //cout<<oth<<" "; } } //cout<<endl; sum+=a[k]; } } for(int i=1;i<=20000;i++) { if(occ[i]==n){ //cout<<"???"<<endl; h.push_back(i); } } cout<<h.size()<<"\n"; for(auto i : h) cout<<i<<" "; }

Compilation message (stderr)

bootfall.cpp: In function 'int main()':
bootfall.cpp:43:23: warning: iteration 20000 invokes undefined behavior [-Waggressive-loop-optimizations]
   43 |                 plc[i]=false;
      |                 ~~~~~~^~~~~~
bootfall.cpp:42:26: note: within this loop
   42 |             for(int i=0;i<=20000;i++)
      |                         ~^~~~~~~
bootfall.cpp:43:23: warning: 'void* __builtin_memset(void*, int, long unsigned int)' forming offset 20000 is out of the bounds [0, 20000] of object 'plc' with type 'bool [20000]' [-Warray-bounds]
   43 |                 plc[i]=false;
      |                 ~~~~~~^~~~~~
bootfall.cpp:9:6: note: 'plc' declared here
    9 | bool plc[20000];
      |      ^~~
#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...