Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define _test int _TEST; cin>>_TEST; while(_TEST--)
- int main()
- {
- _test
- {
- int n, k;
- cin>>n>>k;
- vector<int> a(n);
- for(auto &e: a) cin>>e;
- int MOD = 1e9 + 7;
- vector<ll int> fact(n+1);
- fact[0] = fact[1] = 1;
- for(ll int i=2; i<=n; i++)
- (fact[i] = i*fact[i-1]) %= MOD;
- int e=0, o=0;
- for(auto x: a)
- {
- e += (x%2 == 1);
- o += (x%2 == 0);
- }
- if(k == 1)
- {
- if(e > o) swap(e, o);
- if(e == o)
- {
- ll int ans = 1;
- (ans *= fact[e]) %= MOD;
- (ans *= fact[o]) %= MOD;
- (ans *= 2) %= MOD;
- cout<<ans<<"\n";
- }
- else if(e+1 == o)
- {
- ll int ans = 1;
- (ans *= fact[e]) %= MOD;
- (ans *= fact[o]) %= MOD;
- cout<<ans<<"\n";
- }
- else
- cout<<0<<"\n";
- }
- else if(e==n || o==n)
- cout<<fact[n]<<"\n";
- else
- cout<<0<<"\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment