Problem A Self-Assembly

Similar documents
Computation Theory Finite Automata

Johns Hopkins Math Tournament Proof Round: Automata

Volume vs. Diameter. Teacher Lab Discussion. Overview. Picture, Data Table, and Graph

Recursive Definitions

February 2017 February 18, 2017

Algorithms Exam TIN093 /DIT602

Problem A. Crystal Ball Factory

Sample Project: Simulation of Turing Machines by Machines with only Two Tape Symbols

UNIVERSITY OF NORTH CAROLINA CHARLOTTE 1995 HIGH SCHOOL MATHEMATICS CONTEST March 13, 1995 (C) 10 3 (D) = 1011 (10 1) 9

Solution: By direct calculation, or observe that = = ( ) 2222 = =

Problem A. Union of Doubly Linked Lists

R.2 Number Line and Interval Notation

CS6901: review of Theory of Computation and Algorithms

Chapter 1A -- Real Numbers. iff. Math Symbols: Sets of Numbers

Introduction to Techniques for Counting

CSCI3390-Second Test with Solutions

Finite Mathematics : A Business Approach

Problem solving. Build a better mouse trap and the world will beat a path to your door

CS3719 Theory of Computation and Algorithms

1. Fill in the three character code you received via in the box

MATH 243E Test #3 Solutions

Solutions to 2015 Entrance Examination for BSc Programmes at CMI. Part A Solutions

Deterministic Finite Automaton (DFA)

PROBLEMS OF MARRIAGE Eugene Mukhin

2014 State Competition Sprint Round Problems 1 30

Organization Team Team ID#

RMT 2014 Power Round Solutions February 15, 2014

CHAPTER 12 Boolean Algebra

Final Exam (Version B) December 16, 2014 Name: NetID: Section: 1 2 3

Lecture notes on Turing machines

Algebra. Table of Contents

UNIT-III REGULAR LANGUAGES

Solutions to Exercises Chapter 2: On numbers and counting

Rational Numbers. a) 5 is a rational number TRUE FALSE. is a rational number TRUE FALSE

Investigation Find the area of the triangle. (See student text.)

Solutions to Quiz 1. Problem 1 (20 points). Suppose S(n) is a predicate on natural numbers, n, and suppose. k N S(k) S(k + 2). (1)

Topic 1. Solving Equations and Inequalities 1. Solve the following equation

BC Calculus Diagnostic Test

Mock AMC 10/12. djmathman. November 23, 2013 INSTRUCTIONS

Regular Expressions and Finite-State Automata. L545 Spring 2008

Induction and Recursion

Module 8 Probability

Deep Algebra Projects: Algebra 1 / Algebra 2 Go with the Flow

SCIENCE 10 LAB ANALYSIS OF SOLUTIONS

(Refer Slide Time: 0:21)

Natural Numbers Positive Integers. Rational Numbers

Math.3336: Discrete Mathematics. Combinatorics: Basics of Counting

Final Exam Version A December 16, 2014 Name: NetID: Section: # Total Score

Math 230 Final Exam, Spring 2008

Read this before starting!

chapter 12 MORE MATRIX ALGEBRA 12.1 Systems of Linear Equations GOALS

Formal Specification of Distributed Systems: Communicating Sequential Processes (CSP)

Chapter 1 Logical Reasoning

1999 Probe I. 1) If f(x) = x 4 c. - 1, then f, b 0, equals. d) 1

The University of Melbourne BHP Billiton School Mathematics Competition 2007 INTERMEDIATE DIVISION SOLUTIONS

RMT 2014 Power Round February 15, 2014

Written test, 25 problems / 90 minutes

Algorithms: COMP3121/3821/9101/9801

(2) Generalize De Morgan s laws for n sets and prove the laws by induction. 1

1 of 5 10/4/2009 8:45 PM

NUMERICAL MATHEMATICS & COMPUTING 7th Edition

Full file at

2012 ACM-ICPC Asia Hatyai Regional Programming Contest

FURTHER MATHEMATICS Units 3 & 4 - Written Examination 2

UC Berkeley CS 170: Efficient Algorithms and Intractable Problems Handout 22 Lecturer: David Wagner April 24, Notes 22 for CS 170

PUTNAM TRAINING MATHEMATICAL INDUCTION. Exercises

UNIT-II. NONDETERMINISTIC FINITE AUTOMATA WITH ε TRANSITIONS: SIGNIFICANCE. Use of ε-transitions. s t a r t. ε r. e g u l a r

Critical Reading Answer Key 1. D 2. B 3. D 4. A 5. A 6. B 7. E 8. C 9. D 10. C 11. D

Read this before starting!

Section 6.2 Notes Page Trigonometric Functions; Unit Circle Approach

1 More finite deterministic automata

arxiv: v2 [cs.ds] 3 Oct 2017

Counting Methods. CSE 191, Class Note 05: Counting Methods Computer Sci & Eng Dept SUNY Buffalo

Chapter 14: Finding the Equilibrium Solution and Exploring the Nature of the Equilibration Process

17.1 Binary Codes Normal numbers we use are in base 10, which are called decimal numbers. Each digit can be 10 possible numbers: 0, 1, 2, 9.

The Celsius temperature scale is based on the freezing point and the boiling point of water. 12 degrees Celsius below zero would be written as

Name Period Date. Use mathematical reasoning to create polynomial expressions that generalize patterns. Practice polynomial arithmetic.

Page Points Score Total: 100

Efficient Reassembling of Graphs, Part 1: The Linear Case

Archway Learning Trust. Mathematics Department. Year 11 Mock 2 (February 2019) Foundation Tier. Paper 2. Name: Teacher:

NOTES ON 2009 MEMORANDUM

Proofs, Strings, and Finite Automata. CS154 Chris Pollett Feb 5, 2007.

Counting. Spock's dilemma (Walls and mirrors) call it C(n,k) Rosen, Chapter 5.1, 5.2, 5.3 Walls and Mirrors, Chapter 3 10/11/12

Periodic Table and Atomic Structure: Secret Agent Student Advanced Version

Advanced topic: Space complexity

Problem A. Gift. Input. Output. Examples. All-Ukrainian School Olympiad in Informatics Codeforces, April, 12, 2011

Chapter 4.1 Introduction to Relations

Lesson 1 WHAT S A GROUP?

UNIT 2: REASONING WITH LINEAR EQUATIONS AND INEQUALITIES. Solving Equations and Inequalities in One Variable

1. Problem I calculated these out by hand. It was tedious, but kind of fun, in a a computer should really be doing this sort of way.

First Midterm Examination

ECS 120: Theory of Computation UC Davis Phillip Rogaway February 16, Midterm Exam

1. (A) Factor to get (2x+3)(2x 10) = 0, so the two roots are 3/2 and 5, which sum to 7/2.

Boolean circuits. Lecture Definitions

Essential Questions Warren County Public Schools First Grade Common Core Math Planning and Pacing Guide (1 st Quarter)

Unit 3: Linear and Exponential Functions

CSCI3390-Assignment 2 Solutions

Understanding and Using Variables

Warm-Up 11 Solutions. Peter S. Simon. December 1, 2004

Grade 7/8 Math Circles November 21/22/23, The Scale of Numbers

Transcription:

Problem A Self-Assembly Time Limit: 4 seconds Automatic Chemical Manufacturing is experimenting with a process called self-assembly. In this process, molecules with natural affinity for each other are mixed together in a solution and allowed to spontaneously assemble themselves into larger structures. But there is one problem: sometimes molecules assemble themselves into a structure of unbounded size, which gums up the machinery. You must write a program to decide whether a given collection of molecules can be assembled into a structure of unbounded size. You should make two simplifying assumptions: 1) the problem is restricted to two dimensions, and 2) each molecule in the collection is represented as a square. The four edges of the square represent the surfaces on which the molecule can connect to other compatible molecules. In each test case, you will be given a set of molecule descriptions. Each type of molecule is described by four two-character connector labels that indicate how its edges can connect to the edges of other molecules. There are two types of connector labels: An uppercase letter (A,..., Z) followed by + or. Two edges are compatible if their labels have the same letter but different signs. For example, A+ is compatible with A but is not compatible with A+ or B. Two zero digits 00. An edge with this label is not compatible with any edge (not even with another edge labeled 00). Assume there is an unlimited supply of molecules of each type, which may be rotated and reflected. As the molecules assemble themselves into larger structures, the edges of two molecules may be adjacent to each other only if they are compatible. It is permitted for an edge, regardless of its connector label, to be connected to nothing (no adjacent molecule on that edge). Figure G.1 shows an example of three molecule types and a structure of bounded size that can be assembled from them (other bounded structures are also possible with this set of molecules). Figure A.1: Illustration of Sample Input 1. ACM-ICPC World Finals Dress Rehearsal 2014 Problem A: Self-Assembly 1

Input The input consists of a single test case. A test case has two lines. The first line contains an integer n (1 n 40 000) indicating the number of molecule types. The second line contains n eight-character strings, each describing a single type of molecule, separated by single spaces. Each string consists of four two-character connector labels representing the four edges of the molecule in clockwise order. Output Display the word unbounded if the set of molecule types can generate a structure of unbounded size. Otherwise, display the word bounded. Sample Input 1 Sample Output 1 3 A+00A+A+ 00B+D+A- B-C+00C+ bounded Sample Input 2 Sample Output 2 1 K+K-Q+Qunbounded ACM-ICPC World Finals Dress Rehearsal 2014 Problem A: Self-Assembly 2

Problem B Curvy Little Bottles Time Limit: 1 second In her bike rides around Ekaterinburg, Jill happened upon a shop that sold interesting glass bottles. She thought it might make an interesting project to use such bottles for measuring liquids, but this would require placing markings on the bottles to indicate various volumes. Where should those volume marks be placed? Jill formalized the problem as follows. Assume a bottle is formed by revolving a shape that is the same as the graph of a polynomial P between x = x low and x = x high around the x-axis. Thus the x-axis is coincident with a vertical line through the center of the bottle. The bottom of the bottle is formed by a solid circular region at x = x low, and the top of the bottle, at x = x high, is left open. The first sample input represents a bottle formed using the simple polynomial 4 0.25x, with x low = 0 and x high = 12. The bottom of this bottle is a circle with a radius of 4, and the opening at the top is a circle with a radius of 1. The height of this bottle is 12. Volume markings are in increments of 25. Given a polynomial P, x low, x high, and the volume increment between successive marks on the bottle, compute the distances up from x low for the marks at successive volume increments. A mark cannot be made past the top of the bottle, and no more than the first 8 increments should be marked. Assume the value of P is greater than zero everywhere between x low and x high. Input The input consists of a single test case. A test case has three lines of bottle data: Line 1: n, the degree of the polynomial (an integer satisfying 0 n 10). Line 2: a 0, a 1,..., a n, the real coefficients of the polynomial P defining the bottle s shape, where a 0 is the constant term, a 1 is the coefficient of x 1,..., and a n is the coefficient of x n. For each i, 100 a i 100, and a n 0. Line 3: x low and x high, the real-valued boundaries of the bottle ( 100 x low < x high 100 and x high x low > 0.1). inc, an integer which is the volume increment before each successive mark on the bottle (1 inc 500). Output Display the volume of the full bottle on one line. On a second line, display the increasing sequence of no more than 8 successive distances up from the bottom of the bottle for the volume markings. All volumes and height marks should have absolute error of at most 10 3. If the bottle does not have a volume that allows at least one mark, display the phrase insufficient volume. No test case will result in a mark within 0.01 from the top of the bottle. The volume of the bottle will not exceed 1 000. All distances for marks on a bottle differ by at least 0.04. ACM-ICPC World Finals Dress Rehearsal 2014 Problem B: Curvy Little Bottles 3

Sample Input 1 1 4.0-0.25 0.0 12.0 25 Sample Output 1 263.8938 0.5137 1.0639 1.6579 2.3058 3.0215 3.8262 4.7543 5.8677 Sample Input 2 Sample Output 2 0 1.0 0.0 10.0 10 31.4159 3.1831 6.3662 9.5493 Sample Input 3 Sample Output 3 0 1.7841241161782 5.0 10.0 20 50.0000 2.0000 4.0000 Sample Input 4 Sample Output 4 1 4.0-0.25 0.0 12.0 300 263.8938 insufficient volume ACM-ICPC World Finals Dress Rehearsal 2014 Problem B: Curvy Little Bottles 4

Problem C Fibonacci Words Time Limit: 1 second The Fibonacci word sequence of bit strings is defined as: 0 if n = 0 F (n) = 1 if n = 1 F (n 1) + F (n 2) if n 2 Here + denotes concatenation of strings. The first few elements are: n F (n) 0 0 1 1 2 10 3 101 4 10110 5 10110101 6 1011010110110 7 101101011011010110101 8 1011010110110101101011011010110110 9 1011010110110101101011011010110110101101011011010110101 Given a bit pattern p and a number n, how often does p occur in F (n)? Input The input consists of at most 100 test cases. The first line of each test case contains the integer n (0 n 100). The second line contains the bit pattern p. The pattern p is nonempty and has a length of at most 100 000 characters. Output For each test case, print the number of occurrences of the bit pattern p in F (n). Occurrences may overlap. The number of occurrences will be less than 2 63. Sample Input 1 Sample Output 1 6 10 7 10 6 01 6 101 96 10110101101101 5 8 4 4 7540113804746346428 ACM-ICPC World Finals Dress Rehearsal 2014 Problem C: Fibonacci Words 5

This page is intentionally left blank.

Problem D Low Power Time Limit: 3 seconds You are building advanced chips for machines. Making the chips is easy, but the power supply turns out to be an issue since the available batteries have varied power outputs. Consider the problem of n machines, each with two chips, where each chip is powered by k batteries. Surprisingly, it does not matter how much power each chip gets, but a machine works best when its two chips have power outputs as close as possible. The power output of a chip is simply the smallest power output of its k batteries. You have a stockpile of 2nk batteries that you want to assign to the chips. It might not be possible to allocate the batteries so that in every machine both chips have equal power outputs, but you want to allocate them so that the differences are as small as possible. To be precise, you want to tell your customers that in all machines the difference of power outputs of the two chips is at most d, and you want to make d as small as possible. To do this you must determine an optimal allocation of the batteries to the machines. Consider Sample Input 1. There are 2 machines, each requiring 3 batteries per chip, and a supply of batteries with power outputs 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12. You can, for instance, assign the batteries with power outputs 1, 3, 5 to one chip, those with power 2, 4, 12 to the other chip of the same machine, those with power 6, 8, 9 to the third chip, and those with power 7, 10, 11 to the fourth. The power outputs of the chips are 1, 2, 6, and 7, respectively, and the difference between power outputs is 1 in both machines. Note that there are many other ways to achieve this result. Input The input consists of a single test case. A test case has two lines. The first line contains two positive integers: the number of machines n and the number of batteries per chip k (2nk 10 6 ). The second line contains 2nk integers p i specifying the power outputs of the batteries (1 p i 10 9 ). Output Display the smallest number d such that you can allocate the batteries so that the difference of power outputs of the two chips in each machine is at most d. Sample Input 1 Sample Output 1 2 3 1 2 3 4 5 6 7 8 9 10 11 12 1 Sample Input 2 Sample Output 2 2 2 3 1 3 3 3 3 3 3 2 ACM-ICPC World Finals Dress Rehearsal 2014 Problem D: Low Power 7

This page is intentionally left blank.

Problem E Matrxka Time Limit: 5 seconds Matryoshkas are sets of traditional Russian wooden dolls of decreasing size placed one inside the other. A matryoshka doll can be opened to reveal a smaller figure of the same sort inside, which has, in turn, another figure inside, and so on. The Russian Matryoshka Museum recently exhibited a collection of similarly designed matryoshka sets, differing only in the number of nested dolls in each set. Unfortunately, some over-zealous (and obviously unsupervised) children separated these sets, placing all the individual dolls in a row. There are n dolls in the row, each with an integer size. You need to reassemble the matryoshka sets, knowing neither the number of sets nor the number of dolls in each set. You know only that every complete set consists of dolls with consecutive sizes from 1 to some number m, which may vary between the different sets. Picture from Wikimedia Commons When reassembling the sets, you must follow these rules: You can put a doll or a nested group of dolls only inside a larger doll. You can combine two groups of dolls only if they are adjacent in the row. Once a doll becomes a member of a group, it cannot be transferred to another group or permanently separated from the group. It can be temporarily separated only when combining two groups. Your time is valuable, and you want to do this reassembly process as quickly as possible. The only time-consuming part of this task is opening and subsequently closing a doll, so you want to minimize how often you do this. For example, the minimum number of openings (and subsequent closings) when combining group [1, 2, 6] with the group [4] is two, since you have to open the dolls with sizes 6 and 4. When combining group [1, 2, 5] with the group [3, 4], you need to perform three openings. Write a program to calculate the minimum number of openings required to combine all disassembled matryoshka sets. Input The input consists of a single test case. A test case has two lines. The first line contains one integer n (1 n 500) representing the number of individual dolls in the row. The second line contains n positive integers specifying the sizes of the dolls in the order they appear in the row. Each size is between 1 and 500 inclusive. Output Display the minimum number of openings required when reassembling the matryoshka sets. If reassembling cannot be done (some of the kids might have been excessively zealous and taken some dolls), display the word impossible. ACM-ICPC World Finals Dress Rehearsal 2014 Problem E: Matrxka 9

Sample Input 1 Sample Output 1 7 1 2 3 2 4 1 3 7 Sample Input 2 Sample Output 2 7 1 2 1 2 4 3 3 impossible ACM-ICPC World Finals Dress Rehearsal 2014 Problem E: Matrxka 10

Problem F Ragged Right Time Limit: 1 second Word wrapping is the task of deciding how to break a paragraph of text into lines. For aesthetic reasons, all the lines except the last should be about the same length. For example, the text on the left looks less ragged than the text on the right: This is a paragraph of text. This is a paragraph of text. Your job is to compute a raggedness value for an arbitrary paragraph of text. Measure raggedness in a way similar to the TEX typesetting system. Let n be the length, measured in characters, of the longest line of the paragraph. If some other line contains only m characters, then charge a penalty score of (n m) 2 for that line. The raggedness is the sum of the penalty scores for every line except the last one. Input The input consists of a single test case. A test case is a single paragraph of text containing between 1 and 100 lines. Each line of the paragraph contains between 1 and 80 characters (letters, punctuation characters, decimal digits and spaces). No line starts or ends with spaces. Output Display a single integer, which is the raggedness score for the paragraph. Sample Input 1 Sample Output 1 some blocks of text line up well on the right, but some don t. 283 Sample Input 2 Sample Output 2 this line is short this one is a bit longer and this is the longest of all. 218 ACM-ICPC World Finals Dress Rehearsal 2014 Problem F: Ragged Right 11

This page is intentionally left blank.

Problem G Self-Assembly 2 Time Limit: 4 seconds Automatic Chemical Manufacturing is experimenting with a process called self-assembly. In this process, molecules with natural affinity for each other are mixed together in a solution and allowed to spontaneously assemble themselves into larger structures. But there is one problem: sometimes molecules assemble themselves into a structure of unbounded size, which gums up the machinery. You must write a program to decide whether a given collection of molecules can be assembled into a structure of unbounded size. You should make two simplifying assumptions: 1) the problem is restricted to two dimensions, and 2) each molecule in the collection is represented as a square. The four edges of the square represent the surfaces on which the molecule can connect to other compatible molecules. In each test case, you will be given a set of molecule descriptions. Each type of molecule is described by four two-character connector labels that indicate how its edges can connect to the edges of other molecules. There are two types of connector labels: An uppercase letter (A,..., Z) followed by + or. Two edges are compatible if their labels have the same letter but different signs. For example, A+ is compatible with A but is not compatible with A+ or B. Two zero digits 00. An edge with this label is not compatible with any edge (not even with another edge labeled 00). Assume there is an unlimited supply of molecules of each type, which may be rotated and reflected. As the molecules assemble themselves into larger structures, the edges of two molecules may be adjacent to each other only if they are compatible. It is permitted for an edge, regardless of its connector label, to be connected to nothing (no adjacent molecule on that edge). Figure G.1 shows an example of three molecule types and a structure of bounded size that can be assembled from them (other bounded structures are also possible with this set of molecules). Figure G.1: Illustration of Sample Input 1. ACM-ICPC World Finals Dress Rehearsal 2014 Problem G: Self-Assembly 2 13

Input The input consists of a single test case. A test case has two lines. The first line contains an integer n (1 n 40 000) indicating the number of molecule types. The second line contains n eight-character strings, each describing a single type of molecule, separated by single spaces. Each string consists of four two-character connector labels representing the four edges of the molecule in clockwise order. Output Display the word unbounded if the set of molecule types can generate a structure of unbounded size. Otherwise, display the word bounded. Sample Input 1 Sample Output 1 3 A+00A+A+ 00B+D+A- B-C+00C+ bounded Sample Input 2 Sample Output 2 1 K+K-Q+Qunbounded ACM-ICPC World Finals Dress Rehearsal 2014 Problem G: Self-Assembly 2 14

Problem H Curvy Little Bottles 2 Time Limit: 1 second In her bike rides around Ekaterinburg, Jill happened upon a shop that sold interesting glass bottles. She thought it might make an interesting project to use such bottles for measuring liquids, but this would require placing markings on the bottles to indicate various volumes. Where should those volume marks be placed? Jill formalized the problem as follows. Assume a bottle is formed by revolving a shape that is the same as the graph of a polynomial P between x = x low and x = x high around the x-axis. Thus the x-axis is coincident with a vertical line through the center of the bottle. The bottom of the bottle is formed by a solid circular region at x = x low, and the top of the bottle, at x = x high, is left open. The first sample input represents a bottle formed using the simple polynomial 4 0.25x, with x low = 0 and x high = 12. The bottom of this bottle is a circle with a radius of 4, and the opening at the top is a circle with a radius of 1. The height of this bottle is 12. Volume markings are in increments of 25. Given a polynomial P, x low, x high, and the volume increment between successive marks on the bottle, compute the distances up from x low for the marks at successive volume increments. A mark cannot be made past the top of the bottle, and no more than the first 8 increments should be marked. Assume the value of P is greater than zero everywhere between x low and x high. Input The input consists of a single test case. A test case has three lines of bottle data: Line 1: n, the degree of the polynomial (an integer satisfying 0 n 10). Line 2: a 0, a 1,..., a n, the real coefficients of the polynomial P defining the bottle s shape, where a 0 is the constant term, a 1 is the coefficient of x 1,..., and a n is the coefficient of x n. For each i, 100 a i 100, and a n 0. Line 3: x low and x high, the real-valued boundaries of the bottle ( 100 x low < x high 100 and x high x low > 0.1). inc, an integer which is the volume increment before each successive mark on the bottle (1 inc 500). Output Display the volume of the full bottle on one line. On a second line, display the increasing sequence of no more than 8 successive distances up from the bottom of the bottle for the volume markings. All volumes and height marks should have absolute error of at most 10 3. If the bottle does not have a volume that allows at least one mark, display the phrase insufficient volume. No test case will result in a mark within 0.01 from the top of the bottle. The volume of the bottle will not exceed 1 000. All distances for marks on a bottle differ by at least 0.04. ACM-ICPC World Finals Dress Rehearsal 2014 Problem H: Curvy Little Bottles 2 15

Sample Input 1 1 4.0-0.25 0.0 12.0 25 Sample Output 1 263.8938 0.5137 1.0639 1.6579 2.3058 3.0215 3.8262 4.7543 5.8677 Sample Input 2 Sample Output 2 0 1.0 0.0 10.0 10 31.4159 3.1831 6.3662 9.5493 Sample Input 3 Sample Output 3 0 1.7841241161782 5.0 10.0 20 50.0000 2.0000 4.0000 Sample Input 4 Sample Output 4 1 4.0-0.25 0.0 12.0 300 263.8938 insufficient volume ACM-ICPC World Finals Dress Rehearsal 2014 Problem H: Curvy Little Bottles 2 16

Problem I Fibonacci Words 2 Time Limit: 1 second The Fibonacci word sequence of bit strings is defined as: 0 if n = 0 F (n) = 1 if n = 1 F (n 1) + F (n 2) if n 2 Here + denotes concatenation of strings. The first few elements are: n F (n) 0 0 1 1 2 10 3 101 4 10110 5 10110101 6 1011010110110 7 101101011011010110101 8 1011010110110101101011011010110110 9 1011010110110101101011011010110110101101011011010110101 Given a bit pattern p and a number n, how often does p occur in F (n)? Input The input consists of at most 100 test cases. The first line of each test case contains the integer n (0 n 100). The second line contains the bit pattern p. The pattern p is nonempty and has a length of at most 100 000 characters. Output For each test case, print the number of occurrences of the bit pattern p in F (n). Occurrences may overlap. The number of occurrences will be less than 2 63. Sample Input 1 Sample Output 1 6 10 7 10 6 01 6 101 96 10110101101101 5 8 4 4 7540113804746346428 ACM-ICPC World Finals Dress Rehearsal 2014 Problem I: Fibonacci Words 2 17

This page is intentionally left blank.

Problem J Low Power 2 Time Limit: 3 seconds You are building advanced chips for machines. Making the chips is easy, but the power supply turns out to be an issue since the available batteries have varied power outputs. Consider the problem of n machines, each with two chips, where each chip is powered by k batteries. Surprisingly, it does not matter how much power each chip gets, but a machine works best when its two chips have power outputs as close as possible. The power output of a chip is simply the smallest power output of its k batteries. You have a stockpile of 2nk batteries that you want to assign to the chips. It might not be possible to allocate the batteries so that in every machine both chips have equal power outputs, but you want to allocate them so that the differences are as small as possible. To be precise, you want to tell your customers that in all machines the difference of power outputs of the two chips is at most d, and you want to make d as small as possible. To do this you must determine an optimal allocation of the batteries to the machines. Consider Sample Input 1. There are 2 machines, each requiring 3 batteries per chip, and a supply of batteries with power outputs 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12. You can, for instance, assign the batteries with power outputs 1, 3, 5 to one chip, those with power 2, 4, 12 to the other chip of the same machine, those with power 6, 8, 9 to the third chip, and those with power 7, 10, 11 to the fourth. The power outputs of the chips are 1, 2, 6, and 7, respectively, and the difference between power outputs is 1 in both machines. Note that there are many other ways to achieve this result. Input The input consists of a single test case. A test case has two lines. The first line contains two positive integers: the number of machines n and the number of batteries per chip k (2nk 10 6 ). The second line contains 2nk integers p i specifying the power outputs of the batteries (1 p i 10 9 ). Output Display the smallest number d such that you can allocate the batteries so that the difference of power outputs of the two chips in each machine is at most d. Sample Input 1 Sample Output 1 2 3 1 2 3 4 5 6 7 8 9 10 11 12 1 Sample Input 2 Sample Output 2 2 2 3 1 3 3 3 3 3 3 2 ACM-ICPC World Finals Dress Rehearsal 2014 Problem J: Low Power 2 19

This page is intentionally left blank.

Problem K Matrxka 2 Time Limit: 5 seconds Matryoshkas are sets of traditional Russian wooden dolls of decreasing size placed one inside the other. A matryoshka doll can be opened to reveal a smaller figure of the same sort inside, which has, in turn, another figure inside, and so on. The Russian Matryoshka Museum recently exhibited a collection of similarly designed matryoshka sets, differing only in the number of nested dolls in each set. Unfortunately, some over-zealous (and obviously unsupervised) children separated these sets, placing all the individual dolls in a row. There are n dolls in the row, each with an integer size. You need to reassemble the matryoshka sets, knowing neither the number of sets nor the number of dolls in each set. You know only that every complete set consists of dolls with consecutive sizes from 1 to some number m, which may vary between the different sets. Picture from Wikimedia Commons When reassembling the sets, you must follow these rules: You can put a doll or a nested group of dolls only inside a larger doll. You can combine two groups of dolls only if they are adjacent in the row. Once a doll becomes a member of a group, it cannot be transferred to another group or permanently separated from the group. It can be temporarily separated only when combining two groups. Your time is valuable, and you want to do this reassembly process as quickly as possible. The only time-consuming part of this task is opening and subsequently closing a doll, so you want to minimize how often you do this. For example, the minimum number of openings (and subsequent closings) when combining group [1, 2, 6] with the group [4] is two, since you have to open the dolls with sizes 6 and 4. When combining group [1, 2, 5] with the group [3, 4], you need to perform three openings. Write a program to calculate the minimum number of openings required to combine all disassembled matryoshka sets. Input The input consists of a single test case. A test case has two lines. The first line contains one integer n (1 n 500) representing the number of individual dolls in the row. The second line contains n positive integers specifying the sizes of the dolls in the order they appear in the row. Each size is between 1 and 500 inclusive. Output Display the minimum number of openings required when reassembling the matryoshka sets. If reassembling cannot be done (some of the kids might have been excessively zealous and taken some dolls), display the word impossible. ACM-ICPC World Finals Dress Rehearsal 2014 Problem K: Matrxka 2 21

Sample Input 1 Sample Output 1 7 1 2 3 2 4 1 3 7 Sample Input 2 Sample Output 2 7 1 2 1 2 4 3 3 impossible ACM-ICPC World Finals Dress Rehearsal 2014 Problem K: Matrxka 2 22

Problem L Ragged Right 2 Time Limit: 1 second Word wrapping is the task of deciding how to break a paragraph of text into lines. For aesthetic reasons, all the lines except the last should be about the same length. For example, the text on the left looks less ragged than the text on the right: This is a paragraph of text. This is a paragraph of text. Your job is to compute a raggedness value for an arbitrary paragraph of text. Measure raggedness in a way similar to the TEX typesetting system. Let n be the length, measured in characters, of the longest line of the paragraph. If some other line contains only m characters, then charge a penalty score of (n m) 2 for that line. The raggedness is the sum of the penalty scores for every line except the last one. Input The input consists of a single test case. A test case is a single paragraph of text containing between 1 and 100 lines. Each line of the paragraph contains between 1 and 80 characters (letters, punctuation characters, decimal digits and spaces). No line starts or ends with spaces. Output Display a single integer, which is the raggedness score for the paragraph. Sample Input 1 Sample Output 1 some blocks of text line up well on the right, but some don t. 283 Sample Input 2 Sample Output 2 this line is short this one is a bit longer and this is the longest of all. 218 ACM-ICPC World Finals Dress Rehearsal 2014 Problem L: Ragged Right 2 23

This page is intentionally left blank.