fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int solve(vector<int>& a){
  5. int n = a.size();
  6. int totalSum = accumulate(a.begin(),a.end(),0);
  7. if(totalSum%2!=0)return 0;
  8. int lhs = 0;
  9. int c=0;
  10. for(int i=0;i<n-1;i++){
  11. lhs += a[i];
  12. if(lhs == totalSum/2)c++;
  13. }
  14. return c;
  15. }
  16.  
  17. int main() {
  18. int n;
  19. cin>>n;
  20.  
  21. vector<int>a(n);
  22. for(int i=0;i<n;i++){
  23. cin>>a[i];
  24. }
  25.  
  26. cout << solve(a);
  27. return 0;
  28. }
Success #stdin #stdout 0s 5292KB
stdin
5
1 0 0 1 0
stdout
3