// B3 - Mopadulo #include <iostream> #include <vector> #include <algorithm> using namespace std; #define MOD 1000000007; struct Candidate { long long value; long long count; Candidate(long long v, long long c) { value = v; count = c; } }; int main() { int n, a; long long good, almostGood, tmpGood, even; vector<long long> input; vector<Candidate> candidates; int candidatesSize; bool smallNumbers; cin >> n; smallNumbers = true; for (int i = 0; i < n; ++i) { cin >> a; input.push_back(a); if (a > 3333) { smallNumbers = false; } } if (smallNumbers) { if (input[0] % 2) { good = 0; almostGood = 1; } else { good = 1; almostGood = 0; } for (int i = 1; i < n; ++i) { if (input[i] % 2) { tmpGood = good; good = almostGood; almostGood = (tmpGood + tmpGood) % MOD; } else { good = (good + good) % MOD; almostGood = almostGood; } } cout << good; return 0; } candidates.push_back(Candidate(input[0], 1)); even = 1 - input[0] % 2; for (int i = 1; i < n; ++i) { candidatesSize = candidates.size(); if (even > 0) { candidates.push_back(Candidate(input[i], even)); } if (input[i] % 2) { even = 0; } for (int j = 0; j < candidatesSize; ++j) { candidates[j].value = (candidates[j].value + input[i]) % MOD; if (candidates[j].value % 2 == 0) { even = (even + candidates[j].count) % MOD; } } } cout << even << endl; 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 | // B3 - Mopadulo #include <iostream> #include <vector> #include <algorithm> using namespace std; #define MOD 1000000007; struct Candidate { long long value; long long count; Candidate(long long v, long long c) { value = v; count = c; } }; int main() { int n, a; long long good, almostGood, tmpGood, even; vector<long long> input; vector<Candidate> candidates; int candidatesSize; bool smallNumbers; cin >> n; smallNumbers = true; for (int i = 0; i < n; ++i) { cin >> a; input.push_back(a); if (a > 3333) { smallNumbers = false; } } if (smallNumbers) { if (input[0] % 2) { good = 0; almostGood = 1; } else { good = 1; almostGood = 0; } for (int i = 1; i < n; ++i) { if (input[i] % 2) { tmpGood = good; good = almostGood; almostGood = (tmpGood + tmpGood) % MOD; } else { good = (good + good) % MOD; almostGood = almostGood; } } cout << good; return 0; } candidates.push_back(Candidate(input[0], 1)); even = 1 - input[0] % 2; for (int i = 1; i < n; ++i) { candidatesSize = candidates.size(); if (even > 0) { candidates.push_back(Candidate(input[i], even)); } if (input[i] % 2) { even = 0; } for (int j = 0; j < candidatesSize; ++j) { candidates[j].value = (candidates[j].value + input[i]) % MOD; if (candidates[j].value % 2 == 0) { even = (even + candidates[j].count) % MOD; } } } cout << even << endl; return 0; } |