Back
Close

A child's play

Statement

 Goal

For several years now, in elementary schools, we have seen the emergence of a new educational model, playful programming. The students must program a small robot using assembly blocks. This allows them to get familiar with programming from an early age while exercising their logic and perception of space.

You are a student at one such school. The purpose of the exercise is simple: your teacher has crafted a circuit for your robot, told you how many moves n the robot may make, and you must find out the final position of the robot at end of execution.

To do this you need to know some principles of robot operation.
– When the robot encounters an obstacle (represented by #) it turns right (on same operation) until there's no obstacle ahead anymore. Otherwise on an empty area (represented by .) it moves straight ahead.
– The robot initially moves upwards.
– The robot stops after n moves.
– The top left corner represents the coordinates (0,0)
– The robot's environment is represented as follows, where O is the robot's initial position:
...#........
...........#
............
............
..#O........
..........#.
Input
Line 1: Width w and height h of the map.
Line 2: Number n of operations to be performed by the robot
Next n lines: The map where the robot moves with . representing a free space, # an obstacle and O the starting position.
Output
¤ The final position x y (separated by a space) of the robot at end of execution, where x is the horizontal position and y is the vertical position.
Constraints
¤ 0 < w <= 20
¤ 0 < h <= 10
¤ The obstacles are placed in such a way that the robot will never leave the map
¤ The robot will never be blocked between obstacles
¤ n < 2^53
Example
Input
12 6
987
...#........
...........#
............
............
..#O........
..........#.
Output
7 1

Tags

Difficulty
Easy

Test cases
Test example Test
Input
12 6 987 ...#........ ...........# ............ ............ ..#O........ ..........#.
Output
7 1

Validator example Validator
Input
12 8 987 ....#....... ........#... ............ ...#O....... .......#.... ............ ............ ............
Output
7 3

Test real case Test
Input
12 8 1234321 ....#....... ........#... ...........# ...#O....... ...#........ .......#.... ...........# ....#.......
Output
4 2

Validator real case Validator
Input
12 8 987654 ....#....... ........#... ...........# ...#O....... ...#........ .......#.... ...........# ....#.......
Output
7 2

Test 3 Test
Input
14 10 123456789 ..#........... ....#..#...... .#O.....#..... .............. .............. .......##...#. ............#. .#........###. .#.#.......... ..............
Output
2 1

Validator 3 Validator
Input
14 10 12345678 ..#........... ....#..#...... .#O.....#..... .............. .............. .......##...#. ............#. .#........###. .#.#.......... ..............
Output
3 1

Test 4 Test
Input
16 10 12321123212397 ...#...###...... ...............# .#.............. ...........#.... ................ ................ ..#O............ .......####..... #............... ###############.
Output
6 6

Validator 4 Validator
Input
16 10 123211232123 ...#...###...... ...............# .#.............. ...........#.... ................ ................ ..#O............ .......####..... #............... ###############.
Output
14 8

Test 5 Test
Input
20 10 1234567898765434 ...#.......#........ .......#..........#. ..#O........#....... ......#............. .................... ........#......#.... .................... ..#......#.......... ..............#..... ..................#.
Output
4 1

Validator 5 Validator
Input
20 10 987654321234567 ...#.......#........ .......#..........#. ..#O........#....... ......#............. .................... ........#......#.... .................... ..#......#.......... ..............#..... ..................#.
Output
4 2

Test 6 Test
Input
6 5 15 ###### ##...# #.O#.# #....# ######
Output
2 3

Validator 6 Validator
Input
6 5 14 ###### ##...# #.O#.# #....# ######
Output
2 2

Test 7 Test
Input
4 4 2 #### #..# #O.# ####
Output
2 1

Validator 7 Validator
Input
4 4 3 #### #..# #O.# ####
Output
2 2

Test 8 Test
Input
5 5 13 ##### #...# #.#.# #...# #O###
Output
3 1

Validator 8 Validator
Input
5 5 11 ##### #...# #.#.# #...# #O###
Output
1 1

Test 9 Test
Input
5 5 4 ##### #...# #.#.# #...# ##O##
Output
1 3

Validator 9 Validator
Input
5 5 6 ##### #...# #.#.# #...# ##O##
Output
1 1

Loop detection 1 Test
Input
12 6 4000000000 ..##..#..... ...........# ............ ............ .#.O........ ..........#.
Output
5 4

Loop detection 1 Validator
Input
12 6 4000000000 ..###.#..... ...........# ............ ............ .#..O....... ..........#.
Output
4 4

Loop detection 2 Test
Input
12 6 4000000000 ..##..#..... ...........# ......O..... ............ .#.......... ..........#.
Output
2 2

Loop detection 2 Validator
Input
12 6 4000000000 ..##..##.... ...........# .......O.... ............ .#.......... ..........#.
Output
2 1

Solution language

Solution

Stub generator input