Gerald and Giant Chess
HardRating 2200CodeforcesCombinatorics & Modular Arithmetic
Approach hintTry it first, then revealHide
Sort the black cells and let dp[i] count paths to cell i that avoid every earlier black cell: the binomial count minus routes that first hit some black cell j. Treat the target as the final cell. O(n^2).