#include <iostream> #include <algorithm> #include <stdio.h> #include <set> #include <vector> #include <map> using namespace std; #define LL long long #define MOD 1000000007LL LL tab[300100]; /* LL policz(LL p, LL l) { LL r = 0; LL s = 0; if(l<=1) { if((tab[p]%MOD)%2==0) r = 1; } else { for(LL i=p+l-1;i>=p;i--) { s+=tab[i]; s%=MOD; if (s%2==0) { printf("policz(%lld, %lld) :%lld\n",i,l-i,1LL); LL rc = policz(p,i-p); r+=rc; r%=MOD; } } } printf("policz(%lld, %lld) :%lld\n",p,l,r); return r; } */ LL policzone[300100]; LL policz(LL l) { LL r = 0; LL s = 0; if(l>=0 && policzone[l]>=0)return policzone[l]; if(l<=1) { if((tab[0]%MOD)%2==0) r = 1; } else { for(LL i=l-1;i>=0;i--) { s+=tab[i]; s%=MOD; } for(LL i=0;i<l;i++) { if (s%2==0) { //printf("policz(%lld, %lld) :%lld\n",i,l-i,1LL); LL rc = policz(i); r+=rc; r%=MOD; } s+=MOD; s-=tab[i]; s%=MOD; } } //printf("policz(%lld, %lld) :%lld\n",0LL,l,r); policzone[l]=r; return r; } int main() { // your code goes here LL n; LL a; scanf("%lld",&n); policzone[0]=-1; for(int i=0;i<n;i++) { scanf("%lld",tab+i); policzone[i+1]=-1; } LL r = policz(n); printf("%lld",r); 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 | #include <iostream> #include <algorithm> #include <stdio.h> #include <set> #include <vector> #include <map> using namespace std; #define LL long long #define MOD 1000000007LL LL tab[300100]; /* LL policz(LL p, LL l) { LL r = 0; LL s = 0; if(l<=1) { if((tab[p]%MOD)%2==0) r = 1; } else { for(LL i=p+l-1;i>=p;i--) { s+=tab[i]; s%=MOD; if (s%2==0) { printf("policz(%lld, %lld) :%lld\n",i,l-i,1LL); LL rc = policz(p,i-p); r+=rc; r%=MOD; } } } printf("policz(%lld, %lld) :%lld\n",p,l,r); return r; } */ LL policzone[300100]; LL policz(LL l) { LL r = 0; LL s = 0; if(l>=0 && policzone[l]>=0)return policzone[l]; if(l<=1) { if((tab[0]%MOD)%2==0) r = 1; } else { for(LL i=l-1;i>=0;i--) { s+=tab[i]; s%=MOD; } for(LL i=0;i<l;i++) { if (s%2==0) { //printf("policz(%lld, %lld) :%lld\n",i,l-i,1LL); LL rc = policz(i); r+=rc; r%=MOD; } s+=MOD; s-=tab[i]; s%=MOD; } } //printf("policz(%lld, %lld) :%lld\n",0LL,l,r); policzone[l]=r; return r; } int main() { // your code goes here LL n; LL a; scanf("%lld",&n); policzone[0]=-1; for(int i=0;i<n;i++) { scanf("%lld",tab+i); policzone[i+1]=-1; } LL r = policz(n); printf("%lld",r); return 0; } |