Distinct Neighbours
You are given three positive integers $N, x$, and $y$. Count the number of arrays $P$ of length $N$ such that: - $P_1 = P_N = 1$ - There are exactly $x$ indices $i$ such that $P_i=1$ - There are exactly $y$ indices $i$ such that $P_i=2$ - There are exactly $N-x-y$ indices $i$ such that $P_i=3$ - $P_i \neq P_{i+1}$ for each $1 \leq i \lt N$ Since the answer can be large, output it modulo $998244
HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17
CodeSearch Tutor
Hints, not spoilers — it won’t hand over the full solution unless you insist.
Sign in to chat with the tutor and save your progress.
Sign in to start