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 |
|---|---|---|---|---|---|
A. Tennis Tournamenttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA tennis tournament with n participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.The tournament takes place in the following way (... | Input5 2 3 | Output20 15 | 1 second | 256 megabytes | ['implementation', 'math', '*1000'] |
F. Island Puzzletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA remote island chain contains n islands, with some bidirectional bridges between them. The current bridge network forms a tree. In other words, a total of n - 1 bridges connect pairs of islands in a wa... | Input31 0 22 0 11 22 3 | Output1 3 3 | 2 seconds | 256 megabytes | ['dfs and similar', 'dsu', 'graphs', 'trees', '*3400'] |
E. Orchestratime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPaul is at the orchestra. The string section is arranged in an r × c rectangular grid and is filled with violinists with the exception of n violists. Paul really likes violas, so he would like to take a pic... | Input2 2 1 11 2 | Output4 | 2 seconds | 256 megabytes | ['two pointers', '*3000'] |
D. Preorder Testtime limit per test7 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFor his computer science class, Jacob builds a model tree with sticks and balls containing n nodes in the shape of a tree. Jacob has spent ai minutes building the i-th ball in the tree.Jacob's teacher w... | Input5 33 6 1 4 21 22 42 51 3 | Output3 | 7 seconds | 256 megabytes | ['binary search', 'dfs and similar', 'dp', 'graphs', 'greedy', 'trees', '*2600'] |
C. Package Deliverytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputJohnny drives a truck and must deliver a package from his hometown to the district center. His hometown is located at point 0 on a number line, and the district center is located at the point d.Johnn... | Input10 4 43 55 86 38 4 | Output22 | 2 seconds | 256 megabytes | ['data structures', 'divide and conquer', 'greedy', '*2200'] |
B. Factory Repairstime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA factory produces thimbles in bulk. Typically, it can produce up to a thimbles a day. However, some of the machinery is defective, so it can currently only produce b thimbles each day. The factory in... | Input5 2 2 1 81 1 21 5 31 2 12 21 4 21 3 22 12 3 | Output364 | 4 seconds | 256 megabytes | ['data structures', '*1700'] |
A. XOR Equationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTwo positive integers a and b have a sum of s and a bitwise XOR of x. How many possible values are there for the ordered pair (a, b)?InputThe first line of the input contains two integers s and x (2 ≤ s ... | Input9 5 | Output4 | 2 seconds | 256 megabytes | ['dp', 'math', '*1700'] |
G. Rafflestime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputJohnny is at a carnival which has n raffles. Raffle i has a prize with value pi. Each participant can put tickets in whichever raffles they choose (they may have more than one ticket in a single raffle). At t... | Input2 1 34 51 21 11 22 1 | Output1.6666666671.3333333332.000000000 | 5 seconds | 256 megabytes | ['data structures', 'dp', 'greedy', 'math', '*3100'] |
F. Group Projectstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n students in a class working on group projects. The students will divide into groups (some students may be in groups alone), work on their independent pieces, and then discuss the results to... | Input3 22 4 5 | Output3 | 2 seconds | 256 megabytes | ['dp', '*2400'] |
E. Simple Skewnesstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDefine the simple skewness of a collection of numbers to be the collection's mean minus its median. You are given a list of n (not necessarily distinct) integers. Find the non-empty subset (with repet... | Input41 2 3 12 | Output31 2 12 | 3 seconds | 256 megabytes | ['binary search', 'math', 'ternary search', '*2400'] |
D. Jerry's Protesttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAndrew and Jerry are playing a game with Harry as the scorekeeper. The game consists of three rounds. In each round, Andrew and Jerry draw randomly without replacement from a jar containing n balls, e... | Input21 2 | Output0.0000000000 | 2 seconds | 256 megabytes | ['brute force', 'combinatorics', 'dp', 'probabilities', '*1800'] |
C. Block Towerstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputStudents in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the stu... | Input1 3 | Output9 | 2 seconds | 256 megabytes | ['brute force', 'greedy', 'math', 'number theory', '*1600'] |
B. Cardstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputCatherine has a deck of n cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions: take any two (not necessarily adjacent) cards with di... | Input2RB | OutputG | 2 seconds | 256 megabytes | ['constructive algorithms', 'dp', 'math', '*1300'] |
A. Robot Sequencetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputCalvin the robot lies in an infinite rectangular grid. Calvin's source code contains a list of n commands, each either 'U', 'R', 'D', or 'L' — instructions to move a single square up, right, down, or l... | Input6URLLDR | Output2 | 2 seconds | 256 megabytes | ['brute force', 'implementation', '*1000'] |
E. Frog Fightstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOstap Bender recently visited frog farm and was inspired to create his own frog game.Number of frogs are places on a cyclic gameboard, divided into m cells. Cells are numbered from 1 to m, but the board i... | Input3 52 15 34 3 | Output13 | 2 seconds | 256 megabytes | ['data structures', 'greedy', '*2800'] |
D. Finals in arithmetictime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fill... | Input4 | Output2 | 2 seconds | 256 megabytes | ['constructive algorithms', 'implementation', 'math', '*2400'] |
C. K-special Tablestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPeople do many crazy things to stand out in a crowd. Some of them dance, some learn by heart rules of Russian language, some try to become an outstanding competitive programmers, while others collect... | Input4 1 | Output281 2 3 45 6 7 89 10 11 1213 14 15 16 | 2 seconds | 256 megabytes | ['constructive algorithms', 'implementation', '*1300'] |
B. War of the Corporationstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it... | Inputintellecttell | Output1 | 1 second | 256 megabytes | ['constructive algorithms', 'greedy', 'strings', '*1200'] |
A. Guest From the Pasttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputKolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir... | Input101198 | Output2 | 1 second | 256 megabytes | ['implementation', 'math', '*1700'] |
B. Making a Stringtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an alphabet consisting of n letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied: the i-th letter occurs in the string no... | Input32 5 5 | Output11 | 1 second | 256 megabytes | ['greedy', 'sortings', '*1100'] |
A. Save Luketime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLuke Skywalker got locked up in a rubbish shredder between two presses. R2D2 is already working on his rescue, but Luke needs to stay alive as long as possible. For simplicity we will assume that everything ... | Input2 6 2 2 | Output1.00000000000000000000 | 1 second | 256 megabytes | ['math', '*800'] |
E. Transforming Sequencetime limit per test7 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's define the transformation P of a sequence of integers a1, a2, ..., an as b1, b2, ..., bn, where bi = a1 | a2 | ... | ai for all i = 1, 2, ..., n, where | is the bitwise OR operation.Vasya ... | Input1 2 | Output3 | 7 seconds | 256 megabytes | ['combinatorics', 'dp', 'fft', 'math', '*3300'] |
D. Birthdaytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA MIPT student named Misha has a birthday today, and he decided to celebrate it in his country house in suburban Moscow. n friends came by, and after a typical party they decided to play blind man's buff.The... | Input250 50 | Output5.0000000000 | 2 seconds | 256 megabytes | ['greedy', 'math', 'probabilities', '*2700'] |
C. Electric Chargestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputProgrammer Sasha is a student at MIPT (Moscow Institute of Physics and Technology) and he needs to make a laboratory work to pass his finals.A laboratory unit is a plane with standard coordinate axes... | Input31 101 201 30 | Output0 | 2 seconds | 256 megabytes | ['binary search', 'dp', '*2900'] |
B. Array GCDtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given array ai of length n. You may consecutively apply two operations to this array: remove some subsegment (continuous subsequence) of length m < n and pay for it m·a coins; change some elements... | Input3 1 44 2 3 | Output1 | 3 seconds | 256 megabytes | ['dp', 'greedy', 'number theory', '*2300'] |
A. Graph and Stringtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day student Vasya was sitting on a lecture and mentioned a string s1s2... sn, consisting of letters "a", "b" and "c" that was written on his desk. As the lecture was boring, Vasya decided to comp... | Input2 11 2 | OutputYesaa | 2 seconds | 256 megabytes | ['constructive algorithms', 'graphs', '*1800'] |
F. The Sum of the k-th Powerstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are well-known formulas: , , . Also mathematicians found similar formulas for higher degrees.Find the value of the sum modulo 109 + 7 (so you should find the remainder after dividing... | Input4 1 | Output10 | 2 seconds | 256 megabytes | ['math', '*2600'] |
E. Ants in Leavestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTree is a connected graph without cycles. A leaf of a tree is any vertex connected with exactly one other vertex.You are given a tree with n vertices and a root in the vertex 1. There is an ant in each... | Input121 21 31 42 52 63 73 83 98 108 118 12 | Output6 | 2 seconds | 256 megabytes | ['dfs and similar', 'greedy', 'sortings', 'trees', '*2200'] |
D. Optimal Number Permutationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a.Let number i be in positions xi, yi (xi < yi) in the permuted array a. Let's define ... | Input2 | Output1 1 2 2 | 1 second | 256 megabytes | ['constructive algorithms', '*1900'] |
C. Not Equal on a Segmenttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given array a with n integers and m queries. The i-th query is given with three integers li, ri, xi.For the i-th query find any position pi (li ≤ pi ≤ ri) so that api ≠ xi.InputThe first... | Input6 41 2 1 1 3 51 4 12 6 23 4 13 4 2 | Output26-14 | 1 second | 256 megabytes | ['data structures', 'implementation', '*1700'] |
B. The Timetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given the current time in 24-hour format hh:mm. Find and print the time after a minutes.Note that you should find only the time after a minutes, see the examples to clarify the problem statement.You c... | Input23:5910 | Output00:09 | 1 second | 256 megabytes | ['implementation', '*900'] |
A. Infinite Sequencetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputConsider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 t... | Input3 | Output2 | 1 second | 256 megabytes | ['implementation', 'math', '*1000'] |
E. Wet Shark and Blockstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are b blocks of digits. Each one consisting of the same n digits, which are given to you in the input. Wet Shark must choose exactly one digit from each block and concatenate all of those d... | Input12 1 5 103 5 6 7 8 9 5 1 1 1 1 5 | Output3 | 2 seconds | 256 megabytes | ['dp', 'matrices', '*2000'] |
D. Rat Kwesh and Cheesetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWet Shark asked Rat Kwesh to generate three positive real numbers x, y and z, from 0.1 to 200.0, inclusive. Wet Krash wants to impress Wet Shark, so all generated numbers will have exactly one di... | Input1.1 3.4 2.5 | Outputz^y^x | 2 seconds | 256 megabytes | ['brute force', 'constructive algorithms', 'math', '*2400'] |
C. Wet Shark and Flowerstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n sharks who grow flowers for Wet Shark. They are all sitting around the table, such that sharks i and i + 1 are neighbours for all i from 1 to n - 1. Sharks n and 1 are neighbours too... | Input3 21 2420 421420420 420421 | Output4500.0 | 2 seconds | 256 megabytes | ['combinatorics', 'math', 'number theory', 'probabilities', '*1700'] |
B. Wet Shark and Bishopstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputToday, Wet Shark is given n bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from l... | Input51 11 53 35 15 5 | Output6 | 2 seconds | 256 megabytes | ['combinatorics', 'implementation', '*1300'] |
A. Wet Shark and Odd and Eventime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputToday, Wet Shark is given n integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet ... | Input31 2 3 | Output6 | 2 seconds | 256 megabytes | ['implementation', '*900'] |
F. Xors on Segmentstime limit per test10 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given an array with n integers ai and m queries. Each query is described by two integers (lj, rj).Let's define the function . The function is defined for only u ≤ v.For each query print the ... | Input6 31 2 3 4 5 61 62 53 4 | Output777 | 10 seconds | 512 megabytes | ['data structures', 'strings', 'trees', '*2800'] |
E. New Year Treetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe New Year holidays are over, but Resha doesn't want to throw away the New Year tree. He invited his best friends Kerim and Gural to help him to redecorate the New Year tree.The New Year tree is an un... | Input7 101 1 1 1 1 1 11 21 31 43 53 63 71 3 22 11 4 32 11 2 52 11 6 42 12 22 3 | Output234512 | 3 seconds | 256 megabytes | ['bitmasks', 'data structures', 'trees', '*2100'] |
D. Professor GukiZ and Two Arraystime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputProfessor GukiZ has two arrays of integers, a and b. Professor wants to make the sum of the elements in the array a sa as close as possible to the sum of the elements in the array b sb.... | Input55 4 3 2 141 1 1 1 | Output121 14 2 | 3 seconds | 256 megabytes | ['binary search', 'two pointers', '*2200'] |
C. Pearls in a Rowtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai.Let's call a sequence of consecutive pearls a segment. Let's ... | Input51 2 3 4 1 | Output11 5 | 2 seconds | 256 megabytes | ['greedy', '*1500'] |
B. Grandfather Dovlet’s calculatortime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOnce Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators (https://en.wikipedia.org/wiki/Seven-... | Input1 3 | Output12 | 1 second | 256 megabytes | ['implementation', '*1000'] |
A. Professor GukiZ's Robottime limit per test0.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputProfessor GukiZ makes a new robot. The robot are in the point with coordinates (x1, y1) and should go to the point (x2, y2). In a single step the robot can change any of its coordinates (may... | Input0 04 5 | Output5 | 0.5 seconds | 256 megabytes | ['implementation', 'math', '*800'] |
G. Combining Slimestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYour friend recently gave you some slimes for your birthday. You have a very large amount of slimes with value 1 and 2, and you decide to invent a game using these slimes.You initialize a row with n ... | Input2 500000000 | Output3.562500000000000 | 2 seconds | 256 megabytes | ['dp', 'math', 'matrices', 'probabilities', '*3300'] |
F. Double Knapsacktime limit per test2.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two multisets A and B. Each multiset has exactly n integers each between 1 and n inclusive. Multisets may contain multiple copies of the same number.You would like to find a nonempty s... | Input1010 10 10 10 10 10 10 10 10 1010 9 8 7 6 5 4 3 2 1 | Output1235 8 10 | 2.5 seconds | 256 megabytes | ['constructive algorithms', 'two pointers', '*3000'] |
E. Robot Armtime limit per test8 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRoger is a robot. He has an arm that is a series of n segments connected to each other. The endpoints of the i-th segment are initially located at points (i - 1, 0) and (i, 0). The endpoint at (i - 1, 0) is... | Input5 41 1 32 3 902 5 481 4 1 | Output8.0000000000 0.00000000005.0000000000 -3.00000000004.2568551745 -2.66913060644.2568551745 -3.6691306064 | 8 seconds | 256 megabytes | ['data structures', 'geometry', '*2500'] |
D. Hamiltonian Spanning Treetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA group of n cities is connected by a network of roads. There is an undirected road between every pair of cities, so there are roads in total. It takes exactly y seconds to traverse any sin... | Input5 2 31 21 33 45 3 | Output9 | 2 seconds | 256 megabytes | ['dfs and similar', 'dp', 'graph matchings', 'greedy', 'trees', '*2200'] |
C. Constellationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputCat Noku has obtained a map of the night sky. On this map, he found a constellation with n stars numbered from 1 to n. For each i, the i-th star is located at coordinates (xi, yi). No two stars are loca... | Input30 11 01 1 | Output1 2 3 | 2 seconds | 256 megabytes | ['geometry', 'implementation', '*1600'] |
B. Guess the Permutationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBob has a permutation of integers from 1 to n. Denote this permutation as p. The i-th element of p will be denoted as pi. For all pairs of distinct integers i, j between 1 and n, he wrote the nu... | Input20 11 0 | Output2 1 | 2 seconds | 256 megabytes | ['constructive algorithms', '*1100'] |
A. Slime Combiningtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYour friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1.You are going to play a game with these slimes. Initially, you put a single slime by itself in... | Input1 | Output1 | 2 seconds | 256 megabytes | ['implementation', '*800'] |
E. XOR and Favorite Numbertime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBob has a favorite number k and ai of length n. Now he asks you to answer m queries. Each query is given by a pair li and ri and asks you to count the number of pairs of integers i and j, such... | Input6 2 31 2 1 1 0 31 63 5 | Output70 | 4 seconds | 256 megabytes | ['data structures', '*2200'] |
D. Polylinetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self-touches, such that it passes through all these points. Also, the polyline must... | Input1 -11 11 2 | Output1 | 1 second | 256 megabytes | ['constructive algorithms', 'implementation', '*1700'] |
C. Watering Flowerstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA flowerbed has many flowers and two fountains.You can adjust the water pressure and set any values r1(r1 ≥ 0) and r2(r2 ≥ 0), giving the distances at which the water is spread from the first and sec... | Input2 -1 0 5 30 25 2 | Output6 | 2 seconds | 256 megabytes | ['implementation', '*1600'] |
B. Chocolatetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBob loves everything sweet. His favorite chocolate bar consists of pieces, each piece may contain a nut. Bob wants to break the bar of chocolate into multiple pieces so that each part would contain exactly o... | Input30 1 0 | Output1 | 1 second | 256 megabytes | ['combinatorics', '*1300'] |
A. Elephanttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAn elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point x(x > 0) of the coordinate line. In one step the elephant can ... | Input5 | Output1 | 1 second | 256 megabytes | ['math', '*800'] |
F. Expensive Stringstime limit per test6 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given n strings ti. Each string has cost ci.Let's define the function of string , where ps, i is the number of occurrences of s in ti, |s| is the length of the string s. Find the maximal val... | Input2aabb2 1 | Output4 | 6 seconds | 512 megabytes | ['string suffix structures', 'strings', '*2700'] |
E. Sum of Remainderstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputCalculate the value of the sum: n mod 1 + n mod 2 + n mod 3 + ... + n mod m. As the result can be very large, you should print the value modulo 109 + 7 (the remainder when divided by 109 + 7).The mo... | Input3 4 | Output4 | 2 seconds | 256 megabytes | ['implementation', 'math', 'number theory', '*2200'] |
D. Longest k-Good Segmenttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values.... | Input5 51 2 3 4 5 | Output1 5 | 1 second | 256 megabytes | ['binary search', 'data structures', 'two pointers', '*1600'] |
C. The Labyrinthtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a rectangular field of n × m cells. Each cell is either empty or impassable (contains an obstacle). Empty cells are marked with '.', impassable cells are marked with '*'. Let's call two emp... | Input3 3*.*.*.*.* | Output3.3.5.3.3 | 1 second | 256 megabytes | ['dfs and similar', '*1600'] |
B. Dinner with Emmatime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputJack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.Munhattan consists of... | Input3 44 1 3 52 2 2 25 4 5 1 | Output2 | 1 second | 256 megabytes | ['games', 'greedy', '*1000'] |
A. Comparing Two Long Integerstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two very long integers a, b (leading zeroes are allowed). You should check what number a or b is greater or determine that they are equal.The input size is very large so don'... | Input910 | Output< | 2 seconds | 256 megabytes | ['implementation', 'strings', '*900'] |
E. Hexagonstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAyrat is looking for the perfect code. He decided to start his search from an infinite field tiled by hexagons. For convenience the coordinate system is introduced, take a look at the picture to see how the c... | Input3 | Output-2 0 | 1 second | 256 megabytes | ['binary search', 'implementation', 'math', '*2100'] |
D. Multiplierstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAyrat has number n, represented as it's prime factorization pi of size m, i.e. n = p1·p2·...·pm. Ayrat got secret information that that the product of all divisors of n taken modulo 109 + 7 is the passwor... | Input22 3 | Output36 | 2 seconds | 256 megabytes | ['math', 'number theory', '*2000'] |
C. Running Tracktime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputA boy named Ayrat lives on planet AMI-1511. Each inhabitant of this planet has a talent. Specifically, Ayrat loves running, moreover, just running is not enough for him. He is dreaming of making running ... | Inputabccbaabc | Output23 11 3 | 1 second | 512 megabytes | ['dp', 'greedy', 'strings', 'trees', '*2000'] |
B. Longtail Hedgehogtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis Christmas Santa gave Masha a magic picture and a pencil. The picture consists of n points connected by m segments (they might cross in any way, that doesn't matter). No two segments connect the... | Input8 64 53 52 51 22 86 7 | Output9 | 3 seconds | 256 megabytes | ['dp', 'graphs', '*1600'] |
A. Bulbstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya wants to turn on Christmas lights consisting of m bulbs. Initially, all bulbs are turned off. There are n buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When... | Input3 42 1 43 1 3 11 2 | OutputYES | 1 second | 256 megabytes | ['implementation', '*800'] |
B. Gena's Codetime limit per test0.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIt's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go int... | Input35 10 1 | Output50 | 0.5 seconds | 256 megabytes | ['implementation', 'math', '*1400'] |
A. Link/Cut Treetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputProgrammer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the expose procedure.Unfortunately, Rostislav is unable... | Input1 10 2 | Output1 2 4 8 | 2 seconds | 256 megabytes | ['brute force', 'implementation', '*1500'] |
E. Puzzle Lovertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOleg Petrov loves crossword puzzles and every Thursday he buys his favorite magazine with crosswords and other word puzzles. In the last magazine Oleg found a curious puzzle, and the magazine promised a ... | Inputcodeedoccode | Output4 | 2 seconds | 256 megabytes | ['dp', 'hashing', 'strings', '*3200'] |
D. Kingdom and its Citiestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMeanwhile, the kingdom of K is getting ready for the marriage of the King's daughter. However, in order not to lose face in front of the relatives, the King should first finish reforms in his k... | Input41 32 34 342 1 23 2 3 43 1 2 44 1 2 3 4 | Output1-11-1 | 2 seconds | 256 megabytes | ['dfs and similar', 'divide and conquer', 'dp', 'graphs', 'sortings', 'trees', '*2800'] |
C. Necklacetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIvan wants to make a necklace as a present to his beloved girl. A necklace is a cyclic sequence of beads of different colors. Ivan says that necklace is beautiful relative to the cut point between two adjace... | Input34 2 1 | Output1abacaba | 2 seconds | 256 megabytes | ['constructive algorithms', 'math', '*2500'] |
B. Skillstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was introduced. Now, each player character has exactly n skills. Each skill is represente... | Input3 5 10 1 51 3 1 | Output122 5 2 | 2 seconds | 256 megabytes | ['binary search', 'brute force', 'dp', 'greedy', 'sortings', 'two pointers', '*1900'] |
A. Peter and Snow Blowertime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPeter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing mach... | Input3 0 00 1-1 21 2 | Output12.566370614359172464 | 2 seconds | 256 megabytes | ['binary search', 'geometry', 'ternary search', '*1900'] |
F. Simba on the Circletime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a circular array with n elements. The elements are numbered from some element with values from 1 to n in clockwise order. The i-th cell contains the value ai. The robot Simba is in ce... | Input9 10 1 2 2 2 1 0 1 1 | Output12+0-3-1+2+1+2+1+1+1 | 1 second | 256 megabytes | ['dp', '*2600'] |
E. Square Root of Permutationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA permutation of length n is an array containing each integer from 1 to n exactly once. For example, q = [4, 5, 1, 2, 3] is a permutation. For the permutation q the square of permutation is... | Input42 1 4 3 | Output3 4 2 1 | 2 seconds | 256 megabytes | ['combinatorics', 'constructive algorithms', 'dfs and similar', 'graphs', 'math', '*2200'] |
D. The Union of k-Segmentstime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given n segments on the coordinate axis Ox and the number k. The point is satisfied if it belongs to at least k segments. Find the smallest (by the number of segments) set of segments ... | Input3 20 5-3 23 8 | Output20 23 5 | 4 seconds | 256 megabytes | ['greedy', 'sortings', '*1800'] |
C. Replace To Make Regular Bracket Sequencetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket ... | Input[<}){} | Output2 | 1 second | 256 megabytes | ['data structures', 'expression parsing', 'math', '*1400'] |
B. HDD is Outdated Technologytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputHDD hard drives group data by sectors. All files are split to fragments and each of them are written in some sector of hard drive. Note the fragments can be written in sectors in arbitrary o... | Input33 1 2 | Output3 | 1 second | 256 megabytes | ['implementation', 'math', '*1200'] |
A. The Text Splittingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given the string s of length n and the numbers p, q. Split the string s to pieces of length p and q.For example, the string "Hello" for p = 2, q = 3 can be split to the two strings "Hel" and... | Input5 2 3Hello | Output2Hello | 1 second | 256 megabytes | ['brute force', 'implementation', 'strings', '*1300'] |
H. New Year and Forgotten Treetime limit per test7 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA tree is a connected undirected graph with n - 1 edges, where n denotes the number of vertices. Vertices are numbered 1 through n.Limak is a little polar bear. His bear family prepares a ... | Input12? ?? ?? ?? ???? ??? ??? ??? ?? ?? ?? ? | Output3 11 69 12 101 78 11 41 105 110 1112 1 | 7 seconds | 256 megabytes | ['constructive algorithms', 'flows', 'graphs', '*3200'] |
G. New Year and Caketime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLimak is a little polar bear. According to some old traditions, his bear family prepared a New Year cake. And Limak likes cakes.As you may know, a New Year cake is a strictly convex polygon with n v... | Input52 42 75 75 43 -2 | Output90 | 2 seconds | 256 megabytes | ['geometry', 'two pointers', '*2900'] |
F. New Year and Cleaningtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLimak is a little polar bear. His parents told him to clean a house before the New Year's Eve. Their house is a rectangular grid with h rows and w columns. Each cell is an empty square.He is a l... | Input1 10 2R | Output30 | 2 seconds | 256 megabytes | ['binary search', 'implementation', '*2500'] |
E. New Year and Three Musketeerstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputDo you know the story about the three musketeers? Anyway, you must help them now.Richelimakieu is a cardinal in the city of Bearis. He found three brave warriors and called them the thre... | Input510 20 301 1 1 1 50 | Output2 | 2 seconds | 256 megabytes | ['data structures', 'greedy', 'sortings', '*2400'] |
D. New Year and Ancient Prophecytime limit per test2.5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputLimak is a little polar bear. In the snow he found a scroll with the ancient prophecy. Limak doesn't know any ancient languages and thus is unable to understand the prophecy. But he kn... | Input6123434 | Output8 | 2.5 seconds | 512 megabytes | ['dp', 'hashing', 'strings', '*2000'] |
C. New Year and Dominotime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThey say "years are like dominoes, tumbling one after the other". But would a year fit into a grid? I don't think so.Limak is a little polar bear who loves to play. He has recently got a rectangul... | Input5 8....#..#.#......##.#....##..#.##........41 1 2 34 1 4 11 2 4 52 5 5 8 | Output401015 | 3 seconds | 256 megabytes | ['dp', 'implementation', '*1500'] |
B. New Year and Old Propertytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe year 2015 is almost over.Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the ... | Input5 10 | Output2 | 2 seconds | 256 megabytes | ['bitmasks', 'brute force', 'implementation', '*1300'] |
A. New Year and Daystime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputToday is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015.Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager... | Input4 of week | Output52 | 2 seconds | 256 megabytes | ['implementation', '*900'] |
E. Alphabet Permutationstime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputYou are given a string s of length n, consisting of first k lowercase English letters.We define a c-repeat of some string q as a string, consisting of c copies of the string q. For example, strin... | Input7 4 3abacaba1 3 5 b2 abc1 4 4 c2 cba | Output65 | 1 second | 512 megabytes | ['data structures', 'strings', '*2500'] |
D. Vika and Segmentstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVika has an infinite sheet of squared paper. Initially all squares are white. She introduced a two-dimensional coordinate system on this sheet and drew n black horizontal and vertical segments paral... | Input30 1 2 11 4 1 20 3 2 3 | Output8 | 2 seconds | 256 megabytes | ['constructive algorithms', 'data structures', 'geometry', 'two pointers', '*2300'] |
C. Harmony Analysistime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe semester is already ending, so Danil made an effort and decided to visit a lesson on harmony analysis to know how does the professor look like, at least. Danil was very bored on this lesson until... | Input2 | Output++**+*+*+++++**+ | 3 seconds | 256 megabytes | ['constructive algorithms', '*1800'] |
B. Vika and Squarestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVika has n jars with paints of distinct colors. All the jars are numbered from 1 to n and the i-th jar contains ai liters of paint of color i.Vika also has an infinitely long rectangular piece of pap... | Input52 4 2 3 3 | Output12 | 2 seconds | 256 megabytes | ['constructive algorithms', 'implementation', '*1300'] |
A. Pasha and Sticktime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPasha has a wooden stick of some positive integer length n. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these ... | Input6 | Output1 | 1 second | 256 megabytes | ['combinatorics', 'math', '*1000'] |
F. Frogs and mosquitoestime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThere are n frogs sitting on the coordinate axis Ox. For each frog two values xi, ti are known — the position and the initial length of the tongue of the i-th frog (it is guaranteed that all posi... | Input4 610 215 06 10 1110 101 16 015 1014 10012 2 | Output3 1141 101 11 2 | 2 seconds | 512 megabytes | ['data structures', 'greedy', '*2500'] |
E. Minimum spanning tree for each edgetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputConnected undirected weighted graph without self-loops and multiple edges is given. Graph contains n vertices and m edges.For each edge (u, v) find the minimal possible weight of t... | Input5 71 2 31 3 11 4 52 3 22 5 33 4 24 5 4 | Output98118889 | 2 seconds | 256 megabytes | ['data structures', 'dfs and similar', 'dsu', 'graphs', 'trees', '*2100'] |
D. Gadgets for dollars and poundstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputNura wants to buy k gadgets. She has only s burles for that. She can buy each gadget for dollars or for pounds. So each gadget is selling only for some type of currency. The type of cur... | Input5 4 2 21 2 3 2 13 2 1 2 31 12 11 22 2 | Output31 12 3 | 2 seconds | 256 megabytes | ['binary search', 'greedy', 'two pointers', '*2000'] |
C. Load Balancingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn the school computer room there are n servers which are responsible for processing several computing tasks. You know the number of scheduled tasks for each server: there are mi tasks assigned to the ... | Input21 6 | Output2 | 2 seconds | 256 megabytes | ['implementation', 'math', '*1500'] |
B. The Best Gifttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEmily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are n books on sale from one of m genres.In the booksh... | Input4 32 1 3 1 | Output5 | 2 seconds | 256 megabytes | ['constructive algorithms', 'implementation', '*1100'] |
A. USB Flash Drivestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSean is trying to save a large file to a USB flash drive. He has n USB flash drives with capacities equal to a1, a2, ..., an megabytes. The file size is equal to m megabytes. Find the minimum number ... | Input35213 | Output2 | 2 seconds | 256 megabytes | ['greedy', 'implementation', 'sortings', '*800'] |
B. Hamming Distance Sumtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputGenos needs your help. He was asked to solve the following programming problem by Saitama:The length of some string s is denoted |s|. The Hamming distance between two strings s and t of equal len... | Input0100111 | Output3 | 2 seconds | 256 megabytes | ['combinatorics', 'strings', '*1500'] |
A. Saitama Destroys Hoteltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSaitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top ... | Input3 72 13 85 2 | Output11 | 1 second | 256 megabytes | ['implementation', 'math', '*1000'] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.