#include <iostream> #include <algorithm> using namespace std; int main() { ios::sync_with_stdio(false); int n, a_limit = 1000, even_prefixes = 0; bool limit_exceeded = false; long long mod = 1e9 + 7, res = 0; cin >> n; long long tab[n]; long long prefix_sum[n]; cin >> tab[0]; prefix_sum[0] = tab[0]; for (auto i = 1; i < n; i++) { cin >> tab[i]; if (tab[i] > a_limit) { limit_exceeded = true; } prefix_sum[i] = prefix_sum[i - 1] + tab[i]; prefix_sum[i] %= mod; } if (!limit_exceeded) { if (prefix_sum[n - 1] % 2 != 0) { cout << 0; } else { for(auto i = 0; i < n - 1; i++) { if (prefix_sum[i] % 2 == 0) even_prefixes++; } res = 1; while(even_prefixes > 0) { res *= 2; res %= mod; even_prefixes--; } cout << res; } } else { long long num_of_possibilities_prefix[n]; long long prefix_diff; for (auto i = 0; i < n; i++) { num_of_possibilities_prefix[i] = (prefix_sum[i] % 2 == 0) ? 1 : 0; for (auto j = 1; j <= i; j++) { prefix_diff = prefix_sum[i] - prefix_sum[j - 1]; if (prefix_diff < 0) prefix_diff += mod; if (prefix_diff % 2 == 0) { num_of_possibilities_prefix[i] += num_of_possibilities_prefix[j - 1]; num_of_possibilities_prefix[i] %= mod; } } } cout << num_of_possibilities_prefix[n - 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 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 | #include <iostream> #include <algorithm> using namespace std; int main() { ios::sync_with_stdio(false); int n, a_limit = 1000, even_prefixes = 0; bool limit_exceeded = false; long long mod = 1e9 + 7, res = 0; cin >> n; long long tab[n]; long long prefix_sum[n]; cin >> tab[0]; prefix_sum[0] = tab[0]; for (auto i = 1; i < n; i++) { cin >> tab[i]; if (tab[i] > a_limit) { limit_exceeded = true; } prefix_sum[i] = prefix_sum[i - 1] + tab[i]; prefix_sum[i] %= mod; } if (!limit_exceeded) { if (prefix_sum[n - 1] % 2 != 0) { cout << 0; } else { for(auto i = 0; i < n - 1; i++) { if (prefix_sum[i] % 2 == 0) even_prefixes++; } res = 1; while(even_prefixes > 0) { res *= 2; res %= mod; even_prefixes--; } cout << res; } } else { long long num_of_possibilities_prefix[n]; long long prefix_diff; for (auto i = 0; i < n; i++) { num_of_possibilities_prefix[i] = (prefix_sum[i] % 2 == 0) ? 1 : 0; for (auto j = 1; j <= i; j++) { prefix_diff = prefix_sum[i] - prefix_sum[j - 1]; if (prefix_diff < 0) prefix_diff += mod; if (prefix_diff % 2 == 0) { num_of_possibilities_prefix[i] += num_of_possibilities_prefix[j - 1]; num_of_possibilities_prefix[i] %= mod; } } } cout << num_of_possibilities_prefix[n - 1]; } return 0; } |