task
stringlengths
0
154k
__index_level_0__
int64
0
39.2k
Toil for Oil (OIL) Prospecting for new sources of oil has become a high-technology industry. With improved drilling technology it has become economically viable to seek out ever smaller and harder to reach deposits of oil. However, using exploratory drilling to locate these deposits is not cost-efficient, so researche...
31,300
Partitions (RECTNG2) A partition of a rectangle is either a whole rectangle or a subdivision the rectangle into either a upper part and a lower part or a left part and a right part, and each part is a partition of the corresponding rectangle. Figure 1 shows several examples of partitions. Figure 2 shows three equa...
31,301
Silly Sort (SSORT) Your younger brother has an assignment and needs some help. His teacher gave him a sequence of numbers to be sorted in ascending order. During the sorting process, the places of two numbers can be interchanged. Each interchange has a cost, which is the sum of the two numbers involved. You must wri...
31,302
Bracket Sequence (LEXBRAC) Correct Bracket Sequence (CBS) is a sequence that can be obtained through following rules: An empty string is a CBS. If A is a CBS, then B = (A) is also a CBS. If A is a CBS, then B = [A] is also a CBS. If A and B are CBS, then C = AB is also a CBS. Length of the CBS is the num...
31,303
Overlapping Words (WORDS) Consider the following game: you are given a word W that contains only lower-case letters ("a" to "z"). You are also given a set of words and you are allowed to do the following operation: choose a suffix of W and replace it with another word (you can do this only if that word contains the su...
31,304
Sequence (BIGSEQ) You are given the sequence of all K-digit binary numbers: 0, 1 ... 2 K -1. You need to fully partition the sequence into M chunks. Each chunk must be a consecutive subsequence of the original sequence. Let S i (1 ≤ i ≤ M) be the total number of 1's in all numbers in the ith chunk when writte...
31,305
Manhattan (DISTANCE) The L 1 distance of two d-dimensional points is the sum of absolute values of their coordinate differences (i.e. Σ i=1 d |x i - y i | for two points x,y). Given N points in the plane you must find the farthest pair of points under the L 1 distance metric and output their distance. Inp...
31,306
Segments (SEGMENTS) There are N horizontal line segments in the plane. The ith segment has some height h i (which may be negative) and runs from x = a i to x = b i (a i < b i ). Segments do not contain their endpoints. You must draw a set of vertical lines (note lines and not line segments ) so that every ...
31,307
Tree Game (TREEGAME) A complete binary tree of depth h is given. You can asign the value 0 or 1 to each leaf. Its internal nodes compute their values based on the values of their children, which is 0 if both children have value 1, and 1 otherwise. You play a game with a computer. The computer can ask you for a ...
31,308
Broken Compass (COMPASS) A group of adventurers are on an expedition to reach the North Pole. The only instrument they have is a compass that points to the pole. However, the compass is broken and although its measurements are consistent, the direction it points to is some fixed but unknown angle away from true North...
31,309
Mario (MARIOGAM) Mario lives in an N × M maze grid. In this maze there are coin boxes, monsters, pipe systems, and walls. Whenever Mario enters a cell containing a coin box, he jumps to hit the box and gets as many coins as there are in the box (coin boxes do not disappear or lose coins after being hit). When...
31,310
String Distance (STRDIST) Let A = a 1 a 2 ...a k and B = b 1 b 2 ...b l be strings of lengths k and l, respectively. The string distance between A and B is defined in the following way (d[i,j] is the distance of substrings a 1 ...a i and b 1 ...b j , where 0 ≤ i ≤ k and 0 ≤ j ≤ l -- i or j being 0 represents t...
31,311
Another Longest Increasing Subsequence Problem (LIS2) Given a sequence of N pairs of integers, find the length of the longest increasing subsequence of it. An increasing sequence A 1 ..A n is a sequence such that for every i < j , A i < A j . A subsequence of a sequence is a sequence that appears i...
31,312
Arranging Amplifiers (ARRANGE) Scientists at the TIFR, Mumbai, are doing some cutting edge research on the Propagation of Signals. A young researcher comes up with a method of progressively amplifying signals, as they progress along a path. The method involves the placing of Amplifiers at regular distances along the l...
31,313
Building Beacons (BUILD) A Millionaire Eccentric Mathematician purchases a small Island, to build his residence. In order to keep away Trespassers, he decides to Build some Beacons (Towers) on the perimeter of the Island. To build these Beacons, he visits the Mainland to purchase Stone. Being obsessed with Prime Numb...
31,314
Calculate The Cost (CCOST) In a small village near the Himalayas, there is a rich land-owner, in possession of a vast, rectangular tract of land. Unknown to him, a major oil corporation has verified the existence of a vast oil resource beneath his land. The oil company sends a man to negotiate the purchase of a rect...
31,315
Kirchhof Law (RESIST) Input Multiple test cases. For each test case: The first line contains integers N and M; N is a number of nodes in the circuit (2 < N ≤ 100), M is the number of resistors (0 ≤ M ≤ 300). Each of the next M lines consists of three integers A i , B i and R i — description of a resistor that ha...
31,316
Distinct Subsequences (DSUBSEQ) Given a string, count the number of distinct subsequences of it (including empty subsequence). For the uninformed, a subsequence of a string is a new string which is formed from the original string by deleting some of the characters without disturbing the relative positions of the remai...
31,317
Eliminate The Enemies (ENEMY) In a modification of the popular game 'Pacman', the player has to move in a two-dimensional grid. Several cells of the grid are blocked. The player can start from any cell that is not blocked and can move in any of the directions, i.e. north, west, south or east, provided that the cells a...
31,318
Flying Frogs (FFROG) WiseFrog, The King of FrogLand is on his Deathbed. He has 2 Sons, SensibleFrog and SmartFrog. Both of them are "Infinitely Intelligent". To decide who will succeed him as King, he devises a Strategy Game for the two Sons- An Arena is constructed, in the form of a Rectangle, having m × n Square A...
31,319
G-Line Grid (GLGRID) The 21st century introduces the multicores. As a result a research is going on in parallel Computing. With time the number of processor would grow very large. As of now, Professor Biloo at IIIT asks a student to implement the following code on multiple G-line processors. for(i=1;i<=x;...
31,320
Hospital at Hands (HHAND) In a remote part of the Country, there lies a group of towns, quite far from any other areas. These towns are connected by a set of roads, having the property that there is exactly one path connecting any two towns, and every town is connected. Apollo Hospitals Ltd. decides to invest in thi...
31,321
Incrementing The Integer (ININT) Starting from the number '1', every time you can choose a digit from the current number and add it to the number itself. 23, for example, could be changed into 25 or 26. To get 100, using the above scheme, paths A and B are both possible. A requires 21 steps, but B needs only 17 (whic...
31,322
Jazzy Job (JAZZYJOB) With the magnification of the Energy Crisis, Chemists have decided to re-examine the existing procedures of preparation of various Chemical Substances. As part of this Project, they list all the elements that they commonly find as raw material (Initial Reactants), and the ones that they intend t...
31,323
Minimal Triangulations of Graphs (MINTRIAN) Check whether the given graph is chordal . Input The first line contains an integer 1<=t<=200 denoting the number of test cases. Then t graphs are given (not necessarily connected). Each graph is described by two lines. The first line contains a string of the form: ...
31,324
Palindromes (PLD) A palindrome is a word, phrase, number or other sequence of units that has the property of reading the same in either direction, e.g. 'racecar', 'solos'. Task You are given a number k (2 ≤ k ≤ 30000) and a non-empty string S whose length does not exceed 30000 lowercase letters. We say two pali...
31,325
Counting Rabbits (RABBIT1) Rabbits are incredible animals. One of their more interesting characteristics is related with their reproduction. If we keep a couple of adult rabbits in optimal conditions of life, it is scientifically proved that, each month, that couple is capable of procreat...
31,326
Phone Lines (PHONELIN) There are several cities and towers on a straight line. Towers can be set to connection-accepting by paying a cost. We are given the location (on the X-axis), of the towers and the cities. Our job is to set up certain towers as connection-accepting. Now every city, pays you an amount equal to D...
31,327
Magic Program IV (MAGIC4) This is the solution (TLE).
31,328
Encoding (GNY07C) Chip and Dale have devised an encryption method to hide their (written) text messages. They first agree secretly on two numbers that will be used as the number of rows (R) and columns (C) in a matrix. The sender encodes an intermediate format using the following rules: The text is formed with u...
31,329
Decoding (GNY07D) Chip and Dale have devised an encryption method to hide their (written) text messages. They first agree secretly on two numbers that will be used as the number of rows (R) and columns (C) in a matrix. The sender encodes an intermediate format using the following rules: The text is formed with u...
31,330
Flipping Burned Pancakes (GNY07E) The cook at the Frobbozz Magic Pancake House sometimes falls asleep on the job while cooking pancakes. As a result, one side of a stack of pancakes is often burned. Clearly, it is bad business to serve visibly burned pancakes to the patrons. Before serving, the waitress will arran...
31,331
Monkey Vines (GNY07F) Deep in the Amazon jungle, exceptionally tall trees grow that support a rich biosphere of figs and juniper bugs, which happen to be the culinary delight of brown monkeys. Reaching the canopy of these trees requires the monkeys to perform careful navigation through the tall tree’s fragile vi...
31,332
Model Rocket Height (GNY07G) Just when you thought we had run out of model rocket height problems... Yet another method used to determine the height achieved by a model rocket is the vertical line method. Two observers A and B are spaced D feet apart along a base line along one edge of the flat test field. The lau...
31,333
Tiling a Grid With Dominoes (GNY07H) We wish to tile a grid 4 units high and N units long with rectangles (dominoes) 2 units by one unit (in either orientation). For example, the figure shows the five different ways that a grid 4 units high and 2 units wide may be tiled. Write a program that takes as input t...
31,334
Spatial Concepts Test (GNY07I) The Flathead Testing Corporation (FTC) supplies various tests for Human Resources departments at many companies. One type of test they supply includes spatial concepts questions such as: When the following figure is folded back on the interior lines it forms a cube. Which of t...
31,335
Another Permutation Problem (PERMUT3) Given a permutation of n elements (1, 2, ..., n): A = (a 1 , a 2 , ..., a n ). We define a sequence P(A)=(p 1 , p 2 , …, p n-1 ) where p i = 0 if a i > a i+1 and p i = 1 if a i < a i+1 . Given a permutation B, find the number of all permutations C where P(C)=P(B) including ...
31,336
Chomp (CLK) In Martin Gardner's book «Mathematical Games» the game of «Chomp!» is described as follows. For the game of «Chomp!» you need some pieces which are initially placed on a rectangular playing field and removed from it during the game. (If you are playing on paper then you can use a grid with zeros and c...
31,337
Starcraft I (SC1) Background You may play the game Starcraft I first before you do this problem ^_^. Description Suppose you are using Protoss. At the beginning of the game, you have n probes, a nexus and almost unlimited number of pylons. You can build a probe in the nexus per 3 Starcraft time units (STs), a...
31,338
Archiver (KPARCH) One of your friends wants to write his own archiver. He is going to replace neighboring equal substrings with only one copy. For example, he is going to change substring "AA" with something like "2(A)" and if "A" is long enough it will reduce the file size. But, before performing any coding stuff...
31,339
Weird sorting (KPSORT) You are given N integer numbers a 1 , a 2 , ..., a N . All you need to do is to sort them in non-decreasing order. The bad thing is you are only allowed to perform one action. You can pick any number in the sequence and then reverse all elements to the left and to the right of it. For ...
31,340
Art of War (WAR) The Warring States Period (473-22l BC) refers to the centuries of turmoil following the Spring and Autumn Period. China was divided into many little kingdoms that were constantly fighting with each other. Unlike in previous ages, when chivalry played an important role in battles and the states fou...
31,341
Example (EXAMPLE) As you may have probably noticed a problem statement in a programming contest consists of several sections. The most important section is, of course, the "Example" section. Some seasoned contestants even start reading the problem statement from the examples. And, unfortunately, the least read secti...
31,342
Illumination (ILLUM) Two cubes and a light bulb are placed in a three-dimensional euclidean space. You are expected to find out if one of them casts shadow on the other one and if so, calculate the area of this shadow. Input Multiple test cases. For each test case: The first line of the input contains the coor...
31,343
Put a Point in a Hyperspace (PUTIN) Input Multiple test cases, the number of them is given in the very first line. For each test case: The first line contains 3 space-separated integers K (2<=K<=30), S (2<=S<=10000), M (0<=M<=20). M lines follow, each contains K non-negative integers a ij (1<=i<=M, 1<=j<=K), whi...
31,344
Query on a tree IV (QTREE4) You are given a tree (an acyclic undirected connected graph) with N nodes, and nodes numbered 1,2,3...,N. Each edge has an integer value assigned to it(note that the value can be negative). Each node has a color, white or black. We define dist(a, b) as the sum of the value of the edges on ...
31,345
Polygon (POLYSSQ) You are given N different points in the plane. No three of them are collinear. Write a program that finds out the smallest area of a convex polygon with K vertices which are taken from the given points. Input Two integers, N and K, are written on the first line in the standard input. It follows ...
31,346
Count Minimum Spanning Trees (MSTS) Your task is simple in this problem: count the number of minimum spanning tree ( Wikipedia ) in a simple undirected graph. The number of minimum spanning trees mean in how many ways you can select a subset of the edges of the graphs which forms a minimum spanning tree. Input ...
31,347
Closest distance (GANNHAT) English Vietnamese The manhattan distance between two points A(x 1 ,y 1 ) and B(x 2 ,y 2 ) is defined as following: D(A,B) = |x 1 - x 2 | + |y 1 - y 2 | Given N points A 1 , A 2 , ..., A N , for each point A i you need to calculate the minimum D(A i , A j ) (j ≠ i). Input ...
31,348
Recursive Sequence (Version II) (SPP) Sequence (a i ) of natural numbers is defined as follows: a i = b i (for i <= k ) a i = c 1 a i-1 + c 2 a i-2 + ... + c k a i-k (for i > k ) where b j and c j are given natural numbers for 1<=j<=k . Your task is to compute a m + a m+1 + a m+2 + ... +...
31,349
Untitled Problem (UNTITLED) We consider a sequence S 1 is equal to a sequence S 2 , if and only if they satisfy the following conditions: The length of them are equal. Let Len be the length of them. For each i, j (1 <= i, j <= Len , i != j):If S 1 [i] is smaller than S 1 [j], S 2 [i] must be smaller t...
31,350
Can you answer these queries IV (GSS4) You are given a sequence A of N (N ≤ 100,000) positive integers. There sum will be less than 10 18 . On this sequence you have to apply M (M ≤ 100,000) operations: (A) For given x, y, for each elements between the x-th and the y-th ones (inclusively, counting from 1), modify it...
31,351
Cow Cars (COWCAR) N (1 ≤ N ≤ 50,000) cows conveniently numbered 1, ..., N are driving in separate cars along a highway in Cowtopia. Cow i can drive in any of M different high lanes (1 ≤ M ≤ N) and can travel at a maximum speed of S i (1 ≤ S i ≤ 1,000,000) km/hour. After their other bad driving experience, the cows...
31,352
Glasnici (GLASNICI) A long straight road connects two villages. Along the road, N messengers are stationed and, when needed, they exchange messages using mostly their legs, but also their vocal cords and ears. The first messenger (the closest to the first village) has a radio-receiver which he uses to keep track of cu...
31,353
Maximal Quadrilateral Area (QUADAREA) You are trying to build a house, but unfortunately you currently have only four available walls with side lengths a, b, c, and d. You want your house to be as big as possible, so you would like to know the largest possible area of any quadrilateral you can construct with these fou...
31,354
Army Strength (ARMY) The next MechaGodzilla invasion is on its way to Earth. And once again, Earth will be the battleground for an epic war. MechaGodzilla's army consists of many nasty alien monsters, such as Space Godzilla, King Gidorah, and MechaGodzilla herself. To stop them and defend Earth, Godzilla and h...
31,355
Breaking in (BREAK) Mayco has recently been hired as a security consultant for a well-known software company. At the moment, he's working on his first assignment – trying to determine which of the company's servers would be the best targets for potential attackers. It is a bit difficult, though, because some of the se...
31,356
Inventing Test Data (INVENT) Preparing a problem set is a very hard task. There are always issues with clarity of problem statements, bugs in our solutions, input or output data, and so on. Sometimes, despite our best efforts, these issues are only found during the contest, and this can really spoil it. To preven...
31,357
K Equal Digits (KEQ) Every once in a while, Mishka Jabereen sends an interesting mathematical puzzle to his friends. This week's puzzle will be about so-called "repetitive" numbers – the ones whose decimal expansion has just one kind of digit in it. (Examples of such numbers include 7, 11, and 5555.) The puzzle is abo...
31,358
Large party (LARGE) Irena and Sirup are organizing their engagement party next weekend. They want to invite almost everybody. They have just bought a very big round table for this occasion. But they are now wondering how should they distribute people around the table. Irena claimed that when there are more than K wome...
31,359
Simplify the Railroad System (RAIL) The Slovak national railroad company has recently built new tracks. They want to update their railroad map according to these changes. But they want the map to be as simple as possible. So they decided to remove from the map all the stations that have exactly two other direct connec...
31,360
Perfect Rhyme (PRHYME) A perfect rhyme is not a crime, it is something that exceeds time, a bit of science, a piece of art, soft as a pillow, sharp as a dart. Everyone tried it, but only few chosen ones succeeded. It is a hard task with an unclear path, but a famous end – should you reach it. Many compare it to...
31,361
Number Guessing Game (GUESSING) Please login first to view this problem. :-)
31,362
Summing Sums (SUMSUMS) The N (1 ≤ N ≤ 50,000) cows, conveniently numbered 1, 2, ..., N, are trying to learn some encryption algorithms. After studying a few examples, they have decided to make one of their own! However, they are not very experienced at this, so their algorithm is very simple: Each cow i is given a s...
31,363
Prefix Tiling (PRETILE) You are given a string S with N (1 ≤ N ≤ 100,000) characters from 'A' to 'Z', inclusive. For an integer L between 1 and N, inclusive, we define match (L) as the length of the longest prefix of S that can be tiled by the length-L prefix of S; more specifically, match (L) is the smallest 0-based ...
31,364
Increasing Subsequences (INCSEQ) Given a sequence of N (1 ≤ N ≤ 10,000) integers S 1 , ..., S N (0 ≤ S i < 100,000), compute the number of increasing subsequences of S with length K (1 ≤ K ≤ 50 and K ≤ N); that is, the number of K-tuples i 1 , ..., i K such that 1 ≤ i 1 < ... < i K ≤ N and S i 1 < ... < S i K . ...
31,365
Common Subsequences (CSUBSEQS) You are given four strings, each consisting of at most 50 lower case letters ('a'-'z'). Count the number of non-empty common subsequences of them (the number of distinct non-empty strings which are subsequences of all four strings). Note that a subsequence does not have to be contiguous....
31,366
Distinct Increasing Subsequences (INCDSEQ) Given a sequence of N (1 ≤ N ≤ 10,000) integers S 1 , ..., S N (0 ≤ S i < 1,000,000,000), compute the number of distinct increasing subsequences of S with length K (1 ≤ K ≤ 50 and K ≤ N). Input The first line contains the two integers N and K. The following N lines cont...
31,367
Round-Robin Scheduling (RRSCHED) A computer processor is given N tasks to perform (1 ≤ N ≤ 50,000). The i-th task requires T i seconds of processing time (1 ≤ T i ≤ 1,000,000,000). The processor runs the tasks as follows: each task is run in order, from 1 to N, for 1 second, and then the processor repeats this again...
31,368
Time Limit Exceeded (TLE) Given integers N (1 ≤ N ≤ 50) and M (1 ≤ M ≤ 15), compute the number of sequences a 1 ... a N such that: 0 ≤ a i < 2 M a i is not divisible by c i (0 < c i ≤ 2 M ) a i & a i+1 = 0 (that is, a i and a i+1 have no common bits in their binary representation) Input The fir...
31,369
Find The Determinant III (DETER3) Given a NxN matrix A, find the Determinant of A % P. Input Multiple test cases (the size of input file is about 3MB, all numbers in each matrix are generated randomly). The first line of every test case contains two integers , representing N (0 < N < 201) and P (0 < P < 1,00...
31,370
Super Dice Game (SDGAME) Alice and Bob are playing a game. The game consists of a circular track of M (2 ≤ M ≤ 1,000,000,000) cells labeled 0 through M - 1. Initially both players start at cell 0. The game progresses by having each player take turns rolling one of N (1 ≤ N ≤ 10,000) 'super-dice' labeled 0 through N...
31,371
Memory Limit Exceeded (MLE) Given n points on X-Y plane. To each point, you are to find the other point who is closest to it with respect to the Euclidean distance. Input T (≤ 15) test cases. Each starts with an integer n (2 ≤ n ≤ 100000). Then n lines follow. Each contains two space-separated integers, t...
31,372
Broken Keyboard (BROKEN) Bruce Force's keyboard is broken, only a few keys are still working. Bruce has figured out he can still type texts by switching the keyboard layout whenever he needs to type a letter which is currently not mapped to any of the m working keys of the keyboard. You are given a text tha...
31,373
Decode the Strings (PDECODE) Bruce Force has had an interesting idea how to encode strings. The following is the description of how the encoding is done: Let x 1 , x 2 ... x n be the sequence of characters of the string to be encoded. Choose an integer m and n pairwise distinct numbers p 1 ,p 2 ... p n ...
31,374
Forest (FOREST2) Bruce Force is standing in the forest. He wonders what is the tree trunk the farthest away which is not blocked from his view by other tree trunks. Bruce has made a map of the trees in the forest. The map shows his current position as the origin of a cartesian coordinate system. Tree i is ...
31,375
Help Bob (HELPBOB) Bob loves Pizza but is always out of money. One day he reads in the newspapers that his favorite pizza restaurant, Alfredo's Pizza Restaurant, is running a competition: they will donate a big pizza to the first person who will tell them the lowest price per area that can be achieved by buying any ...
31,376
Another understanding of Super Dice Game (SDGAME2) When we were trying to solve the problem SDGAME, we got a misunderstanding of it. We didn't get AC until we were told the original meaning. But we think our kind of understanding is also interesting and is worthy of doing. So enjoy the problem. Alice and Bob are p...
31,377
Knights of the Round Table (KNIGHTS) Being a knight is a very attractive career: searching for the Holy Grail, saving damsels in distress, and drinking with the other knights are fun things to do. Therefore, it is not very surprising that in recent years the kingdom of King Arthur has experienced an unprecedented incr...
31,378
The Cow Doctor (DOCTOR) Texas is the state having the largest number of cows in the US: according to the 2005 report of the National Agricultural Statistics Service, the bovine population of Texas is 13.8 million. This is higher than the population of the two runner-up states combined: there are only 6.65 million cows...
31,379
Wild West (WILD) Once upon a time in the west... The quiet life of the villages on the western frontier are often stirred up by the appearance of mysterious strangers. A stranger might be a bounty hunter looking for a notorious villain, or he might be a dangerous criminal escaping the hand of justice. The number of st...
31,380
Find the Clones (CLONE) Doubleville, a small town in Texas, was attacked by the aliens. They have abducted some of the residents and taken them to the a spaceship orbiting around earth. After some (quite unpleasant) human experiments, the aliens cloned the victims, and released multiple copies of them back in Doublevi...
31,381
The Warehouse (WARE) Secret Agent OmeGa-7 has found the secret weapon warehouse of the mad scientist Dr. Matroid. The warehouse is full of large boxes (possibly with deadly weapons inside the boxes). While inspecting the warehouse, OmeGa-7 accidentally triggered the alarm system. The warehouse has a very effective pro...
31,382
Widget Factory (WIDGET) The widget factory produces several different kinds of widgets. Each widget is carefully built by a skilled widgeteer. The time required to build a widget depends on its type: the simple widgets need only 3 days, but the most complex ones may need as many as 9 days. The factory is currently ...
31,383
Martian Mining (MARTIAN) The NASA Space Center, Houston, is less than 200 miles from San Antonio, Texas (the site of the ACM Finals this year). This is the place where the astronauts are trained for Mission Seven Dwarfs, the next giant leap in space exploration. The Mars Odyssey program revealed that the surface of Ma...
31,384
Word Rings (WORDRING) A word ring is a sequence of words where the last two letters of each word are the same as the first two letters of the next word (and the last two letters of the last word are the same as the first two letters of the first word). For example, the following sequence is a word ring: intercomm...
31,385
Party of Cloaked Killers (PARTY2) N (1<= N <=100000) perfect killers (we number them 1, 2, 3, ... N ) meet at Blue Mary's house. Every killer has a kind of skill - cloak. No one can see them when they are cloaked - except only a small group of people, which will be discussed later. We can group these killers int...
31,386
Volunteers (VOL) ACM ICPC World Finals 2009, sponsored by IBM and hosted by KTH, Royal Institute of Technology will be held in Stockholm, Sweden. This contest will last for N (1<= N <= 1000) days. We need at least A i volunteers in the i -th day. Now there are M (1<= M <=10000) kind of volunteers. The i -t...
31,387
One Geometry Problem (GEOPROB) This is a problem of Euclidean Geometry. See the figure below. Your task is as follows: given the lengths of segments b, c, and d, calculate the length of segment a. Input The input begins with the number t of test cases in a single line (t ≤ 300). In each of the nex...
31,388
Candy IV (CANDY4) Lazy Child is a lazy child who likes candy very much. Despite being very young, he has two large candy boxes, each initially containing n candies. Everyday he picks one box and open it, if there still are candies, he would eat one. If not, he would be quite sad and open the other box. He will pick ...
31,389
Transportation (TRANSP1) Blue Mary, the queen of Protoss, is planning a war against Zerg. Before the war she plans to make her base as safe as possible. Now there are N (1<= N <= 60) nexuses available in the region controlled by Protoss, numbered 1, 2 ... N . (Those who don't know what nexus is, please visit Bli...
31,390
Not a Triangle (NOTATRI) You have N (3 ≤ N ≤ 2,000) wooden sticks, which are labeled from 1 to N. The i-th stick has a length of L i (1 ≤ L i ≤ 1,000,000). Your friend has challenged you to a simple game: you will pick three sticks at random, and if your friend can form a triangle with them (degenerate triangles inc...
31,391
GCD2 (GCD2) Frank explained its friend Felman the algorithm of Euclides to calculate the GCD of two numbers. Then Felman implements it algorithm int gcd(int a, int b) { if (b==0) return a; else return gcd(b,a%b); } and it proposes to Frank that makes it but with a little integer and another ...
31,392
Can you answer these queries V (GSS5) You are given a sequence A[1], A[2] ... A[N]. (|A[i]| ≤ 10000, 1 ≤ N ≤ 10000). A query is defined as follows: Query(x1, y1, x2, y2) = Max { A[i] + A[i+1] + ... + A[j]; x1 ≤ i ≤ y1, x2 ≤ j ≤ y2 and x1 ≤ x2, y1 ≤ y2 }. Given M queries (1 ≤ M ≤ 10000), your program must output the...
31,393
Query on a tree V (QTREE5) You are given a tree (an acyclic undirected connected graph) with N nodes. The tree nodes are numbered from 1 to N. We define dist(a, b) as the number of edges on the path from node a to node b. Each node has a color, white or black. All the nodes are black initially. We will ask you...
31,394
Untitled Problem II (UNTITLE1) You are given a sequence of N integers A 1 , A 2 ... A N . (-10000 <= A i <= 10000, N <= 50000) Let S i denote the sum of A 1 ... A i . You need to apply M (M <= 50000) operations: 0 x y k: increase all integers from A x to A y by k (1 <= x <= y <= N, -10000 <= k <= 10000...
31,395
Emmons (SHOOTING) After the end of all the shooting competitions in XXIX Olympic Games in Beijing, Matthew Emmons will be known to more and more people because of his last - which is also his worst - shooting in the 50m Rifle 3*40 Men competitions. Four years before in Athens, he shot a wrong target and lost the gold ...
31,396
Eclipse (ECLIPSE) Every so often we hear on the news that there is going to be either a solar or lunar eclipse. Eclipses have a long history dating back well into the BC’s. Astronomers study total solar eclipses very closely as they provide the rare opportunity to observe the corona. An eclipse occurs when two cel...
31,397
Triomino Game (TRIOMINO) English Vietnamese X and Y are playing the following game: They start with an empty 2×N board and move alternately. X moves first. In a move, a player must place an L-triomino (shown on the right), in any of the 4 possible orientations, on the board. The piece placed must not ov...
31,398
Painting Blocks (Act I) (PAINTBLK) n blocks are put in a line. You have k (1 <= k <= 15) kinds of dope, the i -th dope is enough to paint c i (1 <= c i <= 5) blocks. You may assume the sum of all the c i equals to n . Your task is to calculate the number of ways to paint the blocks with these kinds of dope, ...
31,399