You are on page 1of 4

ACM International Collegiate Programming Contest, Asia-Amritapuri Site, 2011 Problem E: Append to Divide Honeydukes' Sweet Shop has

donated buckets of Bertie Bott's Every Flavor Beans ( a kind of jelly bean) to the students of Hogwarts School of Witchcraft and Wizar dry, one basket per House. But when the baskets (each labeled with the House num ber i) were delivered to the school, it was discovered that the number of sweets in each bucket were not exactly divisible by the number of students in that hou se A[i], and quarrels broke out about who got the extra sweets. Harry Potter to the rescue! Harry suggested using magic to make sure that every bucket contained a number of sweets that were exactly divisible by the number of students in the corresponding House. Can you tell us how many sweets were in the last bucket, given the way Harry's s pell worked: Given the number of students A[i] in each of the N houses, we define the array B [0..N] as follows. Initialize B[0] = 1 and for i = 1 to N, set B[i] to the small est integer obtained by appending one or more digits (0-9) to B[i-1] such that B [i] is divisible by A[i]. Find the value of B[N] modulo 1000000007. Input (STDIN): The first line contains the number of test cases T. T cases follow. Each test ca se consists of N in the first line followed by N space-separated integers on the next line denoting the values A[1..N]. Output (STDOUT): Output T lines, one for each case containing B[N] % 1000000007. Constraints: 1 <= T <= 10 1 <= N <= 1000 1 <= A[i] <= 1,000,000 Time limit : 3 secs Sample Input: 2 3 2 3 4 4 1234 56789 12345 6789 Sample Output: 1020 681070756 Notes: Case 1 : A[1..3] = {2,3,4}, B[0..3] = {1, 10, 102, 1020}.

ACM International Collegiate Programming Contest, Asia-Amritapuri Site, 2011 Problem D: Sub-sequences Having discovered that the Muggle-born* students of Hogwarts School of Witchcraf t & Wizardry are all on Facebook, Headmaster Dumbledore decided to go with the f low and has hired an ICPC World Finalist to teach all the students about this 'c ompooter-thingy' and how to program it to do its 'automatic spells'. Harry is st ruggling with his latest homework assignment, which is as follows: You are given a sequence of N numbers A[1..N]. Consider a sub-sequence** such th at the bitwise AND of all the numbers of the sub-sequence is equal to the bitwis e OR of all the numbers of the sub-sequence. Amongst all such sub-sequences, fin d the sub-sequence that has the maximum sum of the numbers, and print this maxim um sum. Can you help Harry finish his homework before he chews through all his writing q uills in frustration?

*Muggle-born: Magical children born of non-magical parents. Input (STDIN): The first line contains the number of test cases T. T cases follow. Each test ca se consists of N in the first line followed by N space-separated integers on the next line denoting the values A[1..N]. Output (STDOUT): Output T lines, one for each case containing the required answer(maximum sum as explained in the problem) for the corresponding case. Constraints: 1 <= T <= 20 1 <= N <= 10000 0 <= A[i] <= 10000 Time limit: 3 seconds Sample Input: 2 3 1 2 3 2 1 1 Sample Output: 3 2 Notes: **A sub-sequence is a sequence that can be derived from another sequence by dele ting 0 or more elements without changing the order of the remaining elements. A bitwise AND of two integers is the logical AND operation on each pair of corre sponding bits in the binary representation of the two integers. For example, 0101 (decimal 5) AND 0011 (decimal 3) = 0001 (decimal 1) The bitwise OR operation is the logical AND operation on each pair of correspond ing bits in the binary representation of the two integers. 0101 (decimal 5) OR 0011 (decimal 3) = 0111 (decimal 7)

Problem C: The Way to the Sorcerer's Stone Harry Potter has discovered that the Sorcerer's Stone of Immortality is hidden i n a dungeon. Having beaten the three-headed dog to get to the dungeon, Harry di scovers to his dismay that the stone is stored at the end of a long crooked corr idor with N-1 bends. At each bend in the corridor (and at the start) is either a Hungarian Horntail dragon that our intrepid hero has to defeat, or a flask of m agic potion that his teacher Snape has left for him. A dragon at junction 'i' t akes away S[i] strength points from him, and a potion at junction 'i' increase s Harry's strength by S[i]. If his strength drops to 0 or less, Harry dies, an d no magical stone can revive him. Note that Harry could be faced with a corridor having no bends (N=1) -- just one single straight section with a flask or a dragon at the start. Harry has used magic before entering the corridor to determine which bends conta in what, but lacks the basic simple mathematical skill to determine what minimum strength he needs to emerge from the corridor alive. Can you help him again wit h your compooter-thingy?

Input (STDIN): The first line contains the number of test cases T. T cases follow. Each test ca se consists of N in the first line followed by N space separated integers on th e next line. If the ith value is negative, it indicates that the ith segment has a dragon, otherwise it indicates a magic potion. Output (STDOUT): Output T lines, one for each case containing the required answer for the corresp onding case. Constraints: 1 <= T <= 100 1 <= N <= 100 -100 <= S[i] <= 100 Time limit: 2 seconds Sample Input:Corridor 3 3 0 0 -1 3 -2 -3 -4 4 2 -2 3 -3 Sample Output: 2 10 1

ACM International Collegiate Programming Contest, Asia-Amritapuri Site, 2011 Problem B: Count Dracula Vampires are supposed to enjoy counting so much that in old Europe they would sc atter some rice in coffins when they buried people, so that if the corpses came awake at night and became vampires, they would be kept busy until morning counti ng the grains of rice. But not all vampires are evil, and the one in the picture has promised to help H arry Potter fight Voldemort, the evil Dark Lord. But instead of learning the mag ic spells Harry has listed for him, our Count gets distracted and starts to coun t the letters in the spells. Can you help the Count count the letters in the spells quickly so that he can mo ve on to actually learning and memorizing the spells? Count Dracula Constraints The word will have at most 1000 characters. Time limit: 1 second Input (STDIN): The input contains a single word containing only lower-case letters. Output (STDOUT): Output each character followed by its count, separated by a single space. The ch aracters should appear in order 'a' to 'z', and only the letters having a positi ve frequency should be output. There should be no extra white space at the end o f each line. Sample Input: helloworld Sample Output: d 1 e 1

h l o r w

1 3 2 1 1

Problem A: Numerology Numerology is a difficult branch of magic, involving converting words and names to numbers, and deriving mystical significance from them. Harry Potter, our hero , has never had a good head for maths, being more at home killing evil wizards o r playing Quidditch, but his Divination teacher at Hogwarts school of witchcraft has assigned him a numerology project for the Progcon ceremony. She has given h im two integers A and B, and has asked him to list all the numbers in the range [A...B] inclusive that contain no digit that occurs more than twice in it, in de cimal representation. Harry could not figure out a magic spell to do this task, but you can perhaps help him with your 'compooter thingy' that Muggles* use. Input (STDIN): The first line contains the number of test cases T. Each of the next T lines con tains two integers, A and B. Output (STDOUT): Output T lines, one for each case containing the required answer for the corresp onding case. Constraints: 1 <= T <= 10000 1 <= A <= B <= 10^18 Time limit: 4 seconds Sample Input: 3 100 120 1000 1000 123 456 Sample Output: 20 0 331 Explanation: For the first case, all numbers except 111 satisfy the condition. *Muggles = non-magical people

You might also like