Sunteți pe pagina 1din 19

The 2011 ACM ASIA Programming Contest Kanpur Site Sponsored by IBM

Hosted by IIT Kanpur

8th December 2011 You get 19 Pages 10 Problems & 300 Minutes

Rules for ACM !CPC 2011 Asia Regional "an#ur $ite% 1. Solutions to problems submitted for judging are alled runs. !a h run is judged as a epted or reje ted b" the judge# and the team is notified of the results. Submitted odes should not ontain team or $ni%ersit" name and the file name should not ha%e an" &hite spa e. 2. The publi ran' list &ill not be updated in the last one hour. (o&e%er# notifi ation of a epted) reje ted runs &ill &'( be suspended at the last one hour of the ontest time. *. A ontestant ma" submit a larifi ation re+uest to judges. If the judges agree that an ambiguit" or error e,ists# a larifi ation &ill be issued to all ontestants. -. Contestants are not to on%erse &ith an"one e, ept members of their team and personnel designated b" the organi.ing ommittee &hile seated at the team des'. )ut the* cannot e+en tal, -ith their team members -hen the* are -al,ing aroun. the contest floor to ha+e foo. or an* other #ur#ose/ S"stems support staff ma" ad%ise ontestants on s"stem/related problems su h as e,plaining s"stem error messages. 0. 1hile the ontest is s heduled for a parti ular time length 2fi%e hours3# the ontest dire tor has the authorit" to alter the length of the ontest in the e%ent of unforeseen diffi ulties. Should the ontest duration be altered# e%er" attempt &ill be made to notif" ontestants in a timel" and uniform manner. 4. A team ma* be .is0ualifie. b* the Contest Director for an" a ti%it" that jeopardi.es the ontest su h as dislodging e,tension ords# unauthori.ed modifi ation of ontest materials# distra ting beha%ior or ommuni ating &ith other teams. 5. Team an bring up to 20 pages of printed materials &ith them. 6ut the" are not allo&ed to bring al ulators or an" ma hine/readable de%i es li'e mobile phone# C7# 787# Pen/dri%e# IP97# MP*)MP- pla"ers# flopp" dis's et . 6lan' papers &ill be pro%ided# if needed. :. 1ith the help of the %olunteers and e,ternal judges# the ontestants an ha%e printouts of their odes for debugging purposes. Passing of #rinte. co.es to other teams is strictl* #rohibite./ ;. (he .ecision of the 1u.ges is final/ 10. (eams shoul. inform the +olunteers if the* .o not get re#l* from the 1u.ges -ithin 10 minutes of submission/ 2olunteers -ill inform the 34ternal 5u.ges an. the e4ternal 1u.ge -ill ta,e further action/ (eams shoul. also notif* the +olunteers if the* cannot log in into the PC62 s*stem/ (his sort of com#lains -ill not be entertaine. after the contest/

11. Ten problems &ill be posed. So far as possible# problems &ill a%oid dependen e on detailed 'no&ledge of a parti ular appli ations area or parti ular ontest language. All problems re+uire "ou to read test data from the file as spe ified in the problem and &rite results to the standard output. 12. <ou an use an" of the standard librar" fun tions that "our hosen programming language pro%ides. In addition# "ou an use the math librar" in C)C==. <ou annot use an" other librar" that re+uires an e,tra flag to be passed to the ompiler ommand. If "ou do this# the judges &ill probabl" find a ode > ompilation error> in "our program. 1*. <our program is not permitted to in%o'e an" e,ternal programs. ?or e,ample# "ou annot use in C the s"stem all 2>grep ,". ab >3 to determine &hether the file ab ontains an o urren e of the string ,".. Violation of this rule may lead to disqualification from the contest.

1-. 9utput must orrespond e,a tl" to the pro%ided sample output format# in luding 2mis3spelling and spa ing. Multiple spa es &ill not be used in an" of the judges@ output# e, ept &here e,pli itl" stated. 10. <our solution to an" problem should be submitted for judging using the PC 2 soft&are onl". 9n e "ou ha%e submitted the solution# it &ill rea h the judges. The time it ta'es for "our problem to be judged &ill depend# among other things# on ho& bus" the judges are. 9n e "our submission has been judged# "ou &ill re ei%e a message through PC 2 indi ating the judgement. The judgement ma" be ><es># meaning that "our submission &as judged to be orre t. 9ther&ise "ou &ill get a message indi ating the problem &ith "our program. ?or e,ample# the message ma" be >In orre t 9utput># >9utput ?ormat !rror># >Compilation !rror># >Auntime !rror># >Aun Time Bimit !, eeded> et . 14. Programming st*le is not consi.ere. in this contest/ You are free to co.e in -hate+er st*le *ou #refer/ Documentation is not re0uire./ (he 1u.ges -ill onl* test -hether the in#ut out#ut beha+ior of *our #rogram is correct or not/

Problem A Strongly Connected Chemicals


Input: Standard Input Output: Standard Output

One type of chemical compounds is the ionic compound, because it is composed of positively charged ions (cations) and negatively charged ions (anions) in such a way that the compound as a whole is electrically neutral. Cations always attract anions and anions always attract cations. Now you are given m cations and n anions, and their connectivity information about which cation attracts which anion. Your task is to find a sub group from the cations and anions where there is at least one cation and at least one anion, such that all the cations in the group attract all the anions in the group. e call such a group as 'Strongly Connected Chemicals'. !s there can be many such groups, we want to find a group which has the highest cardinality. Cardinality means the number of members (cation and anion) in the group. Input "nput starts with an integer T ( 100), denoting the number of test cases. #ach case starts with a line containing two integers$ m and n (1 m, n 50). #ach of the ne%t m lines contains n characters (without space), each either '0' or '1'. "f the jth character in the ith line is 1, that means the ith cation attracts the jth anion, otherwise it doesn&t. utput 'or each case, print the case number and the ma%imum possible si(e of the strongly connected chemical group. Sample Input 2 3 4 1100 1110 0011 2 2 10 00 utput !or Sample Input Case 1: 4 Case 2: 2

Problem B Confusion in the Problem Set


Input: Standard Input Output: Standard Output

! small confusion in a problem set may ruin the whole contest. )o most of the problem setters try their best to remove any kind of ambiguity from the set. *ut sometimes it is not that important. 'or e%ample the mock of last contest. !s it was mock contest so we were not that serious with the set. e printed two problems, problem ! in +age , and +roblem * in +age -. .hen we remembered we have to give rule of the contest too. )o we printed the rule page. *ut we did not notice that the rule page was printed with +age -. e were stapling / pages together. 'irst rule page, then +roblem ! and at the last +roblem *. )o page numbers were, -, , and -. .his looked odd. *ut we already printed all the pages and if we want to fi% the issue we had no other way but print all the three pages. One among us suggested an e%planation0 1 ell, first - means there are - pages after this page. , also means there is , page after this page. *ut the last - means there are - pages before this page.2 "nteresting observation indeed. )o we came up with a rule which is, page numberings of all the n pages are valid, if the page number at a page denotes number of pages before this page or number of page after this page. )o with this rule, 3/, ,, -, 45 is valid but 3/, /, ,, /5 is not valid. Input 'irst line of the input file contains number of tests cases T ("#0). .hen T test cases follow. 'irst line of each test case contains a positive number n ("$10%&) number of pages in the problem set. .hen there are n space separated numbers in the following line each of which ranges from 0 to 10%#' utput 'or each test case output the test case number. .hen output (yes) (without the 6uotes) if the pages can be shuffled somehow so that the pages numbering is valid. Otherwise output (no). 'or the e%act format of the output please follow the sample. Sample Input 2 4 0 3 1 2 4 1 3 3 3 *+planation o! the samples, ,. .he pages can be shuffled in several ways so that the page numbering is valid. One of the valid shuffles are /, ,, -, 4. -. .here is no valid way to shuffle these. utput !or Sample Input Case 1: yes Case 2: no

Problem C
LCM E treme
Input: Standard Input Output: Standard Output

'ind the result of the following code$


unsigned long long allPairLcm(int n){ unsigned long long res = 0; for( int i = 1; i<=n;i++) for(int j=i+1;j<=n;j++) res += lcm(i, j);// lcm means least common multiple return res; }

! straight forward implementation of the code may time out. Input "nput starts with an integer T ( -5000), denoting the number of test cases. #ach case starts with a line containing an integer n (1 n 5.10#). utput 'or each case, print the case number and the value returned by the function 'all/air0cm(n)'. !s the result can be large, we want the result modulo -#&. Sample Input 4 2 10 13 100000 utput !or Sample Input Case 1 ! Case ! 10"# Case " "111 Case $ %1"$#&!&&$$%%%!"'!$

Problem ! "etromino
Input: Standard Input Output: Standard Output

7e%ter wants to completely cover a & + 1 board using 1 tetrominoes. #very cell in the grid has to be covered by e%actly one piece and no piece is allowed to go outside the board. !nd no piece can be rotated or flipped. ! tetromino is a connected set of 8 tiles. !ll ,9 possible tetrominoes that can be used (any number of times) are shown below$

!ssume that all the ,9 pieces have different colors. Now your task is to find the total number of ways 7e%ter can cover the board. .wo board configurations are different if a cell can be found where the colors are different. Input "nput starts with an integer T ( -0), denoting the number of test cases. #ach case starts with a line containing an integer 1 (1 1 102). utput 'or each case, print the case number and the number of ways to fill the board modulo 1000 000 003. Sample Input 4 1 2 3 12 utput !or Sample Input Case 1: 1 Case 2: 4 Case 3: 23 Case 4: 15747348

Problem E Blade and S#ord


Input: Standard Input Output: Standard Output

You may have played the game &*lade and )word&, it&s an action game. :owever, in this problem we are actually solving one stage of the game. 'or simplicity, assume that the game stage can be modeled as a -4 grid which has m rows and n columns. .he cells are categori(ed as follows$ ,) ''' represents an empty space. .he player can move through it. -) '5' represents wall, and the player cannot move through it. You can assume that the boundaries of the grid will be walls. /) '.' means a teleporting cell, once the player moves into this cell, he must choose any other teleporting cell where he will be taken to. *ut if he cannot find a desired teleporting cell, he will die. :owever, after moving to the desired teleporting cell, he can either move to an ad;acent cell, or he can teleport again using the same procedure. 8) '/' means the position of the player and there will be e%actly one cell containing &/'. <) '4' means the destination cell and there will be e%actly one cell containing '4'. Now you are given a stage and the player starts moving. "t takes one unit of time for the player to move to any ad;acent cell from his current position. .wo cells are ad;acent if they share a side. One unit of time is needed for the teleporting service= that means taking the player from one teleporting cell to any other teleporting cell. Your task is to find the minimum possible time unit re6uired for the player to reach the destination cell. Input "nput starts with an integer T ( 100), denoting the number of test cases. #ach case starts with a line containing two integers$ m and n (6 m, n -00). #ach of the ne%t m lines contains n characters denoting the stage. .he given stage follows the restrictions stated above. utput 'or each case, print the case number and the minimum re6uired time. "f it&s impossible for the player to reach the destination cell, print 'impossi7le'. )ee the samples for details.

Sample Input 2 4 10 ########## #.P..#*..# #*......D# ########## 3 9 ######### #P.#..D.# #########

utput !or Sample Input Case 1: 6 Case 2: impossible

Problem $ "he $alling Circle


Input: Standard Input Output: Standard Output

.he little >erry is now developing a game. You know developing game is a comple% thing as there are many challenges involved. 'or e%ample little >erry is now stuck with some geometric pattern and asks for your help. .o help him you do not need to know every detail of the game, only information of the particular frame should suffice. :ere it is$ .wo circles are attached with the wall. .hey are fi%ed. ! line is attached to the circles in such a way that it touches both the circles and each of the touching points has lower Y coordinate than that of the corresponding center of the circle. Now another circle is dropped on the set up from above (higher Y coordinate). .he circle will fall along the Y a%is with a constant velocity of , unit per second until it touches the line. hen it touches the line, it starts to rotate along the line towards the circle that has lower Y coordinate touching point with a constant angular velocity of , revolution per second. hen it touches the circle at the end, it stops. "f both the touching points have same Y coordinate, i.e. the line is parallel to the ? a%is, then the falling circle stops as soon as it touches the line. Now given the setup, you need to find the time after which the falling circle will stop.

Figure 1: Initial Setup, the circle starts falling

Figure 2: The circle touches the line and starts to rotate

Figure 3: The circle touches the circle in the end and stops Input .he first line of the input will denote the number of cases T (T 10000). #ach of the test cases will contain / lines describing / circles. .he first two lines will give information of the circles at the ends and the /rd line will describe the circle that will fall. #ach of the circles are described with / integers +, y and r (8100000 +, y 1000009 0 " r 100). You are assured that the falling circle will always touch the line first and will drop between the fi%ed circles. !lso, note that the falling circle will not bounce, no matter what its height is. utput 'or each case output the case number and the time re6uired in seconds. !bsolute difference less than 1e8# will be considered correct. Sample Input 2 0 0 5 100 1 6 50 60 10 0 0 5 100 1 8 50 60 10 utput !or Sample Input Case 1: 55.000000 Case 2: 56.511165

Problem % My &isit to Spring Secret


Input: Standard Input Output: Standard Output

@ast year in "C+C Aanpur, we introduced you to the story of well0known programmers& mythology )pring )ecret. "f you never heard of this, don&t bother ;ust yet. "t is not really important for the purpose of solving this problem. .his year, powered by an assumption that this mysteriously unknown ob;ect is a place, " myself have decided to visit it. *ut being the pu((ling mythology that it is, " don&t really know if " will be able to recogni(e a spring secret when " see one. Your task is to help me there. "n the conte%t of this problem, lets assume " have visited a series of places. #ach city has a single capital #nglish letter label. .his label is not any uni6ue identifier so multiple places may have the same label, don&t get confused about that. Now we somehow know that if two consecutive places that " have visited has a label &S' then the first place is a )pring )ecret. hereas if a place with label & S' is followed by a place with any other label than & S', then the first place is an inter Obvious. +lease report the count of )pring )ecret and inter Obvious for each test case. Input .here will be at most 100 test cases in the input file. #ach case is contained in a line by itself that contains a series of capital #nglish letters together. You can safely assume that there will be no blank space, punctuation marks or any invalid character in a test case. #ach letter describes the label of a place as described above. .he places are given in chronological order of my visit. You can also assume that " shall visit between - and 50 places in a single test case. utput 'or each test case, print a line in the format, 1 Case :, ; < =2, where : is the case number, ; is the number of )pring )ecrets while = is the number of inter Obviouses present in the test case. Sample Input 2 SABCDPGSSMNSTRSS SSSSS *+planation o! the !irst sample case, "n the first sample test cases, the - S at position B, C,< are )pring )ecrets while the / S at position ,, 9 and ,- are inter Obviouses. utput !or Sample Input Case 1: 2 / 3 Case 2: 4 / 0

Problem '
Scrabble
Input: Standard Input Output: Standard Output

"n this problem, youDll need to find the optimal word to place on a partially completed )crabble game. "nstead of using your previous knowledge of the game, only use the rules described below. !lso, the rules described here are only a subset of all the rules of the game. *ut it should be enough for the purpose of the problem. >ame 4escription, .he game is played by two to four players on a s6uare board with a ,<0by0,< grid of cells (individually known as Fs6uaresF) and ,44 tiles. #ach of the s6uares accommodates a single letter tile. .he words are formed across and down in crossword fashion. .he game contains ,44 tiles, 9B of which are marked with a letter and a point value ranging from , to ,4. .he other two tiles are blank and carry no point value.

Se?uence o! play, *efore the game a dictionary is selected for the purpose of ad;udicating any challenges during the game. .he letter tiles are put in an opa6ue bag. .he players sit circularly and take turns in playing tiles from their EracksD. 7uring a turn, a player has to play at least one tile on the board, adding the value of all words formed to the player&s cumulative score. ! proper play uses one or more of the player&s tiles to form a contiguous string of letters that make a word (the play&s Fmain wordF) on the board, reading either left0to0right or top0to0bottom. .he main word must either use the letters of one or more previously played words or else have at least one of its tiles hori(ontally or vertically ad;acent to an already played word. "f words other than the main word are formed by the play, they are scored as well, and are sub;ect to the same criteria of acceptability. !ny contiguous string of letters on the board will always have to be a valid word. hen the board is blank, the first word played must cover the center s6uare (Bth row and Bth column). .he word must consist of at least two letters, e%tending hori(ontally or vertically. ! blank tile may take the place of any letter. "t then remains that letter for the rest of the game. "t scores no points regardless of what letter it is. Scoring,

'or each word formed in the play, add the normal point value of all other letters in the word (whether newly played or e%isting). "f a player uses all se@en of the tiles in the rack in a single play, a bonus of <4 points is added to the score of that play.

The pro7lem, Given a partially played valid scrabble board, a dictionary, point value of the letters and a rack, you have to find a placement of tiles such that point scored will be ma%imal. Input 'irst line of input will contain an integer 1 (1 "$ 1,A00,000), no of words in the dictionary. Ne%t 1 lines will contain one word each. ords will be given in le%icographic order and in lowercase letters. .he length of a word will be between - and 15. Ne%t line will contain -# integers separated by a space. i0th integer will denote the point value of i0th character. )o, first integer will be the point value of B, second integer will be the value of C etc. Ne%t line will contain an integer denoting number of test cases. !fter that T (T "$ 50) test cases will follow. You will use the dictionary and point values described above on all subse6uent test cases and 6ueries. #ach test case starts with describing the current state of the board in 15 lines. #ach line will correspond to one row of the board and will contain 15 characters. #ach s6uare on the board will either be a lowercase letter or a dot (E'D), denoting an empty s6uare. !t most two of the s6uares can also be uppercase letters denoting a blank tile used as that particular character. You can assume that the board is valid (it is a result of se6uence of valid plays). Ne%t will be an integer D (D "$ 50) denoting number of 6ueries. #ach of the ne%t D lines will contain a string of length at most 3 denoting the 1racE2. *lank tiles will be denoted by E.D. .here will be at most - blank tiles. You can assume that the summation of number of blank tiles in board and in rack will be at most -. utput .he output for each case should start with a line in the format E Case CD where C is the case number starting from ,. .hen there will be D lines in the format EQuery i: total_pointsD where i is the serial of the 6uery (starting from ,), total()oints is the ma%imum achievable points. Note that for some cases total_points can be (ero if no valid placement can be found.

Sample Input 12 abacus abdicate activism award chocoholic euphoria flexible sit sits torpedo torrential zoologist 1 3 3 2 1 4 2 4 1 8 5 1 3 1 1 3 10 1 1 1 1 4 4 8 4 10 1 ............... ............... ............... ............... ............... ............... ............... .......abacus.. .........b..i.. .........d..t.. .........i..... .........c..... .........a..... .........t..... .........e..... 4 eupho** tope** rdwa activsm

utput !or Sample Input Case 1 Query 1: 61 Query 2: 8 Query 3: 9 Query 4: 69

Illustration,

(ere# upper ase letters are used for blan' tiles.

Problem I
An A(erage %ame
Input: Standard Input Output: Standard Output

!lice and *ob has ;ust learned how to find average of some numbers. .hey got really e%cited and decided to come up with a game about finding average. .he game works like this, at the start of game a se6uence of numbers is written. .hen there will be several rounds in the game. "n first round !lice will say a number + and *ob has to select two inde% i and j. @etDs say the average of the uni6ue numbers between ith number and jth number is y. .hen !lice gets a7s(+8y) points in that round. "n ne%t round !lice and *ob switch the role. .he game continues this way. hile !lice and *ob en;oy playing this game, they hate calculating average of uni6ue numbers. )o, they are asking you, their only programmer friend, to write a program that calculates the average for them. Input 'irst line of input is a number T (T "$ 100). T test cases follow. 'irst line of each test case is an integer n (0 " n " 10%&) representing the length of number se6uence. Ne%t line consists n space separated integer representing the se6uence. #ach of these integers has absolute value less than 10%2. Ne%t line has an integer ? (? " 10%5). ? lines follow, each representing a 6uery. #ach 6uery has two space separated integer i, j (1 "$ i "$ j "$ n). utput 'or each case output ? lines representing average of uni6ue elements of corresponding range rounded # digits after decimal points. No case will have output whose rounding changes if the 10%82 is added to or subtracted from answer.

Sample Input 2 10 1 2 3 4 4 3 2 1 -1 0 4 1 4 1 10 3 5 8 10 3 1 1 0 1 1 3

utput !or Sample Input Case 1: 2.500000 1.500000 3.500000 0.000000 Case 2: 0.500000

*+planation !or second ?uery in !irst sample .he range is (,,,4) which includes ten numbers (,, -, /, 8, 8, /, -, ,, 0,, 4). Hni6ue numbers in this ranges are (,, -, /, 8, 0,, 4) whose average is ,.< *+planation !or third ?uery in !irst sample .he range is (/,<) which includes three numbers (/, 8, 8). Hni6ue numbers in this ranges are / and 8 whose average is /.<

Problem )
Permutation Counting
Input: Standard Input Output: Standard Output

7e%ter considers a permutation of first 1 natural numbers good if it doesn&t have + and +F1 appearing consecutively, where (1 + " 1). 'or e%ample, for 1$6, all good permutations are$ 1/ C1# *# 2D 2/ C2# 1# *D 3/ C*# 2# 1D Input "nput starts with an integer T ( 10000), denoting the number of test cases. #ach case starts with a line containing an integer 1 (1 1 10#). utput 'or each case, print the case number and the number of good permutations modulo 1000 000 003. Sample Input 3 2 3 5 utput !or Sample Input Case 1: 1 Case 2: 3 Case 3: 53

S-ar putea să vă placă și