Submission #672187

#TimeUsernameProblemLanguageResultExecution timeMemory
672187ReLiceBootfall (IZhO17_bootfall)C++14
100 / 100
235 ms5752 KiB
#include<bits/stdc++.h> using namespace std; #define endl "\n" #define ll long long #define ld long double #define int long long #define pb push_back #define sz size() #define fr first #define sc second void start(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } const ll N=1e5+1; const ll inf=1e9+7; ll dp[250001],used[250001]; main(){ start(); ll n,k,i,j,b,mx=-1; cin >> n; vector <ll> ans; ll sum=0,a[n]; for (i=0;i<n;i++) { cin>>a[i]; sum+=a[i]; } dp[0]++; for(i=0;i<n;i++) for(j=sum;j-a[i]>=0;j--) dp[j]+=dp[j-a[i]]; if(!dp[sum/2] || sum%2) { cout<<0; exit(0); } for (i=0;i<n;i++) { ll cur=sum-a[i]; for(j=a[i];j<=sum;j++) { dp[j]-=dp[j-a[i]]; } for(ll j=0;j<=cur/2;j++){ if(dp[j])used[cur-j*2]++; } for(ll j=sum;j>=a[i];j--){ dp[j]+=dp[j-a[i]]; } } for(ll i=0;i<=sum;i++) { if(used[i]==n) ans.pb(i); } cout<<ans.sz<<'\n'; for (auto i : ans) cout<<i<<' '; }

Compilation message (stderr)

bootfall.cpp:19:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   19 | main(){
      | ^~~~
bootfall.cpp: In function 'int main()':
bootfall.cpp:21:10: warning: unused variable 'k' [-Wunused-variable]
   21 |     ll n,k,i,j,b,mx=-1;
      |          ^
bootfall.cpp:21:16: warning: unused variable 'b' [-Wunused-variable]
   21 |     ll n,k,i,j,b,mx=-1;
      |                ^
bootfall.cpp:21:18: warning: unused variable 'mx' [-Wunused-variable]
   21 |     ll n,k,i,j,b,mx=-1;
      |                  ^~
#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...