Advertisement
Promi_38

cf 1367B

Sep 26th, 2021
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include<bits\stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int t;
  8.     scanf("%d", &t);
  9.     while(t--)
  10.     {
  11.         int n;
  12.         scanf("%d", &n);
  13.         int a[n], i;
  14.         for(i = 0; i < n; i++) scanf("%d", &a[i]);
  15.         int odd = 0, even = 0;
  16.         for(i = 0; i < n; i++)
  17.         {
  18.             if((a[i] % 2) != (i % 2))
  19.             {
  20.                 if(a[i] % 2 == 0) even++;
  21.                 else odd++;
  22.             }
  23.         }
  24.         if(even == odd) printf("%d\n", even);
  25.         else printf("-1\n");
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement