#include <bits/stdc++.h> using namespace std; using ll = long long; const int MAX = 3e5 + 213; ll MOD = 1e9 + 7; ll tab[MAX]; ll dp[MAX]; int N; void solve_kwadrat() { dp[0] = 1; for (int i = 1; i <= N; ++i) { ll suma = 0; for (int j = i; j > 0; --j) { ll suma_na_przedziale = (tab[i] - tab[j - 1] + MOD) % MOD; if (suma_na_przedziale % 2 == 0) { (suma += dp[j - 1]) %= MOD; } } dp[i] = suma % MOD; } cout << dp[N] % MOD << "\n"; } void solve_male() { ll mod0 = 1; ll mod1 = 0; dp[0] = 0; for (int i = 1; i <= N; ++i) { tab[i] %= 2; ll suma = 0; if (tab[i] == 1) suma = mod1; else suma = mod0; if (tab[i] == 1) (mod1 += suma) %= MOD; else (mod0 += suma) %= MOD; dp[i] = suma % MOD; } cout << dp[N] % MOD << "\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N; bool suma_wieksza_niz_mod = false; for (int i = 1; i <= N; ++i) { cin >> tab[i]; tab[i] += tab[i - 1]; if (tab[i] >= MOD) { suma_wieksza_niz_mod = true; } tab[i] %= MOD; } if (N <= 3000 || suma_wieksza_niz_mod) { cerr << "Kwadrat\n"; solve_kwadrat(); } else { cerr << "Male\n"; solve_male(); } 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 94 95 96 97 98 99 100 101 | #include <bits/stdc++.h> using namespace std; using ll = long long; const int MAX = 3e5 + 213; ll MOD = 1e9 + 7; ll tab[MAX]; ll dp[MAX]; int N; void solve_kwadrat() { dp[0] = 1; for (int i = 1; i <= N; ++i) { ll suma = 0; for (int j = i; j > 0; --j) { ll suma_na_przedziale = (tab[i] - tab[j - 1] + MOD) % MOD; if (suma_na_przedziale % 2 == 0) { (suma += dp[j - 1]) %= MOD; } } dp[i] = suma % MOD; } cout << dp[N] % MOD << "\n"; } void solve_male() { ll mod0 = 1; ll mod1 = 0; dp[0] = 0; for (int i = 1; i <= N; ++i) { tab[i] %= 2; ll suma = 0; if (tab[i] == 1) suma = mod1; else suma = mod0; if (tab[i] == 1) (mod1 += suma) %= MOD; else (mod0 += suma) %= MOD; dp[i] = suma % MOD; } cout << dp[N] % MOD << "\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N; bool suma_wieksza_niz_mod = false; for (int i = 1; i <= N; ++i) { cin >> tab[i]; tab[i] += tab[i - 1]; if (tab[i] >= MOD) { suma_wieksza_niz_mod = true; } tab[i] %= MOD; } if (N <= 3000 || suma_wieksza_niz_mod) { cerr << "Kwadrat\n"; solve_kwadrat(); } else { cerr << "Male\n"; solve_male(); } return 0; } |