Submission #1410562
Source Code Expand
#include<iostream> #include<utility> #include<tuple> #include<set> #include<list> #include<vector> #include<map> #include<algorithm> #include<queue> #include<math.h> #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FUNCTION__ << endl; #define int long long const long long MAXN = 100; const long long MOD = 1e9+7; const long long INF = __LONG_LONG_MAX__ / 2; using namespace std; int hoge[MAXN]; constexpr int power(int b, int i){ if (i == 1) return b % MOD; if (i % 2 == 0) { return power(b*b % MOD, i/2) ; } else { return power(b*b % MOD, i/2)*b % MOD ; } } constexpr int factseed(int n){ if (n == 0 ) return 1; return (n * (factseed(n-1))) % MOD; } constexpr int invMod(int n){ return power(n,MOD - 2); } template<int N> struct Facts { constexpr Facts() : arr() { for (auto i = 0; i != N; ++i){ arr[i] = factseed(i); } } int arr[N]; }; constexpr auto facts = Facts<MAXN>(); constexpr int fact(int n){ return facts.arr[n]; } template<int N> struct Finv { constexpr Finv() : arr() { for (auto i = 0; i != N; ++i){ arr[i] = invMod(fact(i)); } } int arr[N]; }; constexpr auto finvs = Finv<MAXN>(); int combination(int m, int n){ if(m<0 || n < 0 || m < n) return 0; return (((fact(m)*invMod(fact(n))) % MOD) * invMod(fact(m-n))) % MOD; } int perm(int m,int n){ if (n == 0) return 1; return m * (perm (m-1, n-1)); } signed main(){ int N, P; cin >> N >> P; int even_counts = 0; int odd_counts = 0; for (int i = 0; i < N; i++){ int a; cin >> a; if (a % 2 == 0){ even_counts++; } } odd_counts = N - even_counts; if (P == 0){// must be even int prod = 0; for(int i = 0; i<= odd_counts ; i += 2){ prod += combination(odd_counts, i); } printf("%lld\n",prod *(int)pow(2, even_counts)); } else { int prod = 0; for(int i = 1; i<= odd_counts ; i += 2){ prod += combination(odd_counts, i); } printf("%lld\n",prod *(int)pow(2, even_counts )); } return 0; }
Submission Info
Submission Time | |
---|---|
Task | A - Biscuits |
User | yuchiki |
Language | C++14 (GCC 5.4.1) |
Score | 200 |
Code Size | 2306 Byte |
Status | AC |
Exec Time | 1 ms |
Memory | 256 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 200 / 200 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample1.txt, sample2.txt, sample3.txt, sample4.txt |
All | sample1.txt, sample2.txt, sample3.txt, sample4.txt, in1.txt, in2.txt, in3.txt, in4.txt, in5.txt, in6.txt, in7.txt, in8.txt, sample1.txt, sample2.txt, sample3.txt, sample4.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
in1.txt | AC | 1 ms | 256 KB |
in2.txt | AC | 1 ms | 256 KB |
in3.txt | AC | 1 ms | 256 KB |
in4.txt | AC | 1 ms | 256 KB |
in5.txt | AC | 1 ms | 256 KB |
in6.txt | AC | 1 ms | 256 KB |
in7.txt | AC | 1 ms | 256 KB |
in8.txt | AC | 1 ms | 256 KB |
sample1.txt | AC | 1 ms | 256 KB |
sample2.txt | AC | 1 ms | 256 KB |
sample3.txt | AC | 1 ms | 256 KB |
sample4.txt | AC | 1 ms | 256 KB |