#include <bits/stdc++.h>
using namespace std;
#ifdef D
#define DEBUG(x) \
do { \
x \
cout.flush(); \
} while (0)
#else
#define DEBUG(x)
#endif
const long long M = 1e9 + 7;
int n, a, m, w;
int pot(long long a, int k) {
if (k == -1) {
return 0;
}
if (k == 0) {
return 1;
}
if (k == 1) {
return a;
}
if (k % 2 == 0) {
long long b = pot(a, k / 2);
return (b * b) % M;
}
return (a * pot(a, k - 1)) % M;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a;
if (a % 2 == m) {
w++;
} else {
m = 1 - m;
}
}
cout << pot(2, w - 1);
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | #include <bits/stdc++.h> using namespace std; #ifdef D #define DEBUG(x) \ do { \ x \ cout.flush(); \ } while (0) #else #define DEBUG(x) #endif const long long M = 1e9 + 7; int n, a, m, w; int pot(long long a, int k) { if (k == -1) { return 0; } if (k == 0) { return 1; } if (k == 1) { return a; } if (k % 2 == 0) { long long b = pot(a, k / 2); return (b * b) % M; } return (a * pot(a, k - 1)) % M; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n; for (int i = 0; i < n; ++i) { cin >> a; if (a % 2 == m) { w++; } else { m = 1 - m; } } cout << pot(2, w - 1); return 0; } |
English