jakaria_hossain

codeforces - even array

Jun 18th, 2020
941
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define fast()(ios_base::sync_with_stdio(0),cin.tie(NULL));
  5. int main()
  6. {
  7.     fast()
  8.     ll t;
  9.     cin>>t;
  10.     while(t--)
  11.     {
  12.         ll n;
  13.         cin>>n;
  14.         ll ara[n+1],i;
  15.         for(i=0;i<n;i++)cin>>ara[i];
  16.         ll wo=0,we=0;
  17.         for(i=0;i<n;i++)
  18.         {
  19.             if(i%2==0 && ara[i]%2!=0)we++;
  20.             if(i%2==1 && ara[i]%2!=1)wo++;
  21.         }
  22.         if(we==wo)cout<<we<<endl;
  23.         else cout<<"-1"<<endl;
  24.     }
  25. }
RAW Paste Data