#include <bits/stdc++.h> #define DEBUG(x) cout << '>' << #x << ':' << x << endl; #define fi first #define se second #define ll long long #define ld long double #define pb push_back #define vi vector<int> #define MAXN 100001 using namespace std; const ll P = 1000000000 + 7; const ll O = 1; int parity(ll x) { return x & O; } ll last_try(int n, vector<ll> &A, vector<ll> &S) { vector<int> L(n, 0); vector<int> R(n, 0); L[0] = -1; R[0] = 0; R[1] = (parity(A[1]) == 0) ? 1 : 0; L[1] = (parity(A[1]) == 0) ? -1 : 1; for(int i=2; i<n; i++) { L[i] = L[i-1]; if(parity(A[i]) == 0) { R[i] = R[i-1]*2; } else { L[i] = i; if(L[i-1] == -1) { R[i] = 0; } else { int l = L[i-1]; if(l-1 == 0) R[i] = 1; else R[i] = R[l-1]*2; } } R[i] %= P; } return R[n-1] % P; } ll brute_time(int n, vector<ll> &A, vector<ll> &S) { vector<int> R(n, 0); R[0] = 1; ll r= 0; for(int q = 1; q < n; q++) { for(int p=1; p <=q; p++) { ll s = S[q] - S[p-1]; bool ok = ((s % P) % 2 == 0); if(ok) { R[q] += R[p-1]; R[q] %= P; } } } return R[n-1]; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; n++; vector<ll> A(n); vector<ll> S(n, 0); for (int i = 1; i < n; i++) cin >> A[i]; bool over = false; S[0] = A[0]; for (int i = 1; i < n; i++) { S[i] = A[i] + S[i - 1]; if (S[i] >= P) over = true; } ll r = 0; // over = true; if (!over) { r = last_try(n, A, S); } else { r = brute_time(n, A, S); } cout << r << 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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | #include <bits/stdc++.h> #define DEBUG(x) cout << '>' << #x << ':' << x << endl; #define fi first #define se second #define ll long long #define ld long double #define pb push_back #define vi vector<int> #define MAXN 100001 using namespace std; const ll P = 1000000000 + 7; const ll O = 1; int parity(ll x) { return x & O; } ll last_try(int n, vector<ll> &A, vector<ll> &S) { vector<int> L(n, 0); vector<int> R(n, 0); L[0] = -1; R[0] = 0; R[1] = (parity(A[1]) == 0) ? 1 : 0; L[1] = (parity(A[1]) == 0) ? -1 : 1; for(int i=2; i<n; i++) { L[i] = L[i-1]; if(parity(A[i]) == 0) { R[i] = R[i-1]*2; } else { L[i] = i; if(L[i-1] == -1) { R[i] = 0; } else { int l = L[i-1]; if(l-1 == 0) R[i] = 1; else R[i] = R[l-1]*2; } } R[i] %= P; } return R[n-1] % P; } ll brute_time(int n, vector<ll> &A, vector<ll> &S) { vector<int> R(n, 0); R[0] = 1; ll r= 0; for(int q = 1; q < n; q++) { for(int p=1; p <=q; p++) { ll s = S[q] - S[p-1]; bool ok = ((s % P) % 2 == 0); if(ok) { R[q] += R[p-1]; R[q] %= P; } } } return R[n-1]; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; n++; vector<ll> A(n); vector<ll> S(n, 0); for (int i = 1; i < n; i++) cin >> A[i]; bool over = false; S[0] = A[0]; for (int i = 1; i < n; i++) { S[i] = A[i] + S[i - 1]; if (S[i] >= P) over = true; } ll r = 0; // over = true; if (!over) { r = last_try(n, A, S); } else { r = brute_time(n, A, S); } cout << r << endl; return 0; } |