#include <bits/stdc++.h> #define gc getchar #define gcu getchar_unlocked #define fi first #define se second #define pb push_back #define mod ((ll)1e9 + 7) typedef long long ll; using namespace std; //============================================= int n; ll a[1000009], b[1000009], c[1000009]; void wypisz(void) { for (int i = 0; i < n; i++) printf("%d %12lld %12lld %12lld\n", i, a[i], b[i], c[i]); printf("\n\n"); } //============================================= int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%lld", &a[i]); for (int i = 0; i < n; i++) { ll temp = 0; for (int j = 0; j <= i; j++) { b[i - j] += a[i]; b[i - j] %= mod; if (b[i - j] % 2 == 0) { if (i - j == 0) { temp++; temp %= mod; } else { temp += c[i - j - 1]; temp %= mod; } } } c[i] = temp; } printf("%lld\n", c[n - 1]); } //=============================================
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 | #include <bits/stdc++.h> #define gc getchar #define gcu getchar_unlocked #define fi first #define se second #define pb push_back #define mod ((ll)1e9 + 7) typedef long long ll; using namespace std; //============================================= int n; ll a[1000009], b[1000009], c[1000009]; void wypisz(void) { for (int i = 0; i < n; i++) printf("%d %12lld %12lld %12lld\n", i, a[i], b[i], c[i]); printf("\n\n"); } //============================================= int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%lld", &a[i]); for (int i = 0; i < n; i++) { ll temp = 0; for (int j = 0; j <= i; j++) { b[i - j] += a[i]; b[i - j] %= mod; if (b[i - j] % 2 == 0) { if (i - j == 0) { temp++; temp %= mod; } else { temp += c[i - j - 1]; temp %= mod; } } } c[i] = temp; } printf("%lld\n", c[n - 1]); } //============================================= |