Advertisement
Zeinab_Hamdy

F

Oct 21st, 2022
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.26 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. #define ull unsigned long long
  4. #define nl cout<<"\n";
  5. #define sp cout<<" ";
  6. #define sz(x) x.size()
  7. #define NumOfDigit(w) log10(w) + 1
  8. #define fill(arr, val)  memset(arr, val , sizeof(arr))
  9. #define PI 3.141592654
  10. #define ceil(w, m) (((w) / (m)) + ((w) % (m) ? 1 : 0))
  11. #define all(v) v.begin(), v.end()
  12. #define rall(v) v.rbegin(), v.rend()
  13. #define fi first
  14. #define se second
  15. #define cin(v) for (auto&i:v) cin >> i;
  16. #define cout(v) for (auto&i:v) cout << i << " ";
  17. #define fixed(n) fixed << setprecision(n)
  18. #define MOD  1000000007
  19. using namespace std;
  20.  
  21. void zainab_hamdy(){
  22.     ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  23.     //freopen("filename.in" , "r" ,stdin);
  24. #ifndef ONLINE_JUDGE
  25.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  26. #endif
  27. }
  28. /*#include <ext/pb_ds/assoc_container.hpp
  29. #include <ext/pb_ds/tree_policy.hpp>
  30.  
  31. using namespace __gnu_pbds;
  32.  
  33. template <typename K, typename V, typename Comp = std::less<K>>
  34. using ordered_map = tree<K, V, Comp, rb_tree_tag, tree_order_statistics_node_update>;
  35. template <typename K, typename Comp = std::less<K>>
  36. using ordered_set = ordered_map<K, null_type, Comp>;
  37.  
  38. template <typename K, typename V, typename Comp = std::greater_equal<K>>
  39. using ordered_multimap = tree<K, V, Comp, rb_tree_tag, tree_order_statistics_node_update>;
  40. template <typename K, typename Comp = std::greater_equal<K>>
  41. using ordered_multiset = ordered_multimap<K, null_type, Comp>;
  42.  
  43. */
  44. bool prime(ll n){
  45.     if(n==2 || n==3) return true;
  46.     if(n<2 || n%2==0  ) return false;
  47.     for(int i=3;i<=sqrt(n);i+=2)   if(n%i==0) return false;
  48.     return true;
  49. }
  50.  
  51.  
  52. void isAccepted(){
  53.  
  54. int n ; cin >> n ;
  55. ll odd=0, even=0 , x ;
  56. for(int i=0; i<n ;i++){    
  57.     cin >> x ;
  58.     if(x&1) odd++ ;
  59.     else even ++;
  60. }
  61.  
  62. if (even&1 and odd&1 )
  63. cout << -1 ;
  64.  
  65. else if(even==0 or odd==0)
  66. cout << 0;
  67.  
  68. else if( !even&1  and !odd&1)
  69. cout << min(even/2 , odd/2);
  70.  
  71. else if (even&1==0)
  72. cout<< even/2 ;
  73.  
  74. else
  75. cout << odd/2 ;
  76.  
  77.  
  78. nl
  79.  
  80. }
  81. int main(){
  82.       //        zainab_hamdy();
  83.            
  84.     int testCase=1;  // one test case
  85.        cin >> testCase ;      
  86.  while(testCase--)
  87.         isAccepted();  // my code
  88.        
  89.     return 0;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement