#include <iostream> #include <vector> #include <algorithm> int n; std::vector<long long> a; std::vector<long long> pref; std::vector<long long> res; long long s; int main(){ std::ios_base::sync_with_stdio(0); std::cin>>n; long long sum=0; long long max=0; pref.emplace_back(0); for(int i=0;i<n ;i++){ std::cin>>s; a.emplace_back(s); sum+=s; pref.emplace_back(sum); max=std::max(max,s); } if(max*n<1000000007){ //std::cerr<<"DD"<<std::endl; if(pref.back()%2==1){ std::cout<<0<<std::endl; return 0; } long long res=1; for(int i=1;i<pref.size()-1;i++) if(pref[i]%2==0){ res*=2; res%=1000000007; } std::cout<<res<<std::endl; return 0; }else{ //if(n<=3000){ res.emplace_back(1); for(int i=0;i<n;i++){ long long act=0; for(int j=0;j<=i;j++) if(((pref[i+1]-pref[j])%(1000000007))%2==0) act+=res[j]; act%=1000000007; res.emplace_back(act); } //} } std::cout<<res.back()<<std::endl; }
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 | #include <iostream> #include <vector> #include <algorithm> int n; std::vector<long long> a; std::vector<long long> pref; std::vector<long long> res; long long s; int main(){ std::ios_base::sync_with_stdio(0); std::cin>>n; long long sum=0; long long max=0; pref.emplace_back(0); for(int i=0;i<n ;i++){ std::cin>>s; a.emplace_back(s); sum+=s; pref.emplace_back(sum); max=std::max(max,s); } if(max*n<1000000007){ //std::cerr<<"DD"<<std::endl; if(pref.back()%2==1){ std::cout<<0<<std::endl; return 0; } long long res=1; for(int i=1;i<pref.size()-1;i++) if(pref[i]%2==0){ res*=2; res%=1000000007; } std::cout<<res<<std::endl; return 0; }else{ //if(n<=3000){ res.emplace_back(1); for(int i=0;i<n;i++){ long long act=0; for(int j=0;j<=i;j++) if(((pref[i+1]-pref[j])%(1000000007))%2==0) act+=res[j]; act%=1000000007; res.emplace_back(act); } //} } std::cout<<res.back()<<std::endl; } |