How to model this constraint using integer linear programming?
Assuming $x_j$ are binary.

The additional binary variable $y_i$ equals one if and only if when all $j$ are 1.

$$
\sum\limits_{j=i}^{i+p-1}x_j - p+1 \leq y_i \leq \frac{1}{p}\sum\limits_{j=i}^{i+p-1}x_j
$$

Then to have a unique $y_i$ equals one you add
$$
x \leq \sum_{i=1}^n y_i \leq (n-1)(1-x)+1
$$