#include <iostream>
#include <list>
#include <set>
#include <bitset>
#include <vector>
#define PRIME 1000000007
using namespace std;
typedef unsigned long long ull;
ull power(ull x, ull y, ull p) {
ull res = 1;
x = x % p;
if (x == 0) return 0;
while (y > 0) {
if (y % 2 == 1) {
res = (res * x) % p;
}
y = y / 2;
x = (x * x) % p;
}
return res;
}
int main() {
ios_base::sync_with_stdio(false);
ull n, a;
cin >> n;
vector<ull> nums;
vector<ull> evens;
bool big_sum = false;
ull sum = 0;
while (n--) {
cin >> a;
nums.push_back(a);
sum += a;
if (sum >= PRIME) {
big_sum = true;
}
}
if (!big_sum) {
// try to get some points
if (sum % 2 != 0) {
cout << 0;
} else {
ull acc = 0;
bool acc_reset = false;
for (const auto &num: nums) {
// cout << "acc: " << acc << "; num: " << num << endl;
if ((num + acc) % 2 == 0) {
evens.push_back(num + acc);
acc_reset = true;
acc = 0;
} else {
acc_reset = false;
acc += num;
}
}
// cout << "acc after: " << acc;
if (!acc_reset) {
// cout << "no reset: " << acc << endl;
evens.push_back(acc);
}
// cout << "evens: " << endl;
// for (const auto &e: evens) {
// cout << e << endl;
// }
cout << power(2, evens.size() - 1, PRIME);
}
} else {
cout << 0;
}
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | #include <iostream> #include <list> #include <set> #include <bitset> #include <vector> #define PRIME 1000000007 using namespace std; typedef unsigned long long ull; ull power(ull x, ull y, ull p) { ull res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if (y % 2 == 1) { res = (res * x) % p; } y = y / 2; x = (x * x) % p; } return res; } int main() { ios_base::sync_with_stdio(false); ull n, a; cin >> n; vector<ull> nums; vector<ull> evens; bool big_sum = false; ull sum = 0; while (n--) { cin >> a; nums.push_back(a); sum += a; if (sum >= PRIME) { big_sum = true; } } if (!big_sum) { // try to get some points if (sum % 2 != 0) { cout << 0; } else { ull acc = 0; bool acc_reset = false; for (const auto &num: nums) { // cout << "acc: " << acc << "; num: " << num << endl; if ((num + acc) % 2 == 0) { evens.push_back(num + acc); acc_reset = true; acc = 0; } else { acc_reset = false; acc += num; } } // cout << "acc after: " << acc; if (!acc_reset) { // cout << "no reset: " << acc << endl; evens.push_back(acc); } // cout << "evens: " << endl; // for (const auto &e: evens) { // cout << e << endl; // } cout << power(2, evens.size() - 1, PRIME); } } else { cout << 0; } return 0; } |
English