#include <cstdio> #include <map> #define M 1000000007 int main () { std::map <int, int> A; int n, w = 0, s = 0; scanf ("%i", &n); A[0] = 1; while (n--) { int a; scanf ("%i", &a); w = (w+M-a)%M; s = 0; for (auto j: A) s = (s+j.second*((j.first+M-w)%M%2==0))%M; A[w] = (A[w]+s)%M; } printf ("%i\n", s); 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 | #include <cstdio> #include <map> #define M 1000000007 int main () { std::map <int, int> A; int n, w = 0, s = 0; scanf ("%i", &n); A[0] = 1; while (n--) { int a; scanf ("%i", &a); w = (w+M-a)%M; s = 0; for (auto j: A) s = (s+j.second*((j.first+M-w)%M%2==0))%M; A[w] = (A[w]+s)%M; } printf ("%i\n", s); return 0; } |