Advertisement
silentkiler029

cf-1367-B

Jun 16th, 2020
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.23 KB | None | 0 0
  1. /*  BISMILLAHIR-RAHMANIR-RAHIM
  2.  ____________________________________
  3. |                                    |
  4. |       SHANTO_SUST_SWE-19_029       |
  5. |____________________________________|
  6. */
  7.  
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <math.h>
  11. #include <stdlib.h>
  12. #include <time.h>
  13.  
  14. #define debug 1
  15.  
  16. int main()
  17. {
  18.     int t;
  19.     scanf("%d", &t);
  20.     int n;
  21.     int i, even, odd, count;
  22.  
  23.     while(t--){
  24.         scanf("%d", &n);
  25.         int ara[n];
  26.  
  27.         even  = 0, odd = 0, count = 0;
  28.  
  29.         for(i = 0; i < n; i++){
  30.             scanf("%d", &ara[i]);
  31.             if(ara[i] % 2 == 0) even++;
  32.             else odd++;
  33.         }
  34.  
  35.         if(n % 2 == 0){
  36.             if(even == odd){
  37.                 for(i = 0; i < n; i++){
  38.                     if(i % 2 != ara[i] % 2) count++;
  39.                 }
  40.                 printf("%d\n", count / 2);
  41.             }
  42.             else printf("-1\n");
  43.         }
  44.         else{
  45.             if(even == odd + 1){
  46.                 for(i = 0; i < n; i++){
  47.                     if(i % 2 != ara[i] % 2) count++;
  48.                 }
  49.                 printf("%d\n", count / 2);
  50.             }
  51.             else printf("-1\n");
  52.         }
  53.     }
  54.  
  55.  
  56.     return 0;
  57. }
  58.  
  59. //ALHAMDULILLAH
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement