Saleh127

CF 1367B

Jun 16th, 2020
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define test int t; cin>>t; while (t--)
  4. #define ll long long int
  5. #define Faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  6. int main()
  7. {
  8. Faster
  9.  
  10. test
  11. {
  12. ll n,a[10000],c=0,d=0,e=0,f,i,j,k,l;
  13. cin>>n;
  14. for(i=1;i<=n;i++)
  15. {
  16. cin>>a[i];
  17. if(a[i]%2==1) d++;
  18. else e++;
  19. }
  20. if(n%2==0 && e==d)
  21. {
  22. for(i=1;i<=n;i++)
  23. {
  24. if(i%2==1 && a[i]%2==1)
  25. {
  26. c++;
  27. }
  28. else if(i%2==0 && a[i]%2==0)
  29. {
  30. c++;
  31. }
  32. }
  33. cout<<c/2<<endl;
  34. }
  35. else if(n%2==1 && e-d==1)
  36. {
  37. for(i=0;i<n;i++)
  38. {
  39. if(i%2==0 && a[i]%2==0)
  40. {
  41. c++;
  42. }
  43. else if(i%2==1 && a[i]%2==1)
  44. {
  45. c++;
  46. }
  47. }
  48. cout<<c/2<<endl;
  49. }
  50. else cout<<-1<<endl;
  51. }
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment