Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <list>
- #include <map>
- #include <set>
- #include <deque>
- #include <stack>
- #include <queue>
- #include <algorithm>
- #include <sstream>
- #include <iostream>
- #include <iomanip>
- #include <cstdio>
- #include <cmath>
- #include <cstdlib>
- #include <memory.h>
- #include <ctime>
- #include <bitset>
- using namespace std;
- #define ABS(a) ((a>0)?a:-(a))
- #define MIN(a,b) ((a<b)?(a):(b))
- #define MAX(a,b) ((a<b)?(b):(a))
- #define FOR(i,a,n) for (int i=(a);i<(n);++i)
- #define FI(i,n) for (int i=0; i<(n); ++i)
- #define pnt pair <int, int>
- #define mp make_pair
- #define PI 3.1415926535897
- #define MEMS(a,b) memset(a,b,sizeof(a))
- #define LL long long
- #define U unsigned
- const int N = 300010;
- const int M = 100010;
- int mod = 1000000007;
- LL fact[N];
- LL inv[N];
- char s1[6];
- string s;
- int vals[M];
- stringstream tmp;
- int dp[M][202];
- int was[M][202];
- int test;
- int bp(int val, int p)
- {
- if (p == 0)
- return 1;
- LL res = bp(val, p / 2);
- res *= res;
- res %= mod;
- if (p & 1)
- {
- res *= val;
- res %= mod;
- }
- return res;
- }
- int last;
- int r(int n, int k)
- {
- if (n == 0)
- {
- if (k > vals[last] + 1)
- return 0;
- return 1;
- }
- if (was[n][k] == test)
- return dp[n][k];
- was[n][k] = test;
- int c = vals[last];
- if ((k == 1) || (k == 2))
- {
- LL res = fact[c + n + n];
- res *= (c + 1);
- res %= mod;
- res *= inv[n];
- res %= mod;
- res *= inv[c + n + 1];
- res %= mod;
- return dp[n][k] = res;
- }
- LL res = r(n, k - 1) - r(n - 1, k - 2);
- if (res < 0)
- res += mod;
- return dp[n][k] = res;
- }
- int main()
- {
- #ifdef Fcdkbear
- freopen("in.txt", "r", stdin);
- //freopen("out.txt", "w", stdout);
- double beg = clock();
- #endif
- fact[0] = 1;
- FOR(i, 1, N)
- {
- fact[i] = fact[i - 1] * i;
- fact[i] %= mod;
- }
- FOR(i, 0, N)
- {
- inv[i] = bp(fact[i], mod - 2);
- }
- int n;
- scanf("%d", &n);
- MEMS(vals, -1);
- FOR(i, 0, n)
- {
- scanf("%s", s1);
- s = (string)s1;
- if (s[0] == '?')
- continue;
- tmp.clear();
- tmp << s;
- tmp >> vals[i];
- }
- if (vals[0] == -1)
- vals[0] = 0;
- if (vals[0])
- {
- cout << 0 << endl;
- return 0;
- }
- n++;
- vals[n - 1] = 1;
- last = 0;
- LL res = 1;
- FOR(i, 1, n)
- {
- if (vals[i] == 0)
- {
- cout << 0 << endl;
- return 0;
- }
- if (vals[i] != -1)
- {
- test++;
- LL res1 = r(i - last - 1, vals[i]);
- res *= res1;
- res %= mod;
- last = i;
- }
- }
- cout << res << endl;
- #ifdef Fcdkbear
- double end = clock();
- fprintf(stderr, "*** Total time = %.3lf ***\n", (end - beg) / CLOCKS_PER_SEC);
- #endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement