problem_statement stringlengths 147 8.53k | input stringlengths 1 771 | output stringlengths 1 592 β | time_limit stringclasses 32
values | memory_limit stringclasses 21
values | tags stringlengths 6 168 |
|---|---|---|---|---|---|
C. Jeff and Bracketstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputJeff loves regular bracket sequences.Today Jeff is going to take a piece of paper and write out the regular bracket sequence, consisting of nm brackets. Let's number all brackets of this sequence fro... | Input2 61 22 1 | Output12 | 1 second | 256 megabytes | ['dp', 'matrices', '*2500'] |
B. Jeff and Furiktime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputJeff has become friends with Furik. Now these two are going to play one quite amusing game.At the beginning of the game Jeff takes a piece of paper and writes down a permutation consisting of n numbers:... | Input21 2 | Output0.000000 | 1 second | 256 megabytes | ['combinatorics', 'dp', 'probabilities', '*1900'] |
A. Jeff and Roundingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputJeff got 2n real numbers a1,βa2,β...,βa2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n oper... | Input30.000 0.500 0.750 1.000 2.000 3.000 | Output0.250 | 1 second | 256 megabytes | ['dp', 'greedy', 'implementation', 'math', '*1800'] |
E. Wrong Floydtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputValera conducts experiments with algorithms that search for shortest paths. He has recently studied the Floyd's algorithm, so it's time to work with it.Valera's already written the code that counts the sho... | Input3 2 21 2 | Output1 32 3 | 1 second | 256 megabytes | ['brute force', 'constructive algorithms', 'dfs and similar', 'graphs', '*2200'] |
D. Looking for Owlstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEmperor Palpatine loves owls very much. The emperor has some blueprints with the new Death Star, the blueprints contain n distinct segments and m distinct circles. We will consider the segments index... | Input1 23 2 3 -20 0 26 0 2 | Output1 | 2 seconds | 256 megabytes | ['binary search', 'data structures', 'geometry', 'hashing', 'sortings', '*2400'] |
C. Bombstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou've got a robot, its task is destroying bombs on a square plane. Specifically, the square plane contains n bombs, the i-th bomb is at point with coordinates (xi,βyi). We know that no two bombs are at the sam... | Input21 1-1 -1 | Output121 1 R1 1 U21 1 L1 1 D31 1 L1 1 D21 1 R1 1 U3 | 2 seconds | 256 megabytes | ['greedy', 'implementation', 'sortings', '*1600'] |
B. Resorttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputValera's finally decided to go on holiday! He packed up and headed for a ski resort.Valera's fancied a ski trip but he soon realized that he could get lost in this new place. Somebody gave him a useful hint: t... | Input50 0 0 0 10 1 2 3 4 | Output51 2 3 4 5 | 2 seconds | 256 megabytes | ['graphs', '*1500'] |
A. TLtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputValera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.Valera has written n correct solutions. For each correct solution, he knows its running time (i... | Input3 64 5 28 9 6 10 7 11 | Output5 | 2 seconds | 256 megabytes | ['brute force', 'greedy', 'implementation', '*1200'] |
B. Color the Fencetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIgor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tan... | Input55 4 3 2 1 2 3 4 5 | Output55555 | 2 seconds | 256 megabytes | ['data structures', 'dp', 'greedy', 'implementation', '*1700'] |
A. Cinema Linetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe new "Die Hard" movie has just been released! There are n people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 ruble... | Input425 25 50 50 | OutputYES | 2 seconds | 256 megabytes | ['greedy', 'implementation', '*1100'] |
E. Pilgrimstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA long time ago there was a land called Dudeland. Dudeland consisted of n towns connected with nβ-β1 bidirectonal roads. The towns are indexed from 1 to n and one can reach any city from any other city if he... | Input8 57 2 5 4 81 2 12 3 21 4 14 5 21 6 16 7 86 8 10 | Output5 1 | 2 seconds | 256 megabytes | ['dfs and similar', 'dp', 'trees', '*2800'] |
D. Turtlestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou've got a table of size nβΓβm. We'll consider the table rows numbered from top to bottom 1 through n, and the columns numbered from left to right 1 through m. Then we'll denote the cell in row x and column... | Input4 5......###..###...... | Output1 | 2 seconds | 256 megabytes | ['dp', 'matrices', '*2500'] |
C. Subset Sumstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a1,βa2,β...,βan and m sets S1,βS2,β...,βSm of indices of elements of this array. Let's denote Skβ=β{Sk,βi}Β (1ββ€βiββ€β|Sk|). In other words, Sk,βi is some element from set Sk.In this ... | Input5 3 55 -5 5 1 -42 1 24 2 1 4 52 2 5? 2+ 3 4? 1+ 2 1? 2 | Output-349 | 3 seconds | 256 megabytes | ['brute force', 'data structures', '*2500'] |
B. Apple Treetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a rooted tree with n vertices. In each leaf vertex there's a single integer β the number of apples in this vertex. The weight of a subtree is the sum of all numbers in this subtree leaves. Fo... | Input60 0 12 13 5 61 21 31 42 52 6 | Output6 | 2 seconds | 256 megabytes | ['dfs and similar', 'number theory', 'trees', '*2100'] |
A. Mafiatime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other nβ-β1 people take part in the game. For each person we know in how many rounds he ... | Input33 2 2 | Output4 | 2 seconds | 256 megabytes | ['binary search', 'math', 'sortings', '*1600'] |
B. Fixed Pointstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA permutation of length n is an integer sequence such that each integer from 0 to (nβ-β1) appears exactly once in it. For example, sequence [0,β2,β1] is a permutation of length 3 while both [0,β2,β2] and... | Input50 1 3 4 2 | Output3 | 2 seconds | 256 megabytes | ['brute force', 'implementation', 'math', '*1100'] |
A. Difference Rowtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou want to arrange n integers a1,βa2,β...,βan in some order in a row. Let's define the value of an arrangement as the sum of differences between all pairs of adjacent integers.More formally, let's den... | Input5100 -100 50 0 -50 | Output100 -50 0 50 -100 | 2 seconds | 256 megabytes | ['constructive algorithms', 'implementation', 'sortings', '*1300'] |
E. Doodle Jumptime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output In Doodle Jump the aim is to guide a four-legged creature called "The Doodler" up a never-ending series of platforms without falling. β Wikipedia. It is a very popular game and xiaodao likes it very much... | Input37 4 12 27 1 9 47 4 12 3 | OutputNONOYES | 2 seconds | 256 megabytes | ['math', 'number theory', '*3000'] |
D. Robot Controltime limit per test6 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe boss of the Company of Robot is a cruel man. His motto is "Move forward Or Die!". And that is exactly what his company's product do. Look at the behavior of the company's robot when it is walking in... | Input4 61 22 11 33 12 43 41 4 | Output1 | 6 seconds | 256 megabytes | ['dp', 'graphs', 'shortest paths', '*2600'] |
C. Number Transformation IItime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a sequence of positive integers x1,βx2,β...,βxn and two non-negative integers a and b. Your task is to transform a into b. To do that, you can perform the following moves: subtr... | Input33 4 530 17 | Output6 | 1 second | 256 megabytes | ['greedy', 'math', '*2200'] |
B. Lucky Common Subsequencetime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputIn mathematics, a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. For example, the sequence... | InputAJKEQSLOBSROFGZOVGURWZLWVLUXTHOZ | OutputORZ | 3 seconds | 512 megabytes | ['dp', 'strings', '*2000'] |
A. Alice and Bobtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of n distinct integers. And then they take turns to ma... | Input22 3 | OutputAlice | 2 seconds | 256 megabytes | ['games', 'math', 'number theory', '*1600'] |
G. Suffix Subgrouptime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a group of n strings: s1,βs2,β...,βsn.You should find a subgroup si1,βsi2,β...,βsik (1ββ€βi1β<βi2β<β...β<βikββ€βn) of the group. The following two conditions must hold: there exists a str... | Input6bbbbbaaaaaz | Output3 | 2 seconds | 256 megabytes | ['*special problem', 'strings', '*2200'] |
F. Superstitions Inspectiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou read scientific research regarding popularity of most famous superstitions across various countries, and you want to analyze their data. More specifically, you want to know which supersti... | InputUkraine* Friday the 13th* black cat* knock the woodUSA* wishing well* friday the 13thHollandFrance* Wishing Well | Outputfriday the 13th wishing well | 2 seconds | 256 megabytes | ['*special problem', '*2700'] |
E. Black Cat Rushtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputToday you go out of your house and immediately notice that something is weird. Around your door there is a swarm of black cats β all tense paws and twitching tails. As you do your first step, they all ... | Input1 1 5 40 34 -47 0-2 -2 | Output3 | 2 seconds | 256 megabytes | ['*special problem', '*2700'] |
D. Chain Lettertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA chain letter is a kind of a message which urges the recipient to forward it to as many contacts as possible, usually with some kind of mystic explanation. Of course, this is only a superstition, and yo... | Input40111101111011110 | Output3 | 2 seconds | 256 megabytes | ['*special problem', 'dfs and similar', 'graphs', '*2200'] |
C. Counting Fridaystime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputJudging from the previous problem, Friday the 13th really doesn't treat you well, so you start thinking about how to minimize its impact on your life. You are a passionate participant of programming ... | Input52012-01-132012-09-132012-11-202013-09-132013-09-20 | Output2 | 2 seconds | 256 megabytes | ['*special problem', '*2000'] |
B. Triskaidekaphobiatime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTriskaidekaphobia is a fear of number 13. Ordinary people who suffer from this phobia feel uncomfortable around numbers 13, 130, 513 etc, but you, being a programmer, take this fear one step further... | Input7 | Output1 | 2 seconds | 256 megabytes | ['*special problem', '*2100'] |
A. Expecting Troubletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt is Friday the 13th today, and even though you're a modern well-educated person, you can't help feeling a bit nervous about it. You decide to look for evidence against this superstition (or for it... | Input?111?1??11.0 | Output1.00000 | 2 seconds | 256 megabytes | ['*special problem', 'probabilities', '*1500'] |
B. Simple Moleculestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMad scientist Mike is busy carrying out experiments in chemistry. Today he will attempt to join three atoms into one molecule.A molecule consists of atoms, with some pairs of atoms connected by atomic... | Input1 1 2 | Output0 1 1 | 1 second | 256 megabytes | ['brute force', 'graphs', 'math', '*1200'] |
A. Magnetstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus... | Input6101010011010 | Output3 | 1 second | 256 megabytes | ['implementation', '*800'] |
E. Pumping Stationstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMad scientist Mike has applied for a job. His task is to manage a system of water pumping stations.The system consists of n pumping stations, which are numbered by integers from 1 to n. Some pairs of... | Input6 111 2 101 6 82 3 42 5 22 6 33 4 53 5 43 6 24 5 74 6 25 6 3 | Output776 2 1 5 3 4 | 2 seconds | 256 megabytes | ['brute force', 'dfs and similar', 'divide and conquer', 'flows', 'graphs', 'greedy', 'trees', '*2900'] |
D. Water Treetime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMad scientist Mike has constructed a rooted tree, which consists of n vertices. Each vertex is a reservoir which can be either empty or filled with water.The vertices of the tree are numbered from 1 to n w... | Input51 25 12 34 2121 12 33 13 23 33 41 22 43 13 33 43 5 | Output00010101 | 4 seconds | 256 megabytes | ['data structures', 'dfs and similar', 'graphs', 'trees', '*2100'] |
C. Read Timetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMad scientist Mike does not use slow hard disks. His modification of a hard drive has not one, but n different heads that can read data in parallel.When viewed from the side, Mike's hard drive is an endless ... | Input3 42 5 61 3 6 8 | Output2 | 1 second | 256 megabytes | ['binary search', 'greedy', 'two pointers', '*1900'] |
B. Alternating Currenttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMad scientist Mike has just finished constructing a new device to search for extraterrestrial intelligence! He was in such a hurry to launch it for the first time that he plugged in the power wires... | Input-++- | OutputYes | 1 second | 256 megabytes | ['data structures', 'greedy', 'implementation', '*1600'] |
A. Rational Resistancetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.However, all Mike has is lots of identical resistors with un... | Input1 1 | Output1 | 1 second | 256 megabytes | ['math', 'number theory', '*1600'] |
E. Xenia and Treetime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputXenia the programmer has a tree consisting of n nodes. We will consider the tree nodes indexed from 1 to n. We will also consider the first node to be initially painted red, and the other nodes β to be... | Input5 41 22 32 44 52 12 51 22 5 | Output032 | 5 seconds | 256 megabytes | ['data structures', 'divide and conquer', 'trees', '*2400'] |
D. Xenia and Dominoestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputXenia likes puzzles very much. She is especially fond of the puzzles that consist of domino pieces. Look at the picture that shows one of such puzzles. A puzzle is a 3βΓβn table with forbidden cel... | Input5....X.O......X. | Output1 | 2 seconds | 256 megabytes | ['bitmasks', 'dfs and similar', 'dp', '*2100'] |
C. Cupboard and Balloonstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA girl named Xenia has a cupboard that looks like an arc from ahead. The arc is made of a semicircle with radius r (the cupboard's top) and two walls of height h (the cupboard's sides). The cupb... | Input1 1 | Output3 | 2 seconds | 256 megabytes | ['geometry', '*1900'] |
B. Xenia and Spiestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputXenia the vigorous detective faced n (nββ₯β2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right. Spy s has an important note. He has to pass the note to s... | Input3 5 1 31 1 22 2 33 3 34 1 110 1 3 | OutputXXRR | 1 second | 256 megabytes | ['brute force', 'greedy', 'implementation', '*1500'] |
A. Xenia and Divisorstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputXenia the mathematician has a sequence consisting of n (n is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group... | Input61 1 1 2 2 2 | Output-1 | 1 second | 256 megabytes | ['greedy', 'implementation', '*1200'] |
E. Candies Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIahub is playing an uncommon game. Initially, he has n boxes, numbered 1, 2, 3, ..., n. Each box has some number of candies in it, described by a sequence a1, a2, ..., an. The number ak represents the nu... | Input33 6 9 | Output22 31 3 | 2 seconds | 256 megabytes | ['constructive algorithms', 'greedy', '*3000'] |
D. Iahub and Xorstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIahub does not like background stories, so he'll tell you exactly what this problem asks you for.You are given a matrix a with n rows and n columns. Initially, all values of the matrix are zeros. Both r... | Input3 52 1 1 2 2 12 1 3 2 3 22 3 1 3 3 31 2 2 3 31 2 2 3 2 | Output32 | 1 second | 256 megabytes | ['data structures', '*2500'] |
E. Iahub and Permutationstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more important for Iahub. When Iahub ... | Input5-1 -1 4 3 -1 | Output2 | 1 second | 256 megabytes | ['combinatorics', 'math', '*2000'] |
D. Bubble Sort Graphtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIahub recently has learned Bubble Sort, an algorithm that is used to sort a permutation with n elements a1, a2, ..., an in ascending order. He is bored of this so simple algorithm, so he invents his ... | Input33 1 2 | Output2 | 1 second | 256 megabytes | ['binary search', 'data structures', 'dp', '*1500'] |
C. Tourist Problemtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIahub is a big fan of tourists. He wants to become a tourist himself, so he planned a trip. There are n destinations on a straight road that Iahub wants to visit. Iahub starts the excursion from kilome... | Input32 3 5 | Output22 3 | 1 second | 256 megabytes | ['combinatorics', 'implementation', 'math', '*1600'] |
B. Maximal Area Quadrilateraltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIahub has drawn a set of n points in the cartesian plane which he calls "special points". A quadrilateral is a simple polygon without self-intersections with four sides (also called edges) a... | Input50 00 44 04 42 3 | Output16.000000 | 1 second | 256 megabytes | ['brute force', 'geometry', '*2100'] |
A. The Walltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 a... | Input2 3 6 18 | Output3 | 1 second | 256 megabytes | ['math', '*1200'] |
E. Three Swapstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputXenia the horse breeder has n (nβ>β1) horses that stand in a row. Each horse has its own unique number. Initially, the i-th left horse has number i. That is, the sequence of numbers of horses in a row look... | Input51 4 3 2 5 | Output12 4 | 1 second | 256 megabytes | ['constructive algorithms', 'dfs and similar', 'greedy', '*2700'] |
D. Xenia and Bit Operationstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputXenia the beginner programmer has a sequence a, consisting of 2n non-negative integers: a1,βa2,β...,βa2n. Xenia is currently studying bit operations. To better understand how they work, Xenia... | Input2 41 6 3 51 43 41 21 2 | Output1333 | 2 seconds | 256 megabytes | ['data structures', 'trees', '*1700'] |
C. Xenia and Weightstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputXenia has a set of weights and pan scales. Each weight has an integer weight from 1 to 10 kilos. Xenia is going to play with scales and weights a little. For this, she puts weights on the scalepans,... | Input00000001013 | OutputYES8 10 8 | 2 seconds | 256 megabytes | ['constructive algorithms', 'dfs and similar', 'dp', 'graphs', 'greedy', 'shortest paths', '*1700'] |
B. Xenia and Ringroadtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputXenia lives in a city that has n houses built along the main ringroad. The ringroad houses are numbered 1 through n in the clockwise order. The ringroad traffic is one way and also is clockwise.Xen... | Input4 33 2 3 | Output6 | 2 seconds | 256 megabytes | ['implementation', '*1000'] |
A. Helpful Mathstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputXenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.The teacher has written down the sum of multiple numbers. Pupils should calculat... | Input3+2+1 | Output1+2+3 | 2 seconds | 256 megabytes | ['greedy', 'implementation', 'sortings', 'strings', '*800'] |
E. Optimize!time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputManao is solving a problem with the following statement: He came up with a solution that produces the correct answers but is too slow. You are given the pseudocode of his solution, where the function getAn... | Input5 2 105 31 8 5 5 7 | Output2 | 2 seconds | 256 megabytes | ['data structures', '*2600'] |
D. GCD Tabletime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputConsider a table G of size nβΓβm such that G(i,βj)β=βGCD(i,βj) for all 1ββ€βiββ€βn,β1ββ€βjββ€βm. GCD(a,βb) is the greatest common divisor of numbers a and b.You have a sequence of positive integer numbers a1,βa2... | Input100 100 55 2 1 2 1 | OutputYES | 1 second | 256 megabytes | ['chinese remainder theorem', 'math', 'number theory', '*2900'] |
E. Divisor Treetime limit per test0.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA divisor tree is a rooted tree that meets the following conditions: Each vertex of the tree contains a positive integer number. The numbers written in the leaves of the tree are prime numbers. For... | Input26 10 | Output7 | 0.5 seconds | 256 megabytes | ['brute force', 'number theory', 'trees', '*2200'] |
D. Book of Eviltime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPaladin Manao caught the trail of the ancient Book of Evil in a swampy area. This area contains n settlements numbered from 1 to n. Moving through the swamp is very difficult, so people tramped exactly n... | Input6 2 31 21 52 33 44 55 6 | Output3 | 2 seconds | 256 megabytes | ['dfs and similar', 'divide and conquer', 'dp', 'trees', '*2000'] |
C. Quiztime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputManao is taking part in a quiz. The quiz consists of n consecutive questions. A correct answer gives one point to the player. The game also has a counter of consecutive correct answers. When the player answers a ... | Input5 3 2 | Output3 | 1 second | 256 megabytes | ['binary search', 'greedy', 'math', 'matrices', 'number theory', '*1600'] |
B. Routine Problemtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputManao has a monitor. The screen of the monitor has horizontal to vertical length ratio a:b. Now he is going to watch a movie. The movie's frame has horizontal to vertical length ratio c:d. Manao adjust... | Input1 1 3 2 | Output1/3 | 1 second | 256 megabytes | ['greedy', 'math', 'number theory', '*1400'] |
A. Puzzlestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her n students and give each of them a jigsaw ... | Input4 610 12 10 7 5 22 | Output5 | 1 second | 256 megabytes | ['greedy', '*900'] |
E. Vasily the Bear and Painting Squaretime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasily the bear has two favorite integers n and k and a pencil. Besides, he's got k jars with different water color paints. All jars are numbered in some manner from 1 to k, inclus... | Input0 0 | Output1 | 2 seconds | 256 megabytes | ['bitmasks', 'combinatorics', 'dp', 'implementation', '*2700'] |
D. Vasily the Bear and Beautiful Stringstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasily the Bear loves beautiful strings. String s is beautiful if it meets the following criteria: String s only consists of characters 0 and 1, at that character 0 must occur ... | Input1 1 0 | Output2 | 2 seconds | 256 megabytes | ['combinatorics', 'math', 'number theory', '*2100'] |
C. Vasily the Bear and Sequencetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasily the bear has got a sequence of positive integers a1,βa2,β...,βan. Vasily the Bear wants to write out several numbers on a piece of paper so that the beauty of the numbers he wrote o... | Input51 2 3 4 5 | Output24 5 | 1 second | 256 megabytes | ['brute force', 'greedy', 'implementation', 'number theory', '*1800'] |
B. Vasily the Bear and Flytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne beautiful day Vasily the bear painted 2m circles of the same radius R on a coordinate plane. Circles with numbers from 1 to m had centers at points (2Rβ-βR,β0), (4Rβ-βR,β0), ..., (2Rmβ-βR,β... | Input1 1 | Output2.0000000000 | 1 second | 256 megabytes | ['math', '*1900'] |
A. Vasily the Bear and Triangletime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasily the bear has a favorite rectangle, it has one vertex at point (0,β0), and the opposite vertex at point (x,βy). Of course, the sides of Vasya's favorite rectangle are parallel to the... | Input10 5 | Output0 15 15 0 | 1 second | 256 megabytes | ['implementation', 'math', '*1000'] |
F. Buy One, Get One Freetime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA nearby pie shop is having a special sale. For each pie you pay full price for, you may select one pie of a strictly lesser value to get for free. Given the prices of all the pies you wish to a... | Input63 4 5 3 4 5 | Output14 | 5 seconds | 256 megabytes | ['dp', 'greedy', '*3000'] |
E. Counting Skyscraperstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA number of skyscrapers have been built in a line. The number of skyscrapers was chosen uniformly at random between 2 and 314! (314 factorial, a very large number). The height of each skyscraper ... | InputAlice3 1 | Output3.500000000 | 2 seconds | 256 megabytes | ['dp', 'math', 'probabilities', '*2800'] |
D. Rectangles and Squaretime limit per test3 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given n rectangles, labeled 1 through n. The corners of rectangles have integer coordinates and their edges are parallel to the Ox and Oy axes. The rectangles may touch each other, but t... | Input90 0 1 91 0 9 11 8 9 98 1 9 82 2 3 63 2 7 32 6 7 75 3 7 63 3 5 6 | OutputYES 55 6 7 8 9 | 3 seconds | 512 megabytes | ['brute force', 'dp', '*2400'] |
C. More Reclamationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn a far away land, there are two cities near a river. One day, the cities decide that they have too little space and would like to reclaim some of the river area into land.The river area can be repr... | Input3 11 1 | OutputWIN | 2 seconds | 256 megabytes | ['games', '*2100'] |
B. Palindrometime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGiven a string s, determine if it contains any palindrome of length exactly 100 as a subsequence. If it has any, print any one of them. If it doesn't have any, print a palindrome that is a subsequence of s... | Inputbbbabcbbb | Outputbbbcbbb | 2 seconds | 256 megabytes | ['constructive algorithms', 'dp', '*1900'] |
A. Bananatime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPiegirl is buying stickers for a project. Stickers come on sheets, and each sheet of stickers contains exactly n stickers. Each sticker has exactly one character printed on it, so a sheet of stickers can be de... | Inputbanana4 | Output2baan | 2 seconds | 256 megabytes | ['binary search', 'constructive algorithms', 'greedy', '*1400'] |
B. Eight Point Setstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct... | Input0 00 10 21 01 22 02 12 2 | Outputrespectable | 1 second | 256 megabytes | ['sortings', '*1400'] |
A. Candy Bagstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGerald has n younger brothers and their number happens to be even. One day he bought n2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each int... | Input2 | Output1 42 3 | 1 second | 256 megabytes | ['implementation', '*1000'] |
E. Summer Earningstime limit per test9 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMany schoolchildren look for a job for the summer, and one day, when Gerald was still a schoolboy, he also decided to work in the summer. But as Gerald was quite an unusual schoolboy, he found quite u... | Input30 11 01 1 | Output0.50000000000000000000 | 9 seconds | 256 megabytes | ['binary search', 'bitmasks', 'brute force', 'geometry', 'sortings', '*2500'] |
D. Characteristics of Rectanglestime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGerald found a table consisting of n rows and m columns. As a prominent expert on rectangular tables, he immediately counted the table's properties, that is, the minimum of the numbers i... | Input2 21 23 4 | Output1 | 3 seconds | 256 megabytes | ['binary search', 'bitmasks', 'brute force', 'implementation', 'sortings', '*2100'] |
C. Lucky Ticketstime limit per test6 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGerald has a friend, Pollard. Pollard is interested in lucky tickets (ticket is a sequence of digits). At first he thought that a ticket is lucky if between some its digits we can add arithmetic signs a... | Input0 3 | Output000000000000000100000002 | 6 seconds | 256 megabytes | ['brute force', 'constructive algorithms', '*2700'] |
B. Chipstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGerald plays the following game. He has a checkered field of size nβΓβn cells, where m various cells are banned. Before the game, he has to put a few chips on some border (but not corner) board cells. Then for n... | Input3 12 2 | Output0 | 1 second | 256 megabytes | ['greedy', '*1800'] |
A. Secretstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGerald has been selling state secrets at leisure. All the secrets cost the same: n marks. The state which secrets Gerald is selling, has no paper money, only coins. But there are coins of all positive integer ... | Input1 | Output1 | 1 second | 256 megabytes | ['greedy', '*1600'] |
E. Binary Keytime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's assume that p and q are strings of positive length, called the container and the key correspondingly, string q only consists of characters 0 and 1. Let's take a look at a simple algorithm that extrac... | Inputabacabaaba6 | Output100001 | 4 seconds | 256 megabytes | ['dp', 'greedy', 'implementation', '*2400'] |
D. Theft of Blueprintstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputInsurgents accidentally got hold of the plan of a top secret research polygon created on a distant planet for the needs of the Galaxy Empire. The insurgents suppose that this polygon is developing... | Input6 1-1 -1 -1 8 -1-1 5 -1 -1-1 -1 3-1 -1-1 | Output5 | 3 seconds | 256 megabytes | ['graphs', 'math', '*2400'] |
C. Students' Revengetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA student's life is fraught with complications. Some Berland University students know this only too well. Having studied for two years, they contracted strong antipathy towards the chairperson of so... | Input5 3 25 65 81 34 34 11 | Output3 1 2 | 2 seconds | 256 megabytes | ['data structures', 'greedy', 'sortings', '*2200'] |
B. Maximum Absurditytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputReforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as n laws (each law has been assigned a unique number from 1 to n). Today all these l... | Input5 23 6 1 1 6 | Output1 4 | 2 seconds | 256 megabytes | ['data structures', 'dp', 'implementation', '*1500'] |
A. Down the Hatch!time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEverybody knows that the Berland citizens are keen on health, especially students. Berland students are so tough that all they drink is orange juice!Yesterday one student, Vasya and his mates made som... | Input4abbba | Output1 | 2 seconds | 256 megabytes | ['implementation', '*1300'] |
E2. Deja Vutime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEverybody knows that we have been living in the Matrix for a long time. And in the new seventh Matrix the world is ruled by beavers.So let's take beaver Neo. Neo has so-called "deja vu" outbursts when he get... | Input6 61 2 2 1 22 3 1 33 4 2 4 54 5 05 3 1 36 1 1 6 | Output46 1 2 3 | 2 seconds | 256 megabytes | ['constructive algorithms', 'dp', '*3100'] |
E1. Deja Vutime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEverybody knows that we have been living in the Matrix for a long time. And in the new seventh Matrix the world is ruled by beavers.So let's take beaver Neo. Neo has so-called "deja vu" outbursts when he get... | Input6 61 2 2 1 22 3 1 33 4 2 4 54 5 05 3 1 36 1 1 6 | Output46 1 2 3 | 2 seconds | 256 megabytes | ['constructive algorithms', 'graphs', 'implementation', '*2900'] |
D3. Escaping on Beaveractortime limit per test6 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputDon't put up with what you're sick of! The Smart Beaver decided to escape from the campus of Beaver Science Academy (BSA). BSA is a bβΓβb square on a plane. Each point x,βy (0ββ€βx,βyββ€βb) bel... | Input3 30 0 0 10 2 2 23 3 2 3120 0 L 00 0 L 10 0 L 20 0 L 30 0 L 40 0 L 50 0 L 62 0 U 22 0 U 33 0 U 51 3 D 21 3 R 2 | Output0 00 10 21 22 23 23 22 23 21 32 21 3 | 6 seconds | 512 megabytes | ['data structures', 'implementation', 'trees', '*3000'] |
D2. Escaping on Beaveractortime limit per test6 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputDon't put up with what you're sick of! The Smart Beaver decided to escape from the campus of Beaver Science Academy (BSA). BSA is a bβΓβb square on a plane. Each point x,βy (0ββ€βx,βyββ€βb) bel... | Input3 30 0 0 10 2 2 23 3 2 3120 0 L 00 0 L 10 0 L 20 0 L 30 0 L 40 0 L 50 0 L 62 0 U 22 0 U 33 0 U 51 3 D 21 3 R 2 | Output0 00 10 21 22 23 23 22 23 21 32 21 3 | 6 seconds | 512 megabytes | ['graphs', '*2600'] |
D1. Escaping on Beaveractortime limit per test6 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputDon't put up with what you're sick of! The Smart Beaver decided to escape from the campus of Beaver Science Academy (BSA). BSA is a bβΓβb square on a plane. Each point x,βy (0ββ€βx,βyββ€βb) bel... | Input3 30 0 0 10 2 2 23 3 2 3120 0 L 00 0 L 10 0 L 20 0 L 30 0 L 40 0 L 50 0 L 62 0 U 22 0 U 33 0 U 51 3 D 21 3 R 2 | Output0 00 10 21 22 23 23 22 23 21 32 21 3 | 6 seconds | 512 megabytes | ['dfs and similar', 'implementation', '*2400'] |
C3. The Great Julya Calendartime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYet another Armageddon is coming! This time the culprit is the Julya tribe calendar. The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a ... | Input24 | Output5 | 2 seconds | 256 megabytes | ['dp', '*2500'] |
C2. The Great Julya Calendartime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYet another Armageddon is coming! This time the culprit is the Julya tribe calendar. The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a ... | Input24 | Output5 | 2 seconds | 256 megabytes | ['dp', '*2400'] |
C1. The Great Julya Calendartime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYet another Armageddon is coming! This time the culprit is the Julya tribe calendar. The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a ... | Input24 | Output5 | 2 seconds | 256 megabytes | ['dp', '*1100'] |
B2. Shave Beaver!time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Smart Beaver has recently designed and built an innovative nanotechnologic all-purpose beaver mass shaving machine, "Beavershave 5000". Beavershave 5000 can shave beavers by families! How does it w... | Input51 3 4 2 561 1 51 3 42 2 31 1 52 1 51 1 5 | Output2135 | 2 seconds | 256 megabytes | ['data structures', '*1900'] |
B1. Shave Beaver!time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Smart Beaver has recently designed and built an innovative nanotechnologic all-purpose beaver mass shaving machine, "Beavershave 5000". Beavershave 5000 can shave beavers by families! How does it w... | Input51 3 4 2 561 1 51 3 42 2 31 1 52 1 51 1 5 | Output2135 | 2 seconds | 256 megabytes | ['implementation', '*1700'] |
A2. Oh Sweet Beaverettetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output β Oh my sweet Beaverette, would you fancy a walk along a wonderful woodland belt with me? β Of course, my Smart Beaver! Let us enjoy the splendid view together. How about Friday night? At this... | Input51 2 3 1 2 | Output8 11 | 2 seconds | 256 megabytes | ['data structures', 'sortings', '*1500'] |
A1. Oh Sweet Beaverettetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output β Oh my sweet Beaverette, would you fancy a walk along a wonderful woodland belt with me? β Of course, my Smart Beaver! Let us enjoy the splendid view together. How about Friday night? At this... | Input51 2 3 1 2 | Output8 11 | 2 seconds | 256 megabytes | ['brute force', 'implementation', '*1400'] |
B. Road Constructiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA country has n cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those ro... | Input4 11 3 | Output31 24 22 3 | 2 seconds | 256 megabytes | ['constructive algorithms', 'graphs', '*1300'] |
A. Cakeminatortime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a rectangular cake, represented as an rβΓβc grid. Each cell either has an evil strawberry, or is empty. For example, a 3βΓβ4 cake may look as follows: The cakeminator is going to eat the cak... | Input3 4S.........S. | Output8 | 1 second | 256 megabytes | ['brute force', 'implementation', '*800'] |
E. Eviltime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n cities on a two dimensional Cartesian plane. The distance between two cities is equal to the Manhattan distance between them (see the Notes for definition). A Hamiltonian cycle of the cities is defin... | Input41 11 22 12 2 | Output6 | 3 seconds | 256 megabytes | ['math', '*3100'] |
D. The Evil Temple and the Moving Rockstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputImportant: All possible tests are in the pretest, so you shouldn't hack on this problem. So, if you passed pretests, you will also pass the system test.You are an adventurer curre... | Input5 5 | Output>...vv.<....^..>......^.<1 1 | 2 seconds | 256 megabytes | ['constructive algorithms', '*2500'] |
C. Graph Reconstructiontime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputI have an undirected graph consisting of n nodes, numbered 1 through n. Each node has at most two incident edges. For each pair of nodes, there is at most an edge connecting them. No edge connect... | Input8 71 22 34 55 66 88 77 4 | Output1 44 61 62 77 58 52 8 | 3 seconds | 256 megabytes | ['constructive algorithms', '*2400'] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.