/* 2021 * Maciej Szeptuch */ #include <cmath> #include <cstdio> #include <queue> const int MOD = 1000000007; int length; int number[524288]; int result[524288]; int other[524288]; long long int sum; int main(void) { scanf("%d", &length); for(int n = 1; n <= length; ++n) scanf("%d", &number[n]); result[0] = 1; for(int n = 1; n <= length; ++n) { sum += number[n]; if(sum < MOD) { if(number[n] % 2 == 1) { result[n] = other[n - 1]; other[n] = (n > 1 ? 2 * result[n - 1] : 1) % MOD; } else { result[n] = (n > 1 ? 2 * result[n - 1] : 1) % MOD; other[n] = other[n - 1]; } } else { result[n] = 0; int suffix = 0; for(int s = n; s > 0; --s) { suffix = (suffix + number[s]) % MOD; if(suffix % 2 == 0) result[n] = (result[n] + result[s - 1]) % MOD; } } } printf("%d\n", result[length]); 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 | /* 2021 * Maciej Szeptuch */ #include <cmath> #include <cstdio> #include <queue> const int MOD = 1000000007; int length; int number[524288]; int result[524288]; int other[524288]; long long int sum; int main(void) { scanf("%d", &length); for(int n = 1; n <= length; ++n) scanf("%d", &number[n]); result[0] = 1; for(int n = 1; n <= length; ++n) { sum += number[n]; if(sum < MOD) { if(number[n] % 2 == 1) { result[n] = other[n - 1]; other[n] = (n > 1 ? 2 * result[n - 1] : 1) % MOD; } else { result[n] = (n > 1 ? 2 * result[n - 1] : 1) % MOD; other[n] = other[n - 1]; } } else { result[n] = 0; int suffix = 0; for(int s = n; s > 0; --s) { suffix = (suffix + number[s]) % MOD; if(suffix % 2 == 0) result[n] = (result[n] + result[s - 1]) % MOD; } } } printf("%d\n", result[length]); return 0; } |