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
#include <stdio.h>

const int max_size = 3e5;
const int mod = 1e9 + 7;

#define scan(args...) [&]{ return scanf(args); }();

int main()
{
    int n;
    int a[max_size];
    int v[max_size+1];
    long long sum;
    
    sum = 0;
    scan("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scan("%d", &a[i]);
        sum += a[i];
    }
    
    if (sum < mod)
    {
        // O(n)
        
        int result = 0;
        bool even = true;
        
        for (int i = 0; i < n; i++)
        {
            if (a[i] % 2 == 1)
                even = !even;
            if (even)
            {
                if (result == 0)
                    result = 1;
                else
                    result = (2 * result) % mod;
            }
        }
        
        if (even) printf("%d\n", result);
        else printf("0\n");
    }
    else
    {
        // O(n^2)
        v[n] = 1;
        
        for (int i = n-1; i >= 0; i--)
        {
            int sum = 0;
            v[i] = 0;
            
            for (int ind = i; ind < n; ind++)
            {
                sum = (sum + a[ind]) % mod;
                if (sum % 2 == 0)
                    v[i] = (v[i] + v[ind+1]) % mod;
            }
        }
        
        printf("%d\n", v[0]);
    }
    
    return 0;
}