Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void boostear()
  5. {
  6. ios_base::sync_with_stdio(false);
  7. cin.tie(0);
  8. cout.tie(0);
  9. }
  10.  
  11. void files()
  12. {
  13. freopen("input.txt", "r", stdin); // redirects standard input
  14. freopen("output.txt", "w", stdout); // redirects standard output
  15. }
  16.  
  17. int main()
  18. {
  19. boostear();
  20.  
  21. int n;
  22. cin >> n;
  23.  
  24. if(n==1)
  25. {
  26. cout << 1;
  27. return 0;
  28. }
  29. else if(n==2)
  30. {
  31. cout << 0;
  32. return 0;
  33. }
  34.  
  35. vector<int> c(n);
  36. for(int i=0; i<n; i++)
  37. cin >> c[i];
  38.  
  39. vector<int> odd(n), even(n);
  40. even[0]=0;
  41. if(n>2)
  42. odd[0]=c[0], odd[1]=odd[0];
  43.  
  44. for(int i=2; i<n; i+=2)
  45. odd[i]=odd[i-1]+c[i], odd[i+1]=odd[i];
  46. for(int i=1; i<n; i+=2)
  47. even[i]=even[i-1]+c[i], even[i+1]=even[i];
  48.  
  49. int res=0;
  50. if(odd[n-1]-c[0] == even[n-1])
  51. res++;
  52. if(n%2 != 0)
  53. if(odd[n-1]-c[n-1] == even[n-1])
  54. res++;
  55. else if(n%2 == 0)
  56. if(even[n-1]-c[n-1] == odd[n-1])
  57. res++;
  58.  
  59. for(int i=1; i<n-1; i++)
  60. {
  61. int suma1=odd[i-1]+(even[n-1]-even[i]);
  62. int suma2=even[i-1]+(odd[n-1]-odd[i]);
  63. if(suma1==suma2)
  64. res++;
  65. }
  66.  
  67. cout << res;
  68.  
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement