Ankit_132

B

Sep 27th, 2023
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. #define ll     long long
  7. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  8.  
  9. int main()
  10. {
  11.     _test
  12.     {
  13.         int n, k;
  14.         cin>>n>>k;
  15.  
  16.         vector<int> a(n);
  17.         for(auto &e: a)     cin>>e;
  18.  
  19.         int MOD = 1e9 + 7;
  20.         vector<ll int> fact(n+1);
  21.         fact[0] = fact[1] = 1;
  22.  
  23.         for(ll int i=2; i<=n; i++)
  24.             (fact[i] = i*fact[i-1]) %= MOD;
  25.  
  26.         int e=0, o=0;
  27.  
  28.         for(auto x: a)
  29.         {
  30.             e += (x%2 == 1);
  31.             o += (x%2 == 0);
  32.         }
  33.        
  34.         if(k == 1)
  35.         {
  36.             if(e > o)       swap(e, o);
  37.  
  38.             if(e == o)
  39.             {
  40.                 ll int ans = 1;
  41.                 (ans *= fact[e]) %= MOD;
  42.                 (ans *= fact[o]) %= MOD;
  43.                 (ans *= 2) %= MOD;
  44.  
  45.                 cout<<ans<<"\n";
  46.             }
  47.             else if(e+1 == o)
  48.             {
  49.                 ll int ans = 1;
  50.                 (ans *= fact[e]) %= MOD;
  51.                 (ans *= fact[o]) %= MOD;
  52.  
  53.                 cout<<ans<<"\n";
  54.             }
  55.             else
  56.                 cout<<0<<"\n";
  57.         }
  58.         else if(e==n || o==n)
  59.             cout<<fact[n]<<"\n";
  60.         else
  61.             cout<<0<<"\n";
  62.     }
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment