Competitive Programming Network - 2nd Activity March 11th, Alphabet.c, Alphabet.cpp, Alphabet.java, Alphabet.py Standard Standard

Similar documents
Problem A limit 1 second. Alphabet

Problem Y A limit 1 second. Zigzag

2016 ACM ICPC Southeast USA Regional Programming Contest. Division 1

Problem A And Then There Was One Input: A.in. Let s play a stone removing game.

Millionaire. Input. Output. Problem limit seconds

XVIII Open Cup named after E.V. Pankratiev Stage 1: Grand Prix of Romania, Sunday, September 17, 2017

Problem A A New Alphabet

XVIII Open Cup named after E.V. Pankratiev Stage 10, Grand Prix of Korea, Sunday, February 4, 2018

Problem A. Character Encoding

Central Europe Regional Contest 2016

XV Open Cup named after E.V. Pankratiev Stage 6, Grand Prix of Japan, Sunday, February 1, 2015

IMO Training 2008: Graph Theory

MIT Programming Contest Team Contest 1 Problems 2008

Pacific Northwest Region Programming Contest Division 2

Pacific Northwest Region Programming Contest Division 2

Problem A: Collatz Conjecture

Router placement. Problem statement for Final Round, Hash Code 2017

Problem A. Ascent Sequences

Problem A. Interactive Smiley Face

ACM ICPC Dhaka Regional Online Preliminary Contest th October 2018 You get 13 Pages 10 Problems

NOWCODER.COM 牛客网 - 中国最大 IT 笔试 / 面试题库 一. 编程题

Pacific Northwest Region Programming Contest Division 2

ACM-ICPC Indonesia National Contest Problem A. The Best Team. Time Limit: 2s

Central Europe Regional Contest

LESSON 1: INTRODUCTION TO COUNTING

Advanced Operations Research Prof. G. Srinivasan Department of Management Studies Indian Institute of Technology, Madras

ACM Pacific NW Region Programming Contest 13 November 2004 Problem A: Mersenne Composite Numbers

NOWCODER.COM 牛客网 - 中国最大 IT 笔试 / 面试题库 一. 编程题

1. You have a complete bipartite graph where each part contains exactly n nodes, numbered from 0 to n - 1 inclusive.

Algorithms Assignment 3 Solutions

ProCo 2017 Novice Division Round 1

Problem A. Pyramid of Unit Cubes

UCF Practice Local Contest Aug 23, 2014

2015 ICPC. Northeast North America Preliminary

The 2016 ACM ICPC Vietnam National Programming Contest. The problem set consists of 11 problems: ICPC score distribution. Magical palindromic number

CSE 101 Homework 5. Winter 2015

PURPLE COMET MATH MEET April 2011 HIGH SCHOOL - PROBLEMS. The ratio of 3 to the positive number n is the same as the ratio of n to 192. Find n.

Spring 2017 #5 A. Two Buttons

Invariants and Algorithms

Anti Brute Force Lock

1. Alicia tosses 3 fair coins. What is the probability that she gets at 1. least 1 head? Express your answer as a common fraction.

ACM ICPC2009 Latin American Regionals 1. Problem A Pangram. File code name: pangram

HMMT February 2018 February 10, 2018

Whac-a-Mole. Problem G. Input specifications. Output specifications. NCPC 2006 Problem G: Whac-a-Mole 15

Task Overview Sheet. Type Printer Islands Fish. Batch (stdin/stdout)*

Discrete Structures. Fall Homework3

Graph theory. Po-Shen Loh. June We begin by collecting some basic facts which can be proved via bare-hands techniques.

Python allows variables to hold string values, just like any other type (Boolean, int, float). So, the following assignment statements are valid:

Problem Set. The 37 th Annual ACM International Collegiate Programming Contest ASIA Regional - Daejeon. A. Accelerator (2 pages)

1. One-third of 105 is the same as seven-sixths of what number? 1.

ACM ICPC 7th Sharif Internet Contest & Internal Selection Contest of Sharif

ACM International Collegiate Programming Contest 2013

Problem A - Complete the sequence

MTH-129 Review for Test 4 Luczak

8.2 Paths and Cycles

Problem A As Easy as CAB

Problem A. Find a Number

PLU February 2018 Programming Contest. Novice Division

TeamsCode Spring 2018 MIHS Programming Contest

Premium POS Pizza Order Entry Module. Introduction and Tutorial

2010 ACM ICPC Southeast USA Regional Programming Contest. 6 November, 2010 PROBLEMS

Discrete Structures Lecture The Basics of Counting

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. Programming Problems

context. (Similarly, we write ν for ν(g), etc. if there is no risk of confusion.) For a subset A V we write N G (A) = {v V ( w A)(v w)} (the set of

A. Petr and a calendar

Dr. Amotz Bar-Noy s Compendium of Algorithms Problems. Problems, Hints, and Solutions

2013 Four-by-Four Competition Thursday, January 31st, Round Four-by-Four Competition Thursday, January 31st, 2013.

Lecture 25 : Counting DRAFT

High School Programming Tournament: Online Edition. Problems

Problem Solving Strategies set of advanced problems

2. True or false: even though BFS and DFS have the same space complexity, they do not always have the same worst case asymptotic time complexity.

Problems Overview. The 2015 Asia ACM-ICPC Hanoi Regional Contest. Note: The input and output for all the problems are standard input and output.

Understanding Geospatial Data Models

University of Manitoba Open Programming Contest September 22, General Instructions:

Coverage and Search Algorithms. Chapter 10

S. Dasgupta, C.H. Papadimitriou, and U.V. Vazirani 165

Dynamic Programming Homework Problems

Harvard-MIT Mathematics Tournament February 19, 2005

GRAPH THEORY: AN INTRODUCTION

Dynamic Programming Homework Problems

4 th Annual Virginia Tech High School Programming Contest (2017)

1 Introduction and Examples

ARC093 / ABC092. wo01. min(a, B) + min(c, D) C++ #include<cstdio> #include<algorithm> using namespace std;

Instructor: Paul Zeitz, University of San Francisco

PLU February 2013 Programming Contest. Advanced Problems

Dynamic Programming Algorithms

Misspelling is an art form that students seem to excel at. Write a program that removes the nth character from an input string.

MIT Programming Contest Team Round 3 Problems 2006

Solution : a) C(18, 1)C(325, 1) = 5850 b) C(18, 1) + C(325, 1) = 343

ICPC/CCPC Trial Round #2 East China Normal University, September 12, 2018

4th Pui Ching Invitational Mathematics Competition. Heat Event (Secondary 2)

Question 2 (Strongly Connected Components, 15 points). What are the strongly connected components of the graph below?

Name Date Period. Multiple Choice

Graph and Digraph Glossary

Practices (1) 6.MP.2. Reason abstractly and quantitatively.

MathZoom, Summer, 2014

2005 Stanford Local Programming Contest

CS3L Summer 2011 Exam 2 Time: up to 170 minutes (you may leave when finished; or, you must stop promptly at noon)

, 6.7,, Order the numbers from least to greatest. 1. 1, 0, 2, 5, 4. Simplify the expression. 10.

11.2 Eulerian Trails

Transcription:

Problem A. Alphabet Source file name: : : Alphabet.c, Alphabet.cpp, Alphabet.java, Alphabet.py A string of lowercase letters is called alphabetical if deleting zero or more of its letters can result in the alphabet string abcdefghijklmnopqrstuvwxyz. Given a string s, determine the minimum number of letters to insert anywhere in the string to make it alphabetical. The input consists of a single line containing the string s (1 s 50). It is guaranteed that s consists of lowercase ASCII letters a to z only. Print, on a single line, a single integer indicating the minimum number of letters that must be inserted in order to make the string s alphabetical. xyzabcdefghijklmnopqrstuvw 3 aiemckgobjfndlhp 20 Page 1 of 15

Problem B. Buggy Robot Source file name: : : Buggy.c, Buggy.cpp, Buggy.java, Buggy.py You are trying to program a robot to navigate through a 2-dimensional maze and find the exit. The maze can be represented as a grid with n rows and m columns. Some grid cells have obstacles that the robot cannot pass. The other cells are empty, which the robot can freely pass. Exactly one of the empty cells in the grid is marked as the exit, and the robot will exit the maze immediately once it reaches there. You can program the robot by sending it a command string. A command string consists of characters L, U, R, D, corresponding to the directions left, up, right, down, respectively. The robot will then start executing the commands, by moving to an adjacent cell in the directions specified by the command string. If the robot would run into an obstacle or off the edge of the grid, it will ignore the command, but it will continue on to remaining commands. The robot will also ignore all commands after reaching the exit cell. Your friend sent you a draft of a command string, but you quickly realize that the command string will not necessarily take the robot to the exit. You would like to fix the string so that the robot will reach the exit square. In one second, you can delete an arbitrary character, or add an arbitrary character at an arbitrary position. Find how quickly you can fix your friend s command string. You do not care how long it takes the robot to find the exit, but only how long it takes to repair the command string. The first line of input contains the two integers n and m (1 n, m 50). Each of the next n lines contains m characters, describing the corresponding row of the grid. Empty cells are denoted as., the robot s initial position is denoted as R, obstacles are denoted as #, and the exit is denoted as E. The next and final line of input contains your friend s command string, consisting of between 1 and 50 characters, inclusive. It is guaranteed that the grid contains exactly one R and one E, and that there is always a path from R to E. Print, on a single line, a single integer indicating the minimum amount of time to fix the program. www.redprogramacioncompetitiva.com/ Page 2 of 15

3 3 R...#...E LRDD 2 4 R.#. #..E RRUUDDRRUUUU 1 0 Page 3 of 15

Problem C. Cameras Source file name: Cameras.c, Cameras.cpp, Cameras.java, Cameras.py : : Your street has n houses, conveniently numbered from 1 to n. Out of these n houses, k of them have security cameras installed. Mindful of gaps in coverage, the Neighborhood Watch would like to ensure that every set of r consecutive houses has at least two different houses with cameras. What is the minimum number of additional cameras necessary to achieve this? The first line of input contains three integers, n (2 n 10 5 ), k (0 k n), and r (2 r n). The next k lines of input contain the distinct locations of the existing cameras. Print, on a single line, a single integer indicating the minimum number of cameras that need to be added. 15 5 4 2 5 7 10 13 3 www.redprogramacioncompetitiva.com/ Page 4 of 15

Problem D. Contest Strategy Source file name: : : Conteststrat.c, Conteststrat.cpp, Conteststrat.java, Conteststrat.py You are participating in the Association for Computing Machinery s Intercollegiate Programming Competition (ACM ICPC). You must complete a set of n problems. Since you are an experienced problem solver, you can read a problem and accurately estimate how long it will take to solve it, in a negligible amount of time. Let t i be the time it will take to solve the ith problem. Your strategy for the contest is as follows: 1. Read k random problems. 2. Choose a problem that you have read that will take the shortest time to solve (if there are ties, choose any of them arbitrarily). 3. Solve the problem, and read a random unread problem (if there is any). 4. If there are still unsolved problems, go back step 2. Your penalty time for the contest is defined by the sum of submission times for all the problems. Of course, your penalty time depends on the order in which the problems are read. What is the sum of penalty times, over all n! possible different orders you read the problems in? Since the result can be very large, find the answer modulo 10 9 + 7. The first line of input contains two space-separated integers n and k (1 k n 300). The ith line of the next n lines contains a single integer t i (1 t i 10 6 ). Print, on a single line, a single integer representing the sum of penalty times over all possible orders you read the problems in, modulo 10 9 + 7. Page 5 of 15

4 3 1 3 2 1 10 2 1000000 2 152 49 93064 438953 438 9238 9065 1274 336 513850896 www.redprogramacioncompetitiva.com/ Page 6 of 15

Problem E. Enclosure Source file name: Enclosure.c, Enclosure.cpp, Enclosure.java, Enclosure.py : : In the Dark Forest, the territory you control is defined by the smallest convex polygon that contains all trees you control. Your power is defined by the area of the territory you control. You currently control k out of n trees in the Dark Forest. What is the highest power you can achieve by gaining control over a single additional tree somewhere in the forest? The first line of input consists of two space-separated integers n and k (3 k < n 10 5 ). Next follow n lines each with two space-separated integers x i and y i ( x i, y i 10 9 ) specifying the locations of the n trees. You control the first k trees given in the list; the other n k trees do not belong to you. (Note that some of these may still be inside your territory.) It is guaranteed that no three trees have collinear locations. Print, on a single line, the maximum power you can achieve by gaining control over a single additional tree. The output should be rounded and displayed to exactly one decimal place. 5 3-5 -5-5 5 5-5 -4 6 5 5 100.0 Page 7 of 15

Problem F. Illumination Source file name: Illumination.c, Illumination.cpp, Illumination.java, Illumination.py : : You inherited a haunted house. Its floor plan is an n-by-n square grid with l lamps in fixed locations and no interior walls. Each lamp can either illuminate its row or its column, but not both simultaneously. The illumination of each lamp extends by r squares in both directions, so a lamp unobstructed by an exterior wall of the house can illuminate as many as 2r + 1 squares. If a square is illuminated by more than one lamp in its row, or by more than one lamp in its column, the resulting bright spot will scare away ghosts forever, diminishing the value of your property. Is it possible for all lamps to illuminate a row or column, without scaring any ghosts? Note that a square illuminated by two lamps, one in its row and the other in its column, will not scare away the ghosts. The first line of input contains three positive integers, n, r and l (1 n, r, l 10 3 ). Each of the next l lines contains two positive integers r i and c i (1 r i, c i n), indicating that there is a lamp in row r i and column c i. It is guaranteed that all lamps are in distinct locations. Print, on a single line, YES if it is possible to illuminate all lamps as stated above; otherwise, print NO. 3 2 5 1 1 1 3 3 1 3 3 2 2 3 2 6 1 1 1 2 1 3 3 1 3 2 3 3 YES NO www.redprogramacioncompetitiva.com/ Page 8 of 15

Problem G. Maximum Island Source file name: Maximumisl.c, Maximumisl.cpp, Maximumisl.java, Maximumisl.py : : You are mapping a faraway planet using a satellite. Your satellite has captured an image of the planet s surface. The photographed section can be modeled as a grid. Each grid cell is either land, water, or covered by clouds. Clouds mean that the surface could either be land or water, but we can t tell. An island is a set of connected land cells. Two cells are considered connected if they share an edge. Given the image, determine the maximum number of islands that is consistent with the given information. The first line of input contains two space-separated integers n and m (1 n, m 40). Each of the next n lines contains m characters, describing the satellite image. Land cells are denoted by L, water cells are denoted by W, and cells covered by clouds are denoted by C. Print, on a single line, a single integer indicating the maximum number of islands that is consistent with the given grid. 5 4 LLWL CCCC CCCC CCCC LWLL 8 Page 9 of 15

Problem H. Paint Source file name: Paint.c, Paint.cpp, Paint.java, Paint.py : : You are painting a fence with n sections, numbered from 1 to n. There are k artists, each willing to paint their design on a specific portion of the fence. However, artists will never agree to have their section painted over, so they will only paint their portion of the fence if no one else will paint any part of it. You want to select a set of painters that does not conflict to minimize the number of unpainted sections. The first line contains two positive integers n (1 n 10 18 ) and k (1 k 2 10 5 ). Each of the next k lines contains two positive integers a i and b i, where 1 a i b i n, indicating that the ith artist wants to paint all sections between section a i and section b i, inclusive. Print, on a single line, a single integer indicating the minimum number of unpainted sections. 8 3 1 3 2 6 5 8 1 www.redprogramacioncompetitiva.com/ Page 10 of 15

Problem I. Postman Source file name: Postman.c, Postman.cpp, Postman.java, Postman.py : : A postman delivers letters to his neighbors in a one-dimensional world. The post office, which contains all of the letters to begin with, is located at x = 0, and there are n houses to which the postman needs to deliver the letters. House i is located at position x i, and there are m i letters that need to be delivered to this location. But the postman can only carry k letters at once. The postman must start at the post office, pick up some number of letters less than or equal to his carrying capacity, and then travel to some of the houses dropping off letters. He must then return to the post office, repeating this process until all letters are delivered. At the end he must return to the post office. The postman can travel one unit of distance in one unit of time. What is the minimum amount of time it will take the postman to start at the post office, deliver all the letters, and return to the post office? The first line of input contains two space-separated integers n (1 n 10 3 ) and k (1 k 10 7 ). Each of the next n lines contains two space-separated integers x i ( xi 10 7 ) and m i (1 m i 10 7 ). Print, on a single line, the minimum amount of time it will take to complete the mail delivery route. 4 10-7 5-2 3 5 7 9 5 7 1 9400000 10000000 9500000 10000000 9600000 10000000 9700000 10000000 9800000 10000000 9900000 10000000 10000000 10000000 42 1358000000000000 Page 11 of 15

Problem J. Shopping Source file name: : : Shopping.c, Shopping.cpp, Shopping.java, Shopping.py The sale bin of Big Box Bargains contains n products in a row. The ith item has price a i per unit. There is no limit to the quantity of any item. There are q customers who will enter the store to buy items. The ith customer has v i dollars, starts at item l i and walks to the right to item r i (inclusive), one item at a time. Each time they encounter an item, they will buy as many units of the item as they can afford. You are now wondering, for each customer, how much money they will have left after buying items. The first line of input contains two space-separated integers n and q (1 n, q 2 10 5 ). The next line of input contains n space-separated integers a i (1 a i 10 18 ). Each of the next q lines contains three space-separated integers v i (1 v i 10 18 ), l i, and r i (1 l i r i n). For each of the q customers, print, on a single line, a single integer indicating the remaining amount of money after shopping. 5 3 5 3 2 4 6 8 5 5 107 1 4 7 3 5 2 0 1 www.redprogramacioncompetitiva.com/ Page 12 of 15

Problem K. Tournament Wins Source file name: Tournament.c, Tournament.cpp, Tournament.java, Tournament.py : : You are one of 2 k competitors invited to enter a single elimination tournament. You are ranked rth in the published rankings. Furthermore, you know that in any match between two players, the one ranked higher will always win. The only source of uncertainty is the bracket. If every possible tournament bracket is equally likely, determine your expected number of wins in the tournament. Your expected number of wins is the average number of your wins over all possible tournament bracket orderings. The input consists of a single line containing the two space-separated integers k (1 k 20) and r (1 r 2 k ). Print, on a single line, your expected number of wins in the tournament, rounded and displayed to exactly five decimal places. The sixth digit after the decimal point of the exact answer will never be 4 or 5 (eliminating complex rounding considerations). Be careful about very small or very large numbers during intermediate steps. 3 3 1.00000 20 130 11.65203 Page 13 of 15

Problem L. Barbells Source file name: Barbells.c, Barbells.cpp, Barbells.java, Barbells.py : : Your local gym has n barbells and m plates. In order to prepare a weight for lifting, you must choose a single barbell, which has two sides. You then load each side with a (possibly empty) set of plates. For safety reasons, the plates on each side must sum to the same weight. What weights are available for lifting? For example, suppose that there are two barbells weighing 100 and 110 grams, and five plates weighting 1, 4, 5, 5, and 6 grams, respectively. Then, there are six possible weights available for lifting. The table below shows one way to attain the different weights: The first line of input contains the space-separated integers n and m (1 n, m 14). The second line of input contains n space-separated integers b 1,..., b n (1 b i 10 8 ), denoting the weights of the barbells in grams. The third line of input contains m space-separated integers p 1,..., p m (1 p i 10 8 ), denoting the weights of the plates in grams. Print a sorted list of all possible distinct weights in grams, one per line. www.redprogramacioncompetitiva.com/ Page 14 of 15

2 5 100 110 5 5 1 4 6 100 110 112 120 122 130 Page 15 of 15