#include <iostream> #include <cstdio> using namespace std; long long wyn[1000000]; long long sum_pref[1000000]; const int p=1000000007; int dane[1000000]; int main() { int n,x; scanf("%d", &n); wyn[0]=1LL; long long suma=0LL; for (int i=1; i<=n; i++) { scanf("%d", &x); suma+=(long long)(x); sum_pref[i]+=x; sum_pref[i]+=sum_pref[i-1]; dane[i]=x; } if (suma<p) { long long sum_pref_p=0LL; long long sum_pref_n=0LL; for (int i=1; i<=n; i++) { if ((sum_pref[i]%p)%2==0) wyn[i]=1LL; if ((sum_pref[i]%p)%2==0) { wyn[i]+=sum_pref_p; sum_pref_p+=wyn[i]; } else { wyn[i]+=sum_pref_n; sum_pref_n+=wyn[i]; } } printf("%lld\n", wyn[n]); } else { for (int i=1; i<=n; i++) { for (int j=i-1; j>=0; j--) { if (((sum_pref[i]-sum_pref[j])%p)%2==0) wyn[i]+=wyn[j]; } } printf("%lld\n", wyn[n]); } 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 | #include <iostream> #include <cstdio> using namespace std; long long wyn[1000000]; long long sum_pref[1000000]; const int p=1000000007; int dane[1000000]; int main() { int n,x; scanf("%d", &n); wyn[0]=1LL; long long suma=0LL; for (int i=1; i<=n; i++) { scanf("%d", &x); suma+=(long long)(x); sum_pref[i]+=x; sum_pref[i]+=sum_pref[i-1]; dane[i]=x; } if (suma<p) { long long sum_pref_p=0LL; long long sum_pref_n=0LL; for (int i=1; i<=n; i++) { if ((sum_pref[i]%p)%2==0) wyn[i]=1LL; if ((sum_pref[i]%p)%2==0) { wyn[i]+=sum_pref_p; sum_pref_p+=wyn[i]; } else { wyn[i]+=sum_pref_n; sum_pref_n+=wyn[i]; } } printf("%lld\n", wyn[n]); } else { for (int i=1; i<=n; i++) { for (int j=i-1; j>=0; j--) { if (((sum_pref[i]-sum_pref[j])%p)%2==0) wyn[i]+=wyn[j]; } } printf("%lld\n", wyn[n]); } return 0; } |