15
ACM ICPC: The Northeast North America Regional Final Rochester Institute of Technology, November 14, 2015 Problem A: Billboard There are a lot of unused rectangular billboards along route R-55. The Big Green company wants to use them for advertising. They want to design a green rectangular poster and place it on the billboards on which it will fit (unfortunately the billboards are not standardized— they come in various sizes). The advertisement department figured out that the objective should be to maximize the total area of the posters deployed. A poster of size w × h feet fits on a billboard of size a × b feet if and only if w a and h b (that is, we cannot rotate the posters). At most one poster can be placed on each billboard. Input specification: The first line contains k, the number of problems. Then the description of the problems follows. Each problem is described on several lines. The first line contains n, the number of billboards, then n lines follow. The i-th line contains the width and height of the i-th billboard. Each width and height is a positive integer not larger than 30,000. You may assume that n is at most 5,000. Output specification: The output contains one line for each problem—the width and height of the poster which will cover the maximum total area when placed on all billboards on which it fits. If there are multiple optimal solutions then you must output an optimal solution with the smallest width. If there are multiple optimal solutions with the smallest width, from these solutions output the one with the smallest height. Sample input: 2 3 14 22 41 4 14 22 33 44 Sample output: 12 33 1

Problem A: Billboardicpc/questions/2015/NENA_Final_2015.pdf · ACM ICPC: The Northeast North America Regional Final Rochester Institute of Technology, November 14, 2015 Problem A:

  • Upload
    others

  • View
    17

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Problem A: Billboardicpc/questions/2015/NENA_Final_2015.pdf · ACM ICPC: The Northeast North America Regional Final Rochester Institute of Technology, November 14, 2015 Problem A:

ACM ICPC: The Northeast North America Regional Final

Rochester Institute of Technology, November 14, 2015

Problem A: Billboard

There are a lot of unused rectangular billboards along route R-55. The Big Green companywants to use them for advertising. They want to design a green rectangular poster and placeit on the billboards on which it will fit (unfortunately the billboards are not standardized—they come in various sizes). The advertisement department figured out that the objectiveshould be to maximize the total area of the posters deployed. A poster of size w×h feet fitson a billboard of size a× b feet if and only if w ≤ a and h ≤ b (that is, we cannot rotate theposters). At most one poster can be placed on each billboard.

Input specification:

The first line contains k, the number of problems. Then the description of the problemsfollows. Each problem is described on several lines. The first line contains n, the numberof billboards, then n lines follow. The i-th line contains the width and height of the i-thbillboard. Each width and height is a positive integer not larger than 30,000. You mayassume that n is at most 5,000.

Output specification:

The output contains one line for each problem—the width and height of the poster whichwill cover the maximum total area when placed on all billboards on which it fits. If thereare multiple optimal solutions then you must output an optimal solution with the smallestwidth. If there are multiple optimal solutions with the smallest width, from these solutionsoutput the one with the smallest height.

Sample input:

2

3

1 4

2 2

4 1

4

1 4

2 2

3 3

4 4

Sample output:

1 2

3 3

1

Page 2: Problem A: Billboardicpc/questions/2015/NENA_Final_2015.pdf · ACM ICPC: The Northeast North America Regional Final Rochester Institute of Technology, November 14, 2015 Problem A:

Explanation:

For the first input there are five optimal solutions: 1 × 2, 1 × 4, 2 × 1, 2 × 2, 4 × 1 (thesolutions are listed in order of increasing width, and, in case of the same width, in order ofincreasing height; each solution covers 4 square feet in total). For the second input there isone optimal solution: 3 × 3 (the solution covers 18 square feet in total since it fits on thelast two billboards).

2

Page 3: Problem A: Billboardicpc/questions/2015/NENA_Final_2015.pdf · ACM ICPC: The Northeast North America Regional Final Rochester Institute of Technology, November 14, 2015 Problem A:

ACM ICPC: The Northeast North America Regional Final

Rochester Institute of Technology, November 14, 2015

Problem B: Bridge

Zofka and her Dad started playing Bridge (the card game). As a result of this newfoundhobby, the number of various card sets at their home has been dramatically increasing.However, with so many cards, disorder has crept into the house. Cards on the table, floor,shelves, . . . Something had to be done—Zofka decided to organize the cards. She first col-lected all the cards and created a huge stack. As a first step, she wants to reorder the cardsso that all the red cards come before all the black cards. But the task is boring, so her mindwanders off: if she were to swap only adjacent cards, what is the smallest number of swapsshe needs to reorder the cards so that the red cards come before the black cards?

Input specification:

The first line contains k, the number of card stacks. Each stack is described on two lines.The first line contains an integer n > 0. The second line describes the card stack: It containsn strings of the form value suit, where value is either a number from 2 to 10, or one of theletters J, Q, K, A, and suit is a single letter chosen from s, h, d, c (these stand for spades,hearts, diamonds, and clubs—the hearts and diamonds are red, and the spades and clubsare black). The strings are separated by white space and describe the order of the cards onthe stack from the topmost card to the bottommost card. You may assume that n is at most100,000.

Output specification:

The output contains k lines. The i-th line corresponds to the i-th card stack. It contains thesmallest number of swaps of adjacent cards needed to reorder the stack so that, when goingthrough the stack from the top to the bottom, all red cards come before all black cards.

Sample input:

3

3

2_h A_s K_d

4

2_h A_d K_s K_s

6

A_d K_s 2_h K_c 10_h J_d

Sample output:

1

0

5

1

Page 4: Problem A: Billboardicpc/questions/2015/NENA_Final_2015.pdf · ACM ICPC: The Northeast North America Regional Final Rochester Institute of Technology, November 14, 2015 Problem A:

Explanation:

For the first sample input, we need to swap the A of spades with the K of diamonds. Thesecond sample input is already ordered properly. The third sample input needs 5 swaps, forexample: the 10 of hearts with the K of clubs, then the 2 of hearts with the K of spades,then the J of diamonds with the K of clubs, then the 10 of hearts with the K of spades, and,finally, the J of diamonds with the K of spades.

2

Page 5: Problem A: Billboardicpc/questions/2015/NENA_Final_2015.pdf · ACM ICPC: The Northeast North America Regional Final Rochester Institute of Technology, November 14, 2015 Problem A:

ACM ICPC: The Northeast North America Regional Final

Rochester Institute of Technology, November 14, 2015

Problem C: Cable Company

A new cable company in Rochester wants to provide internet access on each street. Therewill be several hubs on each street and each house needs to be connected to one of thehubs. The technicians already figured out how many hubs should be on each street, the onlyquestion is where to place them (and which house should be connected to which hub). Theobjective is to minimize the total length of cable used to connect the houses to the hubs.

Input specification:

The first line contains k, the number of streets in Rochester. Each street is described ontwo lines. The first line contains n, the number of houses on the street, and `, the numberof hubs to be placed on the street. The second line contains n numbers, the locations of thehouses on the street, in increasing order. You may assume that n is at most 10,000 and ` isat most 50. The locations are nonnegative integers not larger than 1,000,000,000.

Output specification:

The output contains one line for each street—the total cable length needed when the hubsare placed optimally, rounded down to the nearest integer.

Sample input:

2

5 1

1 2 3 4 1000

6 2

1 2 3 1000 1001 1010

Sample output:

1001

12

Explanation:

For sample input 1 the hub should be placed at location 3; the total length of the cable is2 + 1 + 0 + 1 + 997 = 1001. For sample input 2 the hubs should be placed at locations 2 and1001; the total length of the cable is (1 + 0 + 1) + (1 + 0 + 9) = 12.

1

Page 6: Problem A: Billboardicpc/questions/2015/NENA_Final_2015.pdf · ACM ICPC: The Northeast North America Regional Final Rochester Institute of Technology, November 14, 2015 Problem A:

ACM ICPC: The Northeast North America Regional Final

Rochester Institute of Technology, November 14, 2015

Problem D: Double Trouble

Suddenly, Thing One and Thing Two appeared out of nowhere in a house, each at a differentlocation. Not only that, but they somehow got synchronized: they do exactly the samemovements—when Thing One goes west, so does Thing Two; when Thing One goes east,so does Thing Two; and the same happens when they go south or north. They move atthe same time. The Things cannot go to a location where there is an obstacle (or the otherThing, unless it is moving away). For example, if there is an obstacle east of Thing One butnot of Thing Two, if they go east only Thing Two moves. Or, if east of Thing One thereis an obstacle and west of it there is Thing Two, if they try to move east, they will stay intheir current locations as Thing One is blocked by the obstacle and Thing Two by ThingOne. Things One and Two want to get out of the house, and they want to do so at the verysame time (that is, they want to leave the house with the same move). This is proving to bevery tricky. Please help!

Input specification:

The first line contains k, the number of houses Things One and Two visit. Each house isdescribed on several lines. The first line is empty. The next line contains two numbers mand n, where m×n are the dimensions of the current house (every house has a single floor).Then m lines follow, each contains a string of length n of symbols ‘.’, ‘x’, ‘1’, and ‘2’, where‘1’ stands for the initial location of Thing One, ‘2’ for Thing Two, ‘.’ is an empty locationwhere the Things can move to, and ‘x’ is an obstacle. Things One and Two start at locationswith no obstacles. You may assume that m,n ≤ 100.

Output specification:

The output contains k lines. The i-th line corresponds to the i-th house. It contains thesmallest number of moves Thing One and Thing Two need to get out of the house at thesame time; or the string STUCK if they cannot get out at the same time. In one moveeach Thing moves to its immediately adjacent location in the chosen direction, or stays putif that location contains an obstacle or the other Thing. The allowed directions are north(up), south (down), west (left), and east (right). The Things get out of the house if theymove north in row 1, south in row m, west in column 1, or east in column n.

Sample input:

2

3 8

x..xxx.x

.2..1..x

xx.xxxxx

3 8

1

Page 7: Problem A: Billboardicpc/questions/2015/NENA_Final_2015.pdf · ACM ICPC: The Northeast North America Regional Final Rochester Institute of Technology, November 14, 2015 Problem A:

xxxxxx.x

2...1..x

xx.xxxxx

Sample output:

6

STUCK

Explanation:

For the first sample input, the Things can follow this sequence of moves: east-north-east-south-north-north. For the second input, it is not possible for the Things to leave the houseat the same time.

2

Page 8: Problem A: Billboardicpc/questions/2015/NENA_Final_2015.pdf · ACM ICPC: The Northeast North America Regional Final Rochester Institute of Technology, November 14, 2015 Problem A:

ACM ICPC: The Northeast North America Regional Final

Rochester Institute of Technology, November 14, 2015

Problem E: Even or Odd?

After hearing about old magnetic tapes and information being stored on them, Filip decidedto replicate the idea by creating a long paper strip with a sequence of numbers. So far sogood, but what to do with it? Reading it over and over stopped being fun. Fortunately, heremembered that in school they learned about odd and even numbers. He tried to cut thepaper strip into contiguous segments so that in each segment the sum of its numbers is even.Then he tried to cut a different paper strip into contiguous segments with odd sums. Butwait! In how many different ways can he cut the paper strip into such segments?

All the numbers are nonnegative integers and Filip cannot cut through a number to splitit into two numbers.

Input specification:

The first line contains k, the number of paper strips. Each strip is described on two lines.The first line contains three integers n > 0, p ∈ {0, 1} and q > 0, where n stands for thenumber of numbers in the sequence on the strip, p = 0 if Filip wants even sums and p = 1 forodd sums, and q is the modulus to be used to output the answer. The second line describesthe sequence—it contains n nonnegative integers. Each of these integers, as well as n, is notlarger than 10,000,000.

Output specification:

The output contains k lines. The i-th line corresponds to the i-th paper strip. Let Ci bethe number of ways in which the paper strip can be cut into sequences with even sums forp = 0 or odd sums for p = 1. Since Ci might be too large, the i-th line contains Ci moduloq (that is, the remainder after dividing Ci by q).

Sample input:

3

5 0 10

1 7 2 3 5

3 0 10

1 7 3

5 1 3

1 7 2 3 5

Sample output:

4

0

1

1

Page 9: Problem A: Billboardicpc/questions/2015/NENA_Final_2015.pdf · ACM ICPC: The Northeast North America Regional Final Rochester Institute of Technology, November 14, 2015 Problem A:

Explanation:

For the first sample input, we can cut the sequence in the following ways into even-sumsegments: 1 7 / 2 / 3 5, or 1 7 2 / 3 5, or 1 7 / 2 3 5, or 1 7 2 3 5 (the last choice is just onesegment). Therefore, there are 4 ways to cut the sequence into even-sum segments. Since4 mod 10 = 4, we output 4.

For the second sample input, it is impossible to cut the sequence into even-sum segments.For the third sample input, we can cut it into odd-sum segments as follows: 1 / 7 2 3 5,

or 1 / 7 / 2 3 / 5, or 1 / 7 2 / 3 / 5, or 1 7 2 3 / 5. Therefore, the number of ways is 4 andthe output is 4 mod 3 = 1.

2

Page 10: Problem A: Billboardicpc/questions/2015/NENA_Final_2015.pdf · ACM ICPC: The Northeast North America Regional Final Rochester Institute of Technology, November 14, 2015 Problem A:

ACM ICPC: The Northeast North America Regional Final

Rochester Institute of Technology, November 14, 2015

Problem F: Palindromic Obsession

Countries on planet Pali follow the following rules for labeling one-way roads between cities:1) each road is labeled by a single lower-case letter, 2) for every city the roads leaving itreceive different labels (roads that enter a city can have identical labels). All roads on Paliare one-way. This system makes it very easy to give driving directions—they are just stringsof lower-case letters. Dezider wants to drive from his city to the capital but he has thefollowing peculiar set of constraints on the drive: 1) it has to take exactly ` days, 2) eachday he will drive on just one road, 3) the directions for the drive must be a palindrome (thatis, a string that reads the same forward and backward). He asked Ruzena (an agent in a tripplanning agency) to give him a list of all strings that satisfy his constraints. Ruzena toldhim that there are too many such strings. Now Dezider wants to know exactly how manystrings satisfy his constraints. Please, help Ruzena and write an algorithm that will countthe strings that satisfy Dezider’s constraints.

Input specification:

The first line contains k, the number of countries on planet Pali. Each country is describedon several lines. The first line contains four numbers: 1) n ≤ 10, the number of cities, 2)Dezider’s starting city (we refer to the cities by numbers 1, . . . , n), 3) the capital, 4) ` ≤ 100,the length of the drive. The next line contains m ≤ 100, the number of roads. Then m linesfollow, each describing a road. Each line describing a road consists of 1) the label of the road(a letter chosen from a, b, . . . , z), 2) the city where the road starts, and 3) the city wherethe road ends.

Output specification:

The output contains one line for each country. The line contains the number of palindromesof length ` that are valid directions from Dezider’s starting city to the capital.

Sample input:

3

2 1 2 10

4

a 1 2

a 2 1

b 1 2

b 2 1

2 1 2 99

4

a 1 2

a 2 1

b 1 2

b 2 1

1

Page 11: Problem A: Billboardicpc/questions/2015/NENA_Final_2015.pdf · ACM ICPC: The Northeast North America Regional Final Rochester Institute of Technology, November 14, 2015 Problem A:

Sample output:

0

1125899906842624

Explanation:

There is no even length path from city 1 to city 2 in the first example. In the second exampleall palindromes of length 99 that use letters a,b are valid.

2

Page 12: Problem A: Billboardicpc/questions/2015/NENA_Final_2015.pdf · ACM ICPC: The Northeast North America Regional Final Rochester Institute of Technology, November 14, 2015 Problem A:

ACM ICPC: The Northeast North America Regional Final

Rochester Institute of Technology, November 14, 2015

Problem G: Puzzle

The Puzzle company wants to create a new 3D puzzle collection. They are exploring a newpuzzle design, where a puzzle consists of a collection of pieces that fill an n-centimeter cube(that is, a cube with sides of length n centimeters). Each piece consists of one or more 1-centimeter cubes that are glued together at their faces. Each piece forms a single connected3D object.

A solution of the puzzle is a sequence of moves that removes all pieces of the puzzlefrom the n × n × n cube. A move is of the following form: First, choose a piece and anaxis-parallel direction. Then, if no other piece obstructs the movement, remove the pieceout of the n × n × n cube by moving it in the chosen direction. No other pieces move (thecompany’s secret technologies allow for a design with no gravity or friction). The companyneeds a program that checks if a puzzle can be solved; that is, whether there exists a sequenceof moves that removes all of the puzzle pieces.

Input specification:

The first line contains k, the number of puzzles. Then the descriptions of the puzzles follow.Each puzzle is described on several lines. The first line contains n, the size of the cube,then the description of n layers of the cube follow. Each layer is described on n lines, eachcontaining n integers from {1, . . . , 1000}. The numbers in the description indicate whichpiece the 1-centimeter cube belongs to (there are at most 1000 pieces). You may assumethat n is at most 50.

Output specification:

The output contains one line for each problem. It should contain the word YES if the puzzleis solvable and NO if the puzzle is not solvable.

Sample input:

2

2

4 4

4 3

4 3

3 3

3

1 1 1

1 2 1

1 1 1

1 2 1

2 2 2

1 2 1

1

Page 13: Problem A: Billboardicpc/questions/2015/NENA_Final_2015.pdf · ACM ICPC: The Northeast North America Regional Final Rochester Institute of Technology, November 14, 2015 Problem A:

1 1 1

1 2 1

1 1 1

Sample output:

YES

NO

Explanation:

In the first input we can move the piece number 3 down and then piece number 4 down(where the first layer with the three cubes of piece 4 is the top layer). In the second inputneither of the 2 pieces can move.

2

Page 14: Problem A: Billboardicpc/questions/2015/NENA_Final_2015.pdf · ACM ICPC: The Northeast North America Regional Final Rochester Institute of Technology, November 14, 2015 Problem A:

ACM ICPC: The Northeast North America Regional Final

Rochester Institute of Technology, November 14, 2015

Problem H: Top Secret

The Association for Cryptic Mysteries (ACM) is, naturally, trying to protect their secrets.They are currently dealing with a particularly challenging group of secrets that are furry, livein flat fields, and have been classified as level-n top secret, which means that they need tobe watched by n entities at all times. Fortunately, the ACM found a good location for thesesecrets: they own just the right kind of (infinitely large) field where exactly n stationaryrobots have been placed for a previous project. The robots cannot change location. Eachrobot has a single extremely powerful laser eye facing in a certain direction. The eye seeseverything in its direction as well as everything within 90 degrees to the right and 90 degreesto the left. Of importance, and as a remarkable engineering feat, the robot’s eye sees literallyeverything within this range, independent of the distance of the object. Please help the ACMcompute the area of the area that is watched simultaneously by all n robots.

Input specification:

The first line contains k, the number of fields. Each field is described on several lines. Thefirst line is empty. The second line contains one positive integer n, the number of robots(and the classification level of the secrets). Then n lines follow, each describing a robot. Thei-th line contains 4 integers xi, yi, ai, bi, where (xi, yi) are the coordinates of the i-th robot’slocation and (ai, bi) are the coordinates of a location in the direction of the i-th robot’s eye.You may assume that (xi, yi) is different from (ai, bi). All coordinates are, in absolute value,smaller than 1,000,000, and n is at most 1,000.

Output specification:

The output contains k lines. The j-th line corresponds to the j-th field. It contains the areaof the area that is watched simultaneously by all of the robots, rounded down to the nearestinteger. If the area is unbounded and its area is infinite, output the string UNBOUNDED.

Sample input:

2

3

5 1 3 3

0 4 4 4

2 6 2 2

1

0 0 1 0

Sample output:

50

UNBOUNDED

1

Page 15: Problem A: Billboardicpc/questions/2015/NENA_Final_2015.pdf · ACM ICPC: The Northeast North America Regional Final Rochester Institute of Technology, November 14, 2015 Problem A:

Explanation:

The first sample input is depicted below.

(5,1)

(0,4)

(0,0)

(2,6)

2