Mathematical and Physical Journal
for High Schools
Issued by the MATFUND Foundation
Already signed up?
New to KöMaL?

Problem I/S. 8. (April 2016)

I/S. 8. An ant executes the following commands: F (one step forward), L (left turn by 90 degrees), and R (right turn by 90 degrees). The ant receives \(\displaystyle N\) (\(\displaystyle 1\le N\le 100\,000\)) commands, and starts its path from the coordinate \(\displaystyle (0;0)\). You should figure out the number of possible final positions of the ant, if exactly one command, out of the \(\displaystyle N\) commands, is replaced by a different one (for example, instead of L at a certain point, it performs an F).

Your program should read the list of commands from the first line of the standard input. The first and only line of the standard output should contain the total number of final positions.

Sample input Sample output
FF3

Explanation. By changing exactly one command, we obtain FL, FR, RF or LF, corresponding to the final positions \(\displaystyle (0;1)\), \(\displaystyle (0;1)\), \(\displaystyle (1;0)\) and \(\displaystyle (-1;0)\).

Scoring and bounds. You can get 1 point for a brief and proper documentation clearly describing your solution. Nine further points can be obtained provided that your program solves any valid input within 1 second of running time.

The source code of your program with a short documentation—also describing which developer environment to use for compiling the source—should be submitted in a compressed file is8.zip.

(10 pont)

Deadline expired on May 10, 2016.


Statistics:

12 students sent a solution.
10 points:Gáspár Attila, Gergely Patrik, Janzer Orsolya Lili, Kis Lázár Bence, Kiss Gergely, Nagy Ábel, Nagy Nándor, Németh 123 Balázs, Noszály Áron, Olexó Gergely, Szakály Marcell.
7 points:1 student.

Problems in Information Technology of KöMaL, April 2016