#include <bits/stdc++.h> using namespace std; //vector <long long> v[1000000][2]; priority_queue <long long> q; long long x[10000000], y[10000000]; char s[1000000]; int main() { long long a, b, c, w, i, j, k=1e9+7, n, z, t; t=1; //scanf("%lld", &t); for(z=0; z<t; z++) { scanf("%lld", &n); if(n<=3000) { scanf("%lld", &x[0]); if(x[0]%2==0)y[0]=1; for(i=1; i<n; i++) { scanf("%lld", &x[i]); x[i]+=x[i-1]; if((x[i]%k)%2==0)y[i]++; for(j=0; j<i; j++) { if(((x[i]-x[j])%k)%2==0)y[i]+=y[j]; } //printf("%lld ", y[i-1]); } w=y[n-1]; } else { w=1; a=0; for(i=0; i<n; i++) { scanf("%lld", &b); a+=b; if(a%2==0 && i!=n-1)w=(w*2)%k; } } printf("%lld\n", w); } 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 | #include <bits/stdc++.h> using namespace std; //vector <long long> v[1000000][2]; priority_queue <long long> q; long long x[10000000], y[10000000]; char s[1000000]; int main() { long long a, b, c, w, i, j, k=1e9+7, n, z, t; t=1; //scanf("%lld", &t); for(z=0; z<t; z++) { scanf("%lld", &n); if(n<=3000) { scanf("%lld", &x[0]); if(x[0]%2==0)y[0]=1; for(i=1; i<n; i++) { scanf("%lld", &x[i]); x[i]+=x[i-1]; if((x[i]%k)%2==0)y[i]++; for(j=0; j<i; j++) { if(((x[i]-x[j])%k)%2==0)y[i]+=y[j]; } //printf("%lld ", y[i-1]); } w=y[n-1]; } else { w=1; a=0; for(i=0; i<n; i++) { scanf("%lld", &b); a+=b; if(a%2==0 && i!=n-1)w=(w*2)%k; } } printf("%lld\n", w); } return(0); } |