Modular combination(Modular n, Modular r) { Modular a = 1; Modular b = 1; for (int i = 1; i <= (int)r; i++) { a = (n - i + 1) * a; b = b * i; } return(a * Modular.Pow(b, MOD - 2)); }
public static Modular Pow(Modular a, int n) { switch (n) { case 0: return(1); case 1: return(a); default: var p = Pow(a, n / 2); return(p * p * Pow(a, n % 2)); } }
public void Solve() { Cin(out N); Cin(out A); var diff = new List <Modular>(); int before = 0; int mcount = 0; for (int i = 0; i < N; i++) { if (A[i] == -1) { mcount++; continue; } if (mcount > 0) { int k = A[i] - before; if (k > 0) { diff.Add(combination(k + mcount, mcount)); } mcount = 0; } before = A[i]; } Modular ans = 1; foreach (Modular t in diff) { ans = ans * t; } Console.WriteLine((int)ans); }