Tasks Task CETIRI OKTALNI TAJNA DEJAVU CUDAK REDOKS Memory limit (heap+stack) Time limit (per test) standard (keyboard) standard (screen) 32 MB 64 MB 1 second 3 seconds Number of tests 5 5 8 10 10 10 Points per test 4 4 5 5 8 9 Total points 20 20 40 50 80 90 300 Note: The evaluation system has two Intel Pentium 4 3.0 GHz processors and is running the Linux operating system. The following compile options are used for different languages: C: O2 s static std=c99 lm C++: O2 s static lm Pascal: O1 XS
1. CETIRI Mirko has chosen four integers which form an arithmetic progression. In other words, when the four numbers are sorted, then the difference between each pair of adjacent elements is constant. As has become usual, Mirko lost one of the numbers and also is not sure whether the remaining three are in the correct (sorted) order. Write a program that, given the three remaining numbers, finds the fourth number. The contains 3 integers between 100 and 100 on a single line, separated by single spaces. Note: the data will guarantee that a solution, although not necessarily unique, will always exist. any number which could have been the fourth number in the sequence. 4 6 8 10 10 1 4 7
2. OKTALNI Slavko is learning about different numeral systems. Slavko is not the brightest when it comes to math, so he is starting out converting binary numerals to octal. The algorithm Slavko uses is this: Pad the binary numeral with zeros on the left until the number of digits is divisible by three. Group adjacent binary digits into groups of 3 digits. Replace each group of binary digits with the corresponding octal digit (as in the table on the right). Write a program that converts a binary numeral to octal so that Slavko can verify his results. 000 0 001 1 010 2 01 100 4 101 5 110 6 111 7 The contains a binary numeral. The number of digits will be less than 100, and the first digit will be 1. the number in octal. 1010 12 11001100 314
3. TAJNA Every evening, little Ivica sends secret messages to little Marica through e-mail. Knowing Ivica's e-letter travels unguarded through the network on its way to Marica's e-mailbox, they have decided to encrypt every message using the following algorithm: Suppose Ivica's message consists of N characters. Ivica must first find a matrix consisting of R rows and C columns such that R C and R C = N. If there is more than one such matrix, Ivica chooses the one with the most rows. Ivica writes his message into the matrix in row-major order. In other words, he writes the first segment of the message into the first row, the second segment into the second row and so on. The message he sends to Marica is the matrix read in column-major order. Marica has grown tired of spending her precious time deciphering Ivica's messages, so you must write a program to do it for her. The contains the received message, a string of lowercase letters of the English alphabet (with no spaces). The number of letters will be between 1 and 100. the original (decrypted) message. bok bok koaski kakosi boudonuimilcbsai bombonisuuladici Third sample test: Ivica wants to send the message "bombonisuuladici" containing 16 letters. He can use a 1 16, 2 8 or 4 4 matrix. Of these, the 4 4 has the most rows. When the message is written into it, the matrix looks like this: b o m b o n i s u u l a d i c i
4. DEJAVU N points are placed in the coordinate plane. Write a program that calculates how many ways we can choose three points so that they form a right triangle with legs parallel to the coordinate axes. A right triangle has one 90-degree internal angle. The legs of a right triangle are its two shorter sides. The first line of contains the integer N (3 N 100 000), the number of points. Each of the following N lines contains two integers X and Y (1 X, Y 100 000), the coordinates of one point. No pair of points will share the same pair of coordinates. the number of triangles. In 40% of all test cases, N will be less than 100. In 70% of all test cases, N will be less than 10 000. Scoring 3 4 2 2 1 0 5 1 2 2 1 2 2 2 3 3 2 4 6 10 10 20 10 10 20 20 20 30 20 30 30 8
5. CUDAK Božo is a strange little boy. Every day he tires his friends with strange questions. Today's question is: how many integers in the interval [A, B] are there such that the sum of their digits is S, and which is the smallest such number? Write a program that answers Božo's question so that he can get some sleep. The contains three integers A, B and S (1 A B < 10 15, 1 S 135). The first line should contain the number of integers in the interval with the digit sum equal to S. The second line should contain the smallest such integer. The data will guarantee that the first number is at least 1. Scoring For correctly ting one of the two numbers you will receive 50% of the score. Note: if you want to receive credit for just the second number, be sure to something (0, for example) as the first number so the judge can interpret your correctly. 1 9 5 1 5 1 100 10 9 19 11111 99999 24 5445 11499
6. REDOKS Luka is not paying attention in class again, while the teacher is explaining redox reactions. Instead of paying attention, he is playing with analog dials. An analog dial is a small device which always shows one digit between 0 and 9. It also contains a small button which increases the number by 1 (unless it is 9, in which case it is changed to 0). Luka has N such dials on his desk, numbered 1 to N left to right, and two sheets of paper for him to write on. Luka's game starts with him setting the dials in some starting configuration, which he then writes onto the first sheet. Luka then does the following M times: Choose two integers A and B (1 A B N) and write them down on the first sheet. Calculate the sum of numbers on dials numbered between A and B (inclusive), and write the sum down on the second sheet. Press the button once on all dials numbered between A and B. Just as he had finished his game, the teacher noticed him, and took away all his dials and the second sheet of paper. Given the contents of the first sheet, help him calculate the numbers on the second sheet. The first line contains two integers N and M (1 N 250 000, 1 M 100 000). The second line contains the initial configuration of the dials, N decimal digits with no spaces. The first digit is the number initially on dial 1, the second digit the number on dial 2 and so on. Each of the following M lines contains two integers A and B (1 A B N). M lines, the sums calculated by Luka, in order in which he calculated them. Scoring In 30% of all test cases, the numbers N and M will be less than 1000.
6. REDOKS 4 3 1234 1 4 1 4 1 4 10 14 18 4 4 1234 1 1 1 2 1 4 1 4 9 16 7 5 9081337 3 7 3 7 17 23 1 19 5