Submission #342558

#TimeUsernameProblemLanguageResultExecution timeMemory
342558katearimaBootfall (IZhO17_bootfall)C++14
100 / 100
460 ms3556 KiB
#include <bits/stdc++.h> using namespace std; const int N=505; int n, a[N], sums[N*N+1], mx, num[N*N]; vector<int> ans; void Add(int x){ mx+=x; for(int j=mx; j>=x; j--){ sums[j]+=sums[j-x]; } } void Delete(int x){ for(int j=x; j<=mx; j++){ sums[j]-=sums[j-x]; } mx-=x; } main(){ cin>>n; sums[0]=1; for(int i=0; i<n; i++){ cin>>a[i]; Add(a[i]); } if(sums[mx/2]==0){ cout<<"0"<<endl; return 0; } for(int i=0; i<n; i++){ vector<bool> v(mx, false); Delete(a[i]); for(int j=0; j<=mx; j++){ if(sums[j]==0) continue; int k=abs(mx-2*j); if(!v[k]){ num[k]++; v[k]=true; } } Add(a[i]); } for(int i=0; i<=mx; i++){ if(num[i]==n) ans.push_back(i); } cout<<ans.size()<<endl; for(int i=0; i<ans.size(); i++){ cout<<ans[i]<<" "; } }

Compilation message (stderr)

bootfall.cpp:21:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   21 | main(){
      |      ^
bootfall.cpp: In function 'int main()':
bootfall.cpp:50:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     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...