Submission #366144

#TimeUsernameProblemLanguageResultExecution timeMemory
366144nicolaalexandraBootfall (IZhO17_bootfall)C++14
0 / 100
4 ms6252 KiB
#include <bits/stdc++.h> #define DIM 502 using namespace std; bool dp_left[DIM][DIM*DIM],dp_right[DIM][DIM*DIM],dp[DIM]; int v[DIM],f[DIM*DIM]; vector <int> sol,w,w2; int n,i,j,sum_total; int main (){ //ifstream cin ("date.in"); //ofstream cout ("date.out"); cin>>n; for (i=1;i<=n;i++){ cin>>v[i]; sum_total += v[i]; } if (sum_total % 2){ cout<<"0"; return 0; } dp[0] = 1; for (i=1;i<=n;i++){ for (j=sum_total-v[i];j>=0;j--){ if (dp[j]) dp[j+v[i]] = 1; } } if (!dp[sum_total/2]){ cout<<"0"; return 0; } dp_left[0][0] = 1; for (i=1;i<=n;i++){ memcpy (dp_left[i],dp_left[i-1],sizeof dp_left[i-1]); for (j=sum_total-v[i];j>=0;j--){ if (dp_left[i][j]) dp_left[i][j+v[i]] = 1; } } dp_right[n+1][0] = 1; for (i=n;i;i--){ memcpy (dp_right[i],dp_right[i+1],sizeof dp_right[i+1]); for (j=sum_total-v[i];j>=0;j--){ if (dp_right[i][j]) dp_right[i][j+v[i]] = 1; } } for (i=1;i<=n;i++){ w.clear(); w2.clear(); for (int j=0;j<=sum_total;j++){ if (dp_left[i-1][j]) w.push_back(j); if (dp_right[i+1][j]) w2.push_back(j); } memset (dp,0,sizeof dp); for (auto it : w) for (auto it2 : w2) dp[it+it2] = 1; int sum = sum_total - v[i]; for (j=1;j<=sum_total;j++){ if ( (sum + j)%2 ) continue; int val = (sum + j)/2; /// exista suma asta? if (dp[val-j]) f[j]++; } } for (i=1;i<=sum_total;i++){ if (f[i] == n) sol.push_back(i); } cout<<sol.size()<<"\n"; for (auto it : sol) cout<<it<<" "; return 0; }
#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...