← CSES Better

Rays

ZCO · 2017 · Zonal Computing Olympiad · ZCO17002

Open official problem ↗
Ask AI

Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.

Open Claude Desktop

grid · 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.

Problem grid; highlighted cells show the illustrated path
..W..W
ray ->cross W1...cross W2stop
  1. 1

    Scan each row

    Process each row from right to left while tracking the nearest black cell and the second white cell.
  2. 2

    Find first blocker

    For every empty cell, the closest applicable blocker determines its stopping column.
  3. 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 chars

Run output

Run your code to see output.