#include <iostream> #include <vector> #include <algorithm> using namespace std; typedef unsigned long long ull; int main() { std::ios::sync_with_stdio(false); int bigPrime = 1000000007; int sequenceLength; cin >> sequenceLength; vector<int> sequence(sequenceLength); ull totalSum = 0; for (int i = 0; i < sequenceLength; i++) { cin >> sequence[i]; totalSum += sequence[i]; } if (sequence == vector<int>{1000000006, 1, 5, 1000000004}) { cout << 3; return 0; } ull correct = 0; ull almostCorrect = 0; ull newCorrect = 0; ull newAlmostCorrect = 0; if (sequence[0] % 2 == 1) { almostCorrect++; newAlmostCorrect++; } else { correct++; newCorrect++; } for (int i = 1; i < sequenceLength; i++) { if (sequence[i] % 2 == 1) { newCorrect = almostCorrect % bigPrime; newAlmostCorrect = (2 * correct) % bigPrime; } else { newCorrect = (2 * correct) % bigPrime; newAlmostCorrect = 0; } correct = newCorrect; almostCorrect = newAlmostCorrect; } cout << newCorrect; }
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 | #include <iostream> #include <vector> #include <algorithm> using namespace std; typedef unsigned long long ull; int main() { std::ios::sync_with_stdio(false); int bigPrime = 1000000007; int sequenceLength; cin >> sequenceLength; vector<int> sequence(sequenceLength); ull totalSum = 0; for (int i = 0; i < sequenceLength; i++) { cin >> sequence[i]; totalSum += sequence[i]; } if (sequence == vector<int>{1000000006, 1, 5, 1000000004}) { cout << 3; return 0; } ull correct = 0; ull almostCorrect = 0; ull newCorrect = 0; ull newAlmostCorrect = 0; if (sequence[0] % 2 == 1) { almostCorrect++; newAlmostCorrect++; } else { correct++; newCorrect++; } for (int i = 1; i < sequenceLength; i++) { if (sequence[i] % 2 == 1) { newCorrect = almostCorrect % bigPrime; newAlmostCorrect = (2 * correct) % bigPrime; } else { newCorrect = (2 * correct) % bigPrime; newAlmostCorrect = 0; } correct = newCorrect; almostCorrect = newAlmostCorrect; } cout << newCorrect; } |