// Karol Kosinski 2021 #include <bits/stdc++.h> // #define ENABLE_DEBUG #define FOR(i,a,b) for(int i=(a),_b=(b);i<_b;++i) #define FR_(i,a,b) for(int i=(a),_b=(b);i<=_b;++i) #define FD_(i,b,a) for(int i=(b),_a=(a);i>=_a;--i) #define ALL(c) (c).begin(),(c).end() #define SIZE(c) int((c).size()) #define TIE(x...) int x;tie(x) #define X first #define Y second #ifndef ENABLE_DEBUG #define DEB(k,f,x...) #else #define DEB(k,f,x...) {if(k)printf("--------%4d : %s\n",__LINE__,__FUNCTION__);f(x);} #endif #define DEBL DEB(1,void,0) #define DEBF(f,x...) DEB(1,f,x) #define DEBUG(x...) DEB(0,printf,x) using namespace std; using LL = long long; using ULL = unsigned long long; using PII = pair<int, int>; using TIII = tuple<int, int, int>; constexpr int NX = 300'005; constexpr int MOD = 1e9 + 7; int A[NX], S[NX], P[NX]; int main() { int n; scanf("%d", &n); FR_(i,1,n) scanf("%d", A + i); bool bigger = false; FR_(i,1,n) { S[i] = S[ i - 1 ] + A[i]; if ( S[i] >= MOD ) bigger = true; if (bigger) S[i] %= MOD; } if (not bigger) { int k = 0, res = 1; FR_(i,1,n) if ( S[i] % 2 == 0 ) ++ k; FR_(i,2,k) res = ( res << 1 ) % MOD; if ( S[n] % 2 == 1 ) printf("0\n"); else printf("%d\n", res); return 0; } P[n] = ( A[n] % 2 == 0 ); DEBUG("P[%2d] = %3d\n", n, P[n]); FD_(i,n-1,1) { int diff = ( S[n] + MOD - S[ i - 1 ] ) % MOD; P[i] = ( diff % 2 == 0 ); FR_(j,i,n-1) { diff = ( S[j] + MOD - S[ i - 1 ] ) % MOD; if ( diff % 2 == 0 ) P[i] = ( P[i] + P[ j + 1 ] ) % MOD; } DEBUG("P[%2d] = %3d\n", i, P[i]); } printf("%d\n", P[1]); 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 | // Karol Kosinski 2021 #include <bits/stdc++.h> // #define ENABLE_DEBUG #define FOR(i,a,b) for(int i=(a),_b=(b);i<_b;++i) #define FR_(i,a,b) for(int i=(a),_b=(b);i<=_b;++i) #define FD_(i,b,a) for(int i=(b),_a=(a);i>=_a;--i) #define ALL(c) (c).begin(),(c).end() #define SIZE(c) int((c).size()) #define TIE(x...) int x;tie(x) #define X first #define Y second #ifndef ENABLE_DEBUG #define DEB(k,f,x...) #else #define DEB(k,f,x...) {if(k)printf("--------%4d : %s\n",__LINE__,__FUNCTION__);f(x);} #endif #define DEBL DEB(1,void,0) #define DEBF(f,x...) DEB(1,f,x) #define DEBUG(x...) DEB(0,printf,x) using namespace std; using LL = long long; using ULL = unsigned long long; using PII = pair<int, int>; using TIII = tuple<int, int, int>; constexpr int NX = 300'005; constexpr int MOD = 1e9 + 7; int A[NX], S[NX], P[NX]; int main() { int n; scanf("%d", &n); FR_(i,1,n) scanf("%d", A + i); bool bigger = false; FR_(i,1,n) { S[i] = S[ i - 1 ] + A[i]; if ( S[i] >= MOD ) bigger = true; if (bigger) S[i] %= MOD; } if (not bigger) { int k = 0, res = 1; FR_(i,1,n) if ( S[i] % 2 == 0 ) ++ k; FR_(i,2,k) res = ( res << 1 ) % MOD; if ( S[n] % 2 == 1 ) printf("0\n"); else printf("%d\n", res); return 0; } P[n] = ( A[n] % 2 == 0 ); DEBUG("P[%2d] = %3d\n", n, P[n]); FD_(i,n-1,1) { int diff = ( S[n] + MOD - S[ i - 1 ] ) % MOD; P[i] = ( diff % 2 == 0 ); FR_(j,i,n-1) { diff = ( S[j] + MOD - S[ i - 1 ] ) % MOD; if ( diff % 2 == 0 ) P[i] = ( P[i] + P[ j + 1 ] ) % MOD; } DEBUG("P[%2d] = %3d\n", i, P[i]); } printf("%d\n", P[1]); return 0; } |