How to Pebbling
And beat Gennady Korotkevich
Pebbling Odometer
(IOI 2012 #1)
• IOI problems are not that hard*
• This problem is a variation on Karel
o The robot taught in Java
o Can't do much except turn, move, and get/put beepers
• The language specification is much more limited
than Java's, however
• Very ad-hoc problem
o Tripped up Gennady Korotkevich (IOI 1st place 2009-2011)
o Only one perfect score on this problem
• Not Johnny Ho (missed .14 points)
• Score rounds to nearest integer :D
Basic Operations
Your odometer starts at (0, 0) and faces north
The +x axis points down and the +y axis points right
left - turn left
right - turn right (nicer than Karel!)
move - move forward one
get - remove one pebble
put - put one pebble
halt - exit
# can be used as comment
Flow Operations
• [label name]: - this defines a label (position marker)
• jump [label name] - move program execution to
• border [label name] - if program is facing border,
jump to label
• pebble [label name] - if current position has at least
one pebble, jump to label
Basic loop
pebble endloop
jump start
# this program moves the odometer forward until it
lands on a pebble
Another example
pebble getpebble_cont
jump endloop
jump start
# this program removes all pebbles from current
Alright... subtask #1
[9 pts]
At the beginning there are x pebbles in cell (0, 0) and
y in cell (0, 1), whereas all the other cells are empty.
Write a program that terminates with the odometer in
cell (0, 0) if x ≤ y, and in cell (0, 1) otherwise.
• Take pebble from (0, 0), and then take pebble from
(0, 1)
• Repeat
• If it's ever not possible to take a pebble from the
position you’re currently on, exit.
Subtask #3 [19 pts]
There are exactly two pebbles somewhere in row 0:
one is in cell (0, x), the other in cell (0, y); x and y are
distinct, and x + y is even.
Write a program that leaves the odometer in cell (0, (x
+ y) / 2), i.e., exactly in the midpoint between the
two cells containing the pebbles.
Find first pebble (on the left)
Add pebble to its right
Find next pebble (on the right)
Add pebble to its left
o unless there's a pebble there already, in which case you exit
• Repeat
Subtask #5 [32 pts]
There may be any number of pebbles in each cell of
the grid (between 0 and 15).
Write a program that finds the minimum, i.e., that
terminates with the odometer in a cell (i, j) such that
every other cell contains at least as many pebbles
as (i, j).
After running the program, the number of pebbles in
each cell must be the same as before running the
Graded based on # of commands in program :)
Target was 444, Johnny got 449
• First case: minimum # of pebbles is 0
o Scan through all locations in zigzag pattern
o If you find a location that has 0 pebbles, exit
• Second case: minimum # of pebbles is 1
For each location:
Take away 1 pebble
If the location has no pebbles left, put back pebbles and exit
Put back pebbles
• [Repeat 13 more times]
Solution [cont.]
• Optimally, make a program that generates your
program (label names must be unique)
• Need some more work to minimize code size
o Cascade putting back pebbles when exiting
• 15 points: solve subtask #1
• 20 points: solve subtask #3
• Please note that you start facing north at (0, 0), and
(x, y) means that the object is currently lying on row
x and column y
• We'll be somewhat lenient since an interpreter is not
yet available
o 30 points: write an interpreter for us too :)
Random flashcards
Arab people

15 Cards


46 Cards

African nomads

18 Cards


14 Cards

Create flashcards