CCC '26 J4 - Snail Path
View as PDFCanadian Computing Competition: 2026 Stage 1, Junior #4

A snail is crawling across an infinite grid of equally sized squares. It can crawl horizontally (east and west) or vertically (north and south), but it cannot crawl diagonally.
As the snail crawls, it leaves a trail of slime which makes the squares of the grid it touches slimy.
For example, after the snail below crawls east squares, there will be
slimy squares as
shown.

Input Specification
The first line of input contains a positive integer, , representing the number of movements
taken by the snail.
The next lines will specify the snail's movements, in order. Each movement will contain
an uppercase directional letter (
N, E, S, or W), followed by a positive integer less than or equal
to representing the number of squares the snail crawls in that direction.
The following table shows how the 15 available marks are distributed:
| Marks | Description | Bound |
|---|---|---|
| 4 | The snail will never crawl north or west of its initial position and will stay close to its initial position. |
|
| 3 | The snail will stay close to its initial position. | |
| 6 | The snail may crawl quite far from its initial position. | |
| 2 | The snail may crawl extremely far from its initial position. |
Output Specification
Output the non-negative integer, , which is the number of times the snail enters a slimy
square.
Sample Input 1
3
S2
N2
S3
Sample Output 1
4
Explanation for Sample Output 1

The diagram shows the snail's path. Whenever the snail enters a slimy square, a numbered circle is placed along the path.
Notice that a single slimy square can be entered multiple times.
Sample Input 2
3
S2
W15
N20
Output for Sample Input 2
0
Explanation of Output for Sample Output 2
The snail's path will consist of slimy squares. However, the snail never returns to a square
after leaving it, so the snail never enters a slimy square.
Comments