#include <bits/stdc++.h> using namespace std; const int N = int(3e5) + 99; int n, x; long long a[N]; long long b[N]; int input[N]; bool subtask = true; const int p = 1e9+7; void solve1() { a[0] = input[0]; b[0] = (a[0] % 2 == 0) ? 1 : 0; for (int i = 1; i < n; i++) { x = input[i]; b[i] = 0; if ((x + a[0])%p == 0) { b[i] = 1; } for (int j = 1; j < i; j++) { if ((x + a[j]) % p == 0) { b[i] += b[j]; b[i] %= p; } } for (int j = 0; j <= i; j++) { a[j] += x; a[j] %= p; } } // for (int i = 0; i < n; i++) { // cout << a[i] << " "; // } // cout << endl; // for (int i = 0; i < n; i++) { // cout << b[i] << " "; // } // cout << endl; cout << b[n-1] << endl; } void solve2() { long long good = 0, bad = 0; long long temp; if (input[0] % 2 == 1) { bad++; } else { good++; } for (int i = 1; i < n; i++) { x = input[i]; if (x % 2 == 1) { temp = good * 2; good = bad; bad = temp % p; } else { good = (good * 2) % p; } } cout << good << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (int i = 0; i < n; i++) { cin >> input[i]; if (input[i] > 3000) { subtask = false; } } if (subtask) { solve2(); } else { solve1(); } }
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 85 86 87 88 89 | #include <bits/stdc++.h> using namespace std; const int N = int(3e5) + 99; int n, x; long long a[N]; long long b[N]; int input[N]; bool subtask = true; const int p = 1e9+7; void solve1() { a[0] = input[0]; b[0] = (a[0] % 2 == 0) ? 1 : 0; for (int i = 1; i < n; i++) { x = input[i]; b[i] = 0; if ((x + a[0])%p == 0) { b[i] = 1; } for (int j = 1; j < i; j++) { if ((x + a[j]) % p == 0) { b[i] += b[j]; b[i] %= p; } } for (int j = 0; j <= i; j++) { a[j] += x; a[j] %= p; } } // for (int i = 0; i < n; i++) { // cout << a[i] << " "; // } // cout << endl; // for (int i = 0; i < n; i++) { // cout << b[i] << " "; // } // cout << endl; cout << b[n-1] << endl; } void solve2() { long long good = 0, bad = 0; long long temp; if (input[0] % 2 == 1) { bad++; } else { good++; } for (int i = 1; i < n; i++) { x = input[i]; if (x % 2 == 1) { temp = good * 2; good = bad; bad = temp % p; } else { good = (good * 2) % p; } } cout << good << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (int i = 0; i < n; i++) { cin >> input[i]; if (input[i] > 3000) { subtask = false; } } if (subtask) { solve2(); } else { solve1(); } } |