3,[2,0,2]
2
可能的站法(1 2 3), (3 2 1)
3,[1,1,1]
0
不存在这样的站法
其中1<=n<=1000000, 0<=a_i<=1000000
class Solution { public: /** * * @param n int整型 * @param a int整型vector * @return int整型 */ int solve(int n, vector<int>& a) { const int M = 1e9+7; int s = 1, cnt[1000001]; memset(cnt, 0, sizeof(cnt)); for(int i=0;i<a.size();i++) cnt[a[i]]++; if(n&1){ for(int i=0;i<n;i++){ if(i==0){ if(cnt[0] != 1) return 0; }else{ if(((i&1) && cnt[i]!=0) || (!(i&1) && cnt[i]!=2)) return 0; if(!(i&1)) s = (s<<1)%M; } } }else{ for(int i=0;i<n;i++){ if(((i&1) && cnt[i]!=2) || (!(i&1) && cnt[i]!=0)) return 0; if(!(i&1)) s = (s<<1)%M; } } return s; } };
class Solution { public: int solve(int n, vector<int>& a) { vector<int> b(n); for (auto num: a) if (num < 0 || num >= n || num & 1 == n & 1 || b[num]++ == 2) return 0; for (int i = !(n & 1); i < n; i += 2) if ((i == 0 && b[i] != 1) || (i > 0 && b[i] != 2)) return 0; long long res = 1, base = 2, mod = 1000000007; while (n >>= 1) { if (n & 1) res = res * base % mod; base = base * base % mod; } return res; } };
class Solution { public: /** * * @param n int整型 * @param a int整型vector * @return int整型 */ const int M = 1000000007; int qpow(long long a, long long n) { long long res = 1; while (n) { if (n & 1) res = (res * a) % M; a = (a * a) % M; n >>= 1; //cout<< res<< " "<< a<< " "<< n<< endl; } return (int)res; } int solve(int n, vector<int>& a) { // write code here if (n<= 0) return 0; if (n==1) return (a[0] == 0); sort(a.begin(), a.end()); int now, start; if (n & 1) { if (a[0] != 0) return 0; now = 2; start = 1; } else { now = 1; start = 0; } while (start < a.size()) { if (a[start] != now || a[start+1] != now) return 0; start += 2; now += 2; } return qpow((long long)2, (long long)n/2); } };
class Solution { public: /** * * @param n int整型 * @param a int整型vector * @return int整型 */ static const int N = 1000001; int solve(int n, vector<int>& a) { // write code here const int MOD = 1000000007; int len = a.size(); int count[N] = {0}; int ans=1; for(auto &k : a) count[k]++; if(n%2==0){ for(int i=0;i<n;i++){ if(i%2==1 && count[i]!=2) return 0; if(i%2==0 && count[i]!=0) return 0; if(i%2==0) ans=ans*2%MOD; } } if(n%2==1){ for(int i=0;i<n;i++){ if(i==0){ if(count[0]!=1) return 0; }else{ if(i%2==1 && count[i]!=0) return 0; if(i%2==0 && count[i]!=2) return 0; if(i%2==0) ans=ans*2%MOD; } } } return ans; } };