31.07.2015 Views

LITHUANIAN OLYMPIADS INFORMATICS

LITHUANIAN OLYMPIADS INFORMATICS

LITHUANIAN OLYMPIADS INFORMATICS

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Output. Output must be written to the output file. Firstly output the list of commandsof the first block, then – of the second one and etc.The numbers of command of the same block should be written in separate lines,i.e. one number per line. Zero (0) as an indicator of the end of each block must bewritten in a separate line. Numbers of commands that belong to the same block mustbe presented in ascending order.ExampleInput Output Comments12 6L 10 4L 11 3M 12 11L 11 5S 10 12L 6 5126030450Three operations are performed in the first step:L 10 4L 11 3L 6 5One operations is performed in the second step:M 12 11Two operations are performed in the third step:L 11 5S 10 12197. Puzzle. (Runtime limit – to 3 min.; processor Pentium 133 MHz) n×m table (nrows, m columns) is filled with positive numbers. Two fields of the table are called neighboringif they have a common border. The numbers of three fields make equality, if• the first two fields are neighboring;• the second and the third fields are neighboring;• after placing one of the below listed arithmetic operations between thefirst and the second field it is possible to put an equality sign between theremaining two fields.The possible operations are composition,subtraction multiplication, and integer division(div). For example there is given a table(n = m = 3). Some equalities are shown in thepicture. One can make other equalities, forexample 19–7=12;Note. Assume, that if arithmetic operation12 7 44 19 2112 21 1Picture 197.112 7 44 19 2112 21 1= is placed between numbers a and b, then we can analyze expressions a = b and b = a.Task. Write a program to calculate the maximum number of equalities that can be madein the given table. A number written to each field can come into one equality only, and it canbe used only once in this equality. The result should be the number of possible equalities.Input. Positive integers n and m (3 ≤ n, m ≤ 100) are given on the first line of theinput file. Remaining n lines contain a table, each line containing m positive numbers(not exceeding maxint), separated by space.Output The maximum number of equalities (one integer) must be written to theoutput file.21+=×=

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!