9. Blank papers will be provided. If the judges agree that an ambiguity or error exists. unauthorized modification of contest materials. Systems support staff may advise contestants on system‐related problems such as explaining system error messages. The decision of the judges is final. A contestant may submit a clarification request to judges. the contest director has the authority to alter the length of the contest in the event of unforeseen difficulties. notification of accepted/ rejected runs will NOT be suspended at the last one hour of the contest time. Volunteers will inform the External Judges and the external judge will take further action. A team may be disqualified by the Contest Director for any activity that jeopardizes the contest such as dislodging extension cords. Teams should inform the volunteers if they do not get reply from the judges within 10 minutes of submission. a clarification will be issued to all contestants. Each run is judged as accepted or rejected by the judge. the contestants can have printouts of their codes for debugging purposes. 5. 8. The public rank list will not be updated in the last one hour. But they cannot even talk with their team members when they are walking around the contest floor to have food or any other purpose. 10. distracting behavior or communicating with other teams. floppy disks etc. Solutions to problems submitted for judging are called runs. 6. Eight problems will be posed. MP3/MP4 players. Should the contest duration be altered. All problems require you to read test data from the standard input as specified in the problem and write results to the standard output. While the contest is scheduled for a particular time length (five hours). 2. 11. problems will avoid dependence on detailed knowledge of a particular applications area or particular contest language. 7. Pen‐drive. Team can bring up to 25 pages of printed materials with them. IPOD. Passing of printed codes to other teams is strictly prohibited. But they are not allowed to bring calculators or any machine‐readable devices like mobile phone. So far as possible.
3
. Contestants are not to converse with anyone except members of their team and personnel designated by the organizing committee while seated at the team desk.Rules for ACM‐ICPC 2012 Asia Regional Kharagpur Site
1. Submitted codes should not contain team or University name and the file name should not have any white space. 3. CD. With the help of the volunteers and external judges. Teams should also notify the volunteers if they cannot log in into the PC^2 system. However. every attempt will be made to notify contestants in a timely and uniform manner. and the team is notified of the results. if needed. DVD. This sort of complains will not be entertained after the contest. 4.

4
. you cannot use in C the system call ("grep xyz abc") to determine whether the file abc contains an occurrence of the string xyz. The time it takes for your problem to be judged will depend. among other things. 13. the message may be "Incorrect Output". "Run Time Limit Exceeded" etc. on how busy the judges are.12. The judgment may be "Yes". Your solution to any problem should be submitted for judging using the PC2 software only. you can use the math library in C/C++. including (mis)spelling and spacing. 15. Multiple spaces will not be used in any of the judges’ output. 16. Output must correspond exactly to the provided sample output format. except where explicitly stated. Programming style is not considered in this contest. You can use any of the standard library functions that your chosen programming language provides. meaning that your submission was judged to be correct. Otherwise you will get a message indicating the problem with your program. it will reach the judges. Once your submission has been judged. "Runtime Error". "Output Format Error". If you do this. Once you have submitted the solution. The judges will only test whether the input‐output behavior of your program is correct or not. 14. For example. "Compilation Error". In addition. You cannot use any other library that requires an extra flag to be passed to the compiler command. Violation of this rule may lead to disqualification from the contest. You are free to code in whatever style you prefer. the judges will probably find a code "compilation error" in your program. you will receive a message through PC2 indicating the judgment. For example. Documentation is not required. Your program is not permitted to invoke any external programs.

and D will be arriving in your college soon. B. D) will occupy a room marked X. Each team has K members. Teams from four regional colleges A. 102. followed by the number of ways the rooms can be marked modulo 1000.Problem A: Room Allotment
Input: Standard Input Output: Standard Output Problem Code: RoomAllot Your college is holding the finals of a regional inter‐college sports meet. and a team member of college X (X = A. B. Each room has to be marked as A. the teams have requested you for some special considerations for their accommodation. it is also decided that they will each be allotted a separate room to make their stay comfortable. Since the rooms are small. print the case no. It is vacation period and the hostels are empty. so it is decided that they will be put up in your hostel for the duration of the meet. followed by a space. In how many ways can you mark the rooms? Input: First line contains the number of test cases N. Each test case has a single line containing a single integer. However. or D. Teams C and D do not trust each other and have both specifically requested that no member of their team should be put up in a room with a member of the other team in an adjoining room. Sample Input Sample Output 2 Case 1: 680 4 Case 2: 520 7
5
. C. Output: For each test case.…(100 + 4K)) in one long corridor of your hostel. you have been entrusted with allotting them rooms from a set of 4K side‐by‐side rooms (numbered 101. the value of K (3 ≤ K ≤ 100). C. followed by a colon. C. As a member of the organizing team. and since the rooms are empty because of the vacation. B. Teams A and B have both requested that each member of their team should have another member of their own team in an adjoining room (the room to the left or right). 103.

This page intentionally left blank
6
.

so that none of them have to work much more than the other while still having similar profit potential. they also employ a number of salesmen for door‐to‐door selling in smaller cities. the number of cities (0 < K ≤ 200). A being senior. gets the cities with higher total profit. first line of input contains K.
Sample Input 2 5 100 210 100 75 340 4 300 250 280 290 Sample Output Case 1: 415 410 Case 2: 570 550
7
.Problem B: Travelling Salesmen
Input: Standard Input Output: Standard Output Problem Code: Salesmen
Company X sells cosmetic products of different types. If the profits are not equal. Output: For each test case. followed by the profits of A and B separated by a single space. In addition to selling their products through stores in larger cities. print the case no. Can you find out the profits that A and B can earn? Input: The first line contains the number of test cases N. In addition. followed a space. For each test case. The two salespersons would like to fairly distribute the cities between themselves. Two salesman are assigned to sell the products in K small cities in a region. Hence they would like to distribute the cities such that the number of cities allotted to each do not differ by more than one. followed by a colon. they would like to ensure that the difference between the total profits of the salesmen (sum of the profits of the cities that they visit) is minimized among all such possible distributions. Some cities are more lucrative than others in terms of sales potential ‐ each city is associated with an integer profit value estimated from the previous year’s sales data. and the second line contains a sequence of K integers with the profit values of each city (profit value of a city is between 1 and 400).

This page intentionally left blank
8
.

12 15. Output: For each test case. The storage charge being significant. and are moved off to the site as soon as they are loaded. Sample Input Sample Output 2 Case 1: 327 5 3 Case 2: 4169 7. You can assume that enough trucks are available so that a truck is always available when a machine is sent off and the next one is to be loaded. Can you help company X to decide how to load the trucks and send off the machines? Input: The first line contains the number of test cases N. Second line contains a sequence of K real numbers (upto 2 decimal place maximum) indicating the weight in ton of each machine. Third line contains a sequence of K real numbers (up to 2 decimal place maximum) indicating the loading time in hour for each machine.Problem C: Loading Machines
Input: Standard Input Output: Standard Output Problem Code: MachineLoad A construction company X has imported a number of large machinery by ship for a project. X employs a fleet of large trailer trucks to move the machinery from the dock to its project site. For each test case. Machines are loaded one by one sequentially on the trucks by a single group of laborers. followed by a space. and X continues to pay the storage charge for the machine until it is loaded and sent off. there is a considerable loading time for each machine. X would like to move the machines away to the project site as fast as possible paying the minimum total storage cost to the dock authorities. The machines being large. followed by the total storage cost paid by X rounded off to the nearest integer.6 2 4 7 20.25 3. print the case number.7 1.5
9
.75 12 8.4 5 4 3.5 6. which have been unloaded and stored in a warehouse in the dock.4 5. first line contains two integers.45 1. followed by a colon. the number of machines K (0 < K ≤ 200) and the storage charge C per hour per ton.5 1.5 1. The dock authorities charge X a storage charge per hour per ton for each machine.5 5 4.

This page intentionally left blank
10
.

number of songs K (0 < K ≤ 150) and number of types T (0 < T ≤ 6). (other than for the first move) a player must choose a song from the pool which has not been chosen yet. The players alternate their moves. and which has not been chosen yet. However. A team that cannot find a matching song at any step when its turn comes up is eliminated. The next team at each step has to sing a song that starts with the last letter of the song sung by the previous team. Can you find the number of songs in the pool for which A has a winning strategy? Input: The first line contains the number of test cases N. For the first move. they decide to try out a variation just for fun. and whose first letter matches the last letter of the previous song. but would like to start with a song that increases his chance of winning depending on the choices that B makes in the game. The songs are to be chosen from a common pool of songs that is known to both of them. B graciously asks A to start the game. The game continues until a single team is left. This is followed by K lines. Two songs are of the same type if they have both the same first letter and the same last letter. During its turn. Player A chooses any song from the pool. But that seems difficult. The game ends when there is no song in the pool which begins with the last letter of the previous song. A can start with any song. given that A does not know what choices B is going to make as the game has not even started. Two friends A and B would like to play Antakshari.Problem D: Antakshari
Input: Standard Input Output: Standard Output Problem Code: Antakshari Antakshari is a game that can be played by two or more teams. For each test case. each line containing one song (a string of characters of maximum length 50)
11
. T < K. since they have played Antakshari several times before. which has not been sung before by any team so far. the first line contains two integers. in which the teams take turns to sing songs. The first team starts the game by singing a song. The player who was the last to choose successfully wins in this case. A winning strategy for A is a choice of the first song which will guarantee that A will win irrespective of the choices that B makes subsequently at any step of the game.

. followed by a space. followed by a colon. print 0). Sample Input Sample Output 2 Case 1: 5 8 4 Case 2: 4 a night in the woods and There Were Shepherds an Old Fashioned Christmas all you need is elves silver anklets stories of ghosts step into durga puja a walk in the mountain 7 3 a night in the woods and There Were Shepherds an Old Fashioned Christmas all you need is elves silver anklets stories of ghosts step into durga puja
12
. followed by the number of songs for which A has a winning strategy (if there is no such song.Output: For each test case. print the case no.

13
. Hence the money that each volunteer asks for may vary. followed by a space. In fact. Not having too much money and resources. Input: First line contains the number of test cases N. food etc.) for a nominal amount of money to cover their basic expenses like travel. but now has to choose some of the volunteers. while minimizing the total amount of money it has to spend. they get the last day off on leap years!). Different volunteers may have to travel from different places and may have offered their services for different number of days. the ending day of the offer (an integer from 1 to 365). there is at least one volunteer present. starting day ≤ ending day. first line contains the number of offers K (0 < K ≤ 500). it cannot accept an offer for only some of the days in the offer.. You have to help the NGO to find a set of volunteers to accept. someone or other has volunteered to work for each day of the year! Each volunteer has offered to work for some number of consecutive days (fixed dates. Having a choice. Output: For each test case. and hence their travelling expenses etc. may be different.Problem E: Choosing Volunteers
Input: Standard Input Output: Standard Output Problem Code: Volunteer An NGO would like to man a community helpline 365 days a year (yes. The next K lines each contains 3 integers. For each test case. followed by the total amount of money that the NGO has to spend. followed by a colon. etc. The starting and ending day are specified assuming that the days in a year are numbered from 1 to 365. For each offer. 12th to 21st June. and with little money at its disposal. it would like to choose a set of volunteers such that on each of the 365 days. it will have to accept the offer fully (paying the full amount) or reject it fully (paying nothing). like 3rd to 5th April. The NGO is thrilled with so many offers. the starting day of the offer (an integer from 1 to 365). and the amount of money asked (an integer). They were surprised to get a large number of offers in response to the advertisement. they advertise for volunteers who will be willing to offer their services for some nominal fee for the next year. print the case no. For all offers.

The second line prints the number of students M in the first group. sorted by increasing student id with one space between successive ids. followed by the number of friends P the student has. The third line prints the same for the second group. it decided to form the two groups such that for any student X in one group. that is not a problem for the school. at least ⎡P/2⎤ of his friends are in the other group. given the large number of students and their friend lists. Output: For each test case. followed by a space. and would like you to help. Each of these lines contains an integer student id (the students are numbered from 1 to K). if X has P friends. followed by a colon in the first line. the first line has the number of students K (0 < K ≤ 1000). N. the focus is to ensure that the students interact with other students who are not their friends. Note that some student may have no friends. However. You can print the groups in any order. at least half of his/her friends are in the other group. The school knows the friends of all students (assume that X is a friend of Y means Y is also a friend of X) and will have to form the groups. Can you tell the school how to divide the students into the two groups? Input: The first line contains the number of test cases. followed by P integers for the student ids of the P friends.
15
. the school is finding it very difficult to do this. in which case the line will contain 0 for P with no following integer (for example. one for each of the students. For each test case. just “23 0” if student with id 23 has no friends). The group sizes may be skewed and each group may have any number of students. Thus. print the case number. to promote interactions between diverse groups. followed by K lines. a school decided to divide their students into two groups and take them on a day‐long excursion on two different days with different group activities planned.Problem F: Social Game
Input: Standard Input Output: Standard Output Problem Code: GroupFriends In order to foster interaction among the children. However. followed by the student ids of the M students in the group.

rectangular. 50 per square meter. It is assumed that sides of the square farmlands are parallel to x‐ and y‐ axes. and 2 meters high. minimum x‐coordinate).. followed by a colon. the ratio of wall‐area to floor‐ area of each farmhouse is arbitrarily large.e. The cost of fencing is Rs. Mr. By definition. and the 3rd and the 4th lines correspond to the bottom‐left and the bottom‐right farmhouses respectively. If two (or more) corners have the same minimum x‐coordinate. But the strange part is that each farmhouse has a very large number of walls. there are four lines. The 2nd line is for similar information corresponding to the top‐right farmhouse. N. Firm would like to find the least cost (rounded to nearest integer) that he has to spend for the fencing. The four farmhouses are located in four adjacent equal‐area square farmlands so that each farmland contains one farmhouse only. The corners are specified either in clockwise or in anticlockwise order. The 1st line contains the number of corners C (3 < C ≤ 20000) of the top‐left farmhouse. each corner is defined by the intersection of two consecutive walls. Can you help Mr. and the walls have arbitrary orientations.Problem G: Farmhouse Fencing
Input: Standard Input Output: Standard Output Problem Code: FarmFencing Mr Firm has four strange farmhouses whose walls are all vertical. Mr Firm wants to fence his four farmhouses by a single fencing of height 2 meters so that the four farmhouses lie within the common fenced area. then the one with minimum y‐coordinate among them appears first.. print the case no. followed by a space. Output: For each test case. Firm to find the money he will have to spend for fencing his farmlands? Input: The first line contains the number of test cases. As a result. Note that the new fencing may include some wall of the old fencing and some corner of a farmhouse may touch the fence. followed by (x. and the union of the four square farmlands is a square which is 4 times as large as each square farmland. For each test case. followed by the cost of fencing rounded to the nearest integer. y) coordinates of its corners. starting from the leftmost corner (i.
17
.

That is. For tiling (to be discussed below).
Figure 1: Polygon to Fracture
You are also given a set of 27 primitive patterns as shown in Figure 2. y). Every pattern is specified by its width (w) and height (h). use the center to uniquely specify the position of a pattern. The sides of the polygon are aligned with 0°. 90°. The left‐bottom corner of this rectangle is taken to be the center of the pattern. c> where (x. or diagonal. Any pattern placed anywhere on the integer plane can be specified by a triplet: <(x. Rest of the dimensions follows from the geometry (the fact that sides must be horizontal. y) is the center and c is the code of the pattern (Figure 2. the sides are horizontal. vertical or diagonal). A sample polygon is shown in Figure 1. Table 1).
19
. 45°. or 135°. Every pattern is assumed to be contained in a minimal Isothetic (axis aligned) rectangle. vertical.Problem H: Pattern Fracturing
Input: Standard Input Output: Standard Output Problem Code: PatternFracture You are given a simple (non‐self‐intersecting) polygon with integer coordinates. The properties of the patterns are listed in Table 1.

A polygon can have tilings with different costs. A sample tiling is shown in Figure 3. C(P) = 7. Figure 4 and Figure 5 present two alternate tilings with costs C(P) = 115 and C(P) = 86. This is computed by counting the red links of unit length. Note that the total number of diagonal sides in the tiling patterns used is not the same as the number of diagonal sides in the stitch. as a single long diagonal side in the stitch may have diagonal sides from more than one tiling pattern. In Figure 3. Hence no stitch is counted where the border of a pattern touches the border of the polygon.
21
. For example for the polygon P (Figure 1).
Figure 3: Sample tiling of a polygon
Every tiling has a cost computed as follows: Cost C(P) of tiling a Polygon P = Total length of horizontal stitches + Total length of vertical stitches + Total number of diagonal sides in the tiling patterns used The stitches are computed between pairs of patterns only.You may use any number of patterns of any type (Figure 2) in tiling the polygon.

Input: The first line contains the number of tests cases N. The second test case is for the polygon shown in Figure 6. print the case number.
22
.
Figure 4: Tiling of polygon in Figure 1 with Cost = 115
Figure 5: Tiling of polygon in Figure 1 with Cost = 86
Given a polygon P. the first line contains the number of vertices M (0 < M ≤ 10. For each test case. left‐to‐right order. For the exact format. followed by the cost of the solution in the first line.000) of the polygon to be tiled. Output: For each test case. Each of the next M lines contains the x and y coordinates of a vertex of the polygon. The sample output for Case 1 shows the tiling shown in Figure 3. However. The second line will contain the number of patterns P used in the tiling. followed by a space. followed by a colon. Each of the following P lines lists the patterns (specified as triplets) in the tiling in the bottom‐to‐top. the first test case is the polygon in Figure 3. The vertices are listed in the counterclockwise order starting from the bottom‐most left‐most vertex of the polygon. see the sample input and output given next. So you decide to do as well as you can and find a tiling that reduces the cost. you want to find a tiling that minimizes C(P). finding the exact minimum is hard. In the sample input.

in SampleInput. Note that this does not imply that your code.txt 1 2 3 Cost of a “good” tiling ≤ 100 ≤ 3400 ≤ 7500
24
. Test case no. we have given you a sample input file SampleInput.txt with three test cases in the above format. The cost of a “good” tiling for the three cases is shown in the table below. when submitted. You solution should aim to achieve a tiling with cost equal to or lower than that.To help you in estimating the quality of solutions you get. will pass the actual test cases.