Ask AI
Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.
Open Claude Desktopgrid · simulation · prefix-sums
The organizer’s problem statement is available at the official source link.
ray grid
A row scan needs only the next stopping wall
Each empty cell launches a rightward ray. It stops on a black cell or at the boundary; absent a black cell, it can pass one white cell and stops on the second. Sum inclusive travel lengths.
| . | . | W | . | . | W |
| ray -> | cross W1 | ... | cross W2 | stop |
- 1
Scan each row
Process each row from right to left while tracking the nearest black cell and the second white cell. - 2
Find first blocker
For every empty cell, the closest applicable blocker determines its stopping column. - 3
Sum ray lengths
Add the inclusive travel length; non-empty cells launch no ray.
Tools
1
2
3
4
5
6
7
8
9
10
11
12
Draft saved locally
|12 lines, 156 charsRun output
Run your code to see output.