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. Even Substringstime limit per test0.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string s=s_1s_2\dots s_n of length n, which only contains digits 1, 2, ..., 9.A substring s[l \dots r] of s is a string s_l s_{l + 1} s_{l + 2} \ldots s_r. A substring s[l \dots r] o... | 4
1234
| 6 | 0.5 seconds | 256 megabytes | ['implementation', 'strings', '*800'] |
B. Circustime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp is a head of a circus troupe. There are n — an even number — artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether the... | 4
0011
0101
| 1 4 | 1 second | 256 megabytes | ['brute force', 'greedy', 'math', 'strings', '*1800'] |
A. Sushi for Twotime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputArkady invited Anna for a dinner to a sushi restaurant. The restaurant is a bit unusual: it offers n pieces of sushi aligned in a row, and a customer has to choose a continuous subsegment of these sushi ... | 7
2 2 2 1 1 2 2
| 4 | 1 second | 256 megabytes | ['binary search', 'greedy', 'implementation', '*900'] |
F. Matches Are Not a Child's Play time limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputLena is playing with matches. The natural question arising in the head of any child playing with matches is whether it's possible to set a tree on fire with a matches, or not.Let's say... | 5 7
1 5
1 2
1 3
4 3
when 1
when 2
when 3
when 4
when 5
compare 2 3
compare 3 4
| 4 1 3 2 5 2 4 | 4 seconds | 512 megabytes | ['data structures', 'trees', '*3400'] |
E. Train Car Selectiontime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputVasya likes to travel by train, but doesn't like when the car he travels in is located in the tail of the train.Vasya gets on the train at the station. The train consists of n cars indexed from 1 ... | 1 8
1 1
3 1 1
3 1 1
2 1
2 1
3 1 1
2 1
3 1 5
| 1 0 1 1 1 2 3 0 3 0 1 3 5 0 1 4 | 2 seconds | 512 megabytes | ['data structures', 'greedy', '*2700'] |
D. Cooperative Gametime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputThis is an interactive problem.Misha likes to play cooperative games with incomplete information. Today he suggested ten his friends to play a cooperative game "Lake".Misha has already come up with a ... | 2 05 12346789
3 246789 135 0
3 246789 0 135
3 246789 0 135
2 135 0246789
1 0123456789
| next 0 5 next 0 1 3 next 2 3 0 1 4 5 6 7 8 9 next 9 8 7 6 5 4 3 2 1 0 next 0 1 3 5 next 1 3 5 done | 1 second | 512 megabytes | ['constructive algorithms', 'interactive', 'number theory', '*2400'] |
C. Museums Tourtime limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputIn the country N, there are n cities connected by m one-way roads. Although this country seems unremarkable, there are two interesting facts about it. At first, a week lasts d days here. At second, there... | 4 5 3
3 1
1 2
2 4
4 1
2 3
011
110
111
001
| 3 | 4 seconds | 512 megabytes | ['dp', 'graphs', 'implementation', '*2500'] |
B. Camp Scheduletime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputThe new camp by widely-known over the country Spring Programming Camp is going to start soon. Hence, all the team of friendly curators and teachers started composing the camp's schedule. After some conti... | 101101
110
| 110110 | 1 second | 512 megabytes | ['greedy', 'hashing', 'strings', '*1600'] |
A. Skyscraperstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputDora loves adventures quite a lot. During some journey she encountered an amazing city, which is formed by n streets along the Eastern direction and m streets across the Southern direction. Naturally, thi... | 2 3
1 2 1
2 1 2
| 2 2 2 2 2 2 | 2 seconds | 512 megabytes | ['implementation', 'sortings', '*1600'] |
E. Nastya Hasn't Written a Legendtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn this task, Nastya asked us to write a formal statement.An array a of length n and an array k of length n-1 are given. Two types of queries should be processed: increase a_i by x. T... | 3
1 2 3
1 -1
5
s 2 3
+ 1 2
s 1 2
+ 3 1
s 2 3
| 5 7 8 | 2 seconds | 256 megabytes | ['binary search', 'data structures', '*2200'] |
D. Nastya Is Buying Lunchtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAt the big break Nastya came to the school dining room. There are n pupils in the school, numbered from 1 to n. Unfortunately, Nastya came pretty late, so that all pupils had already stood in t... | Input2 11 21 2 | Output1 | 2 seconds | 256 megabytes | ['greedy', '*1800'] |
C. Nastya Is Transposing Matricestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputNastya came to her informatics lesson, and her teacher who is, by the way, a little bit famous here gave her the following task.Two matrices A and B are given, each of them has size n \t... | 2 2
1 1
6 1
1 6
1 1
| YES | 1 second | 256 megabytes | ['constructive algorithms', 'sortings', '*1500'] |
B. Nastya Is Playing Computer Gamestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputFinished her homework, Nastya decided to play computer games. Passing levels one by one, Nastya eventually faced a problem. Her mission is to leave a room, where a lot of monsters live... | 2 2
| 6 | 1 second | 256 megabytes | ['constructive algorithms', 'math', '*1000'] |
A. Nastya Is Reading a Booktime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter lessons Nastya decided to read a book. The book contains n chapters, going one after another, so that one page of the book belongs to exactly one chapter and each chapter contains at lea... | 3
1 3
4 7
8 11
2
| 3 | 1 second | 256 megabytes | ['implementation', '*800'] |
F2. Spanning Tree with One Fixed Degreetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an undirected unweighted connected graph consisting of n vertices and m edges. It is guaranteed that there are no self-loops or multiple edges in the given graph.You... | 4 5 1
1 2
1 3
1 4
2 3
3 4
| YES 2 1 2 3 3 4 | 3 seconds | 256 megabytes | ['constructive algorithms', 'dfs and similar', 'dsu', 'graphs', 'greedy', '*1900'] |
F1. Spanning Tree with Maximum Degreetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an undirected unweighted connected graph consisting of n vertices and m edges. It is guaranteed that there are no self-loops or multiple edges in the given graph.Your ... | 5 5
1 2
2 3
3 5
4 3
1 5
| 3 5 2 1 3 2 3 4 | 3 seconds | 256 megabytes | ['graphs', '*1600'] |
E. K Balanced Teamstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are a coach at your local university. There are n students under your supervision, the programming skill of the i-th student is a_i.You have to form k teams for yet another new programming compet... | 5 2
1 2 15 15 15
| 5 | 3 seconds | 256 megabytes | ['dp', 'sortings', 'two pointers', '*1800'] |
D. Zero Quantity Maximizationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given two arrays a and b, each contains n integers.You want to create a new array c as follows: choose some real (i.e. not necessarily integer) number d, and then for every i \in [1... | 5
1 2 3 4 5
2 4 7 11 3
| 2 | 2 seconds | 256 megabytes | ['hashing', 'math', 'number theory', '*1500'] |
C. Balanced Teamtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are a coach at your local university. There are n students under your supervision, the programming skill of the i-th student is a_i.You have to create a team for a new programming competition. As yo... | 6
1 10 17 12 15 2
| 3 | 2 seconds | 256 megabytes | ['sortings', 'two pointers', '*1200'] |
B. Preparation for International Women's Daytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputInternational Women's Day is coming soon! Polycarp is preparing for the holiday.There are n candy boxes in the shop for sale. The i-th box contains d_i candies.Polycarp wants... | 7 2
1 2 2 3 2 4 10
| 6 | 2 seconds | 256 megabytes | ['math', 'number theory', '*1200'] |
A. Middle of the Contesttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp is going to participate in the contest. It starts at h_1:m_1 and ends at h_2:m_2. It is guaranteed that the contest lasts an even number of minutes (i.e. m_1 \% 2 = m_2 \% 2, where x \% ... | 10:00
11:00
| 10:30 | 1 second | 256 megabytes | ['implementation', '*1000'] |
G. Greedy Subsequencestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFor some array c, let's denote a greedy subsequence as a sequence of indices p_1, p_2, ..., p_l such that 1 \le p_1 < p_2 < \dots < p_l \le |c|, and for each i \in [1, l - 1], p_{i + 1} is the min... | 6 4
1 5 2 5 3 6
| 2 2 3 | 2 seconds | 256 megabytes | ['data structures', 'dp', 'trees', '*2400'] |
F. Clear the Stringtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string s of length n consisting of lowercase Latin letters. You may apply some operations to this string: in one operation you can delete some contiguous substring of this string, if ... | 5
abaca
| 3 | 3 seconds | 256 megabytes | ['dp', '*2000'] |
E. Knapsacktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a set of items, each having some integer weight not greater than 8. You denote that a subset of items is good if total weight of items in the subset does not exceed W.You want to calculate the maxim... | 10
1 2 3 4 5 6 7 8
| 10 | 2 seconds | 256 megabytes | ['dfs and similar', 'dp', 'greedy', '*2300'] |
D. Stressful Trainingtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputBerland SU holds yet another training contest for its students today. n students came, each of them brought his laptop. However, it turned out that everyone has forgot their chargers!Let students b... | 2 4
3 2
4 2
| 5 | 3 seconds | 256 megabytes | ['binary search', 'greedy', '*2300'] |
C. Painting the Fencetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a long fence which consists of n sections. Unfortunately, it is not painted, so you decided to hire q painters to paint it. i-th painter will paint all sections x such that l_i \le x \le r... | 7 5
1 4
4 5
5 6
6 7
3 5
| 7 | 2 seconds | 256 megabytes | ['brute force', '*1700'] |
B. Discountstime limit per test2.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou came to a local shop and want to buy some chocolate bars. There are n bars in the shop, i-th of them costs a_i coins (and you want to buy all of them).You have m different coupons that allow you to bu... | 7
7 1 3 1 4 10 8
2
3 4
| 27 30 | 2.5 seconds | 256 megabytes | ['greedy', 'sortings', '*900'] |
A. Regular Bracket Sequencetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA string is called bracket sequence if it does not contain any characters other than "(" and ")". A bracket sequence is called regular if it it is possible to obtain correct arithmetic express... | 3
1
4
3
| 1 | 1 second | 256 megabytes | ['greedy', 'implementation', '*1100'] |
G. Most Dangerous Sharktime limit per test2 secondsmemory limit per test768 megabytesinputstandard inputoutputstandard outputSemyon participates in the most prestigious competition of the world ocean for the title of the most dangerous shark. During this competition sharks compete in different subjects: speed swimming,... | 2 7
3
1 2 2
1 2 1
1
3
2
3
2 2
1 3
1 1
| 5 | 2 seconds | 768 megabytes | ['data structures', 'dp', 'two pointers', '*2700'] |
F. Asya And Kittenstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAsya loves animals very much. Recently, she purchased n kittens, enumerated them from 1 and n and then put them into the cage. The cage consists of one row of n cells, enumerated with integers from 1... | 5
1 4
2 5
3 1
4 5
| 3 1 4 2 5 | 2 seconds | 256 megabytes | ['constructive algorithms', 'dsu', '*1700'] |
E. String Multiplicationtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRoman and Denis are on the trip to the programming competition. Since the trip was long, they soon got bored, and hence decided to came up with something. Roman invented a pizza's recipe, while ... | 3
a
b
a
| 3 | 2 seconds | 256 megabytes | ['dp', 'greedy', 'strings', '*2300'] |
D. Gourmet choicetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his ow... | 3 4
>>>>
>>>>
>>>>
| Yes 2 2 2 1 1 1 1 | 2 seconds | 256 megabytes | ['dfs and similar', 'dp', 'dsu', 'graphs', 'greedy', '*2000'] |
C. Birthdaytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputCowboy Vlad has a birthday today! There are n children who came to the celebration. In order to greet Vlad, the children decided to form a circle around him. Among the children who came, there are both tall a... | 5
2 1 1 3 2
| 1 2 3 2 1 | 1 second | 256 megabytes | ['binary search', 'greedy', 'sortings', '*1200'] |
B. Draw!time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou still have partial information about the score during the historic football match. You are given a set of pairs (a_i, b_i), indicating that at some point during the match the score was "a_i: b_i". It is kno... | Input32 03 13 4 | Output2 | 2 seconds | 256 megabytes | ['greedy', 'implementation', '*1400'] |
A. Sea Battletime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn order to make the "Sea Battle" game more interesting, Boris decided to add a new ship type to it. The ship consists of two rectangles. The first rectangle has a width of w_1 and a height of h_1, while th... | 2 1 2 1
| 12 | 1 second | 256 megabytes | ['math', '*800'] |
C. Connecttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice lives on a flat planet that can be modeled as a square grid of size n \times n, with rows and columns enumerated from 1 to n. We represent the cell at the intersection of row r and column c with ordered ... | 5
1 1
5 5
00001
11111
00111
00110
00110
| 10 | 1 second | 256 megabytes | ['brute force', 'dfs and similar', 'dsu', '*1400'] |
B. Two Cakestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSasha and Dima want to buy two n-tier cakes. Each cake should consist of n different tiers: from the size of 1 to the size of n. Tiers should go in order from the smallest to the biggest (from top to bottom)... | 3
1 1 2 2 3 3
| 9 | 1 second | 256 megabytes | ['greedy', '*1200'] |
A. Be Positivetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array of n integers: a_1, a_2, \ldots, a_n. Your task is to find some non-zero integer d (-10^3 \leq d \leq 10^3) such that, after each number in the array is divided by d, the number of p... | Input510 0 -7 2 6 | Output4 | 1 second | 256 megabytes | ['implementation', '*800'] |
E. Legendary Treetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem.A legendary tree rests deep in the forest. Legend has it that individuals who realize this tree would eternally become a Legendary Grandmaster.To help you determine the t... | Input55 | Output31 2 324 52ANSWER1 22 33 42 5 | 3 seconds | 256 megabytes | ['binary search', 'interactive', 'trees', '*3100'] |
D. Isolationtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFind the number of ways to divide an array a of n integers into any number of disjoint non-empty segments so that, in each segment, there exist at most k distinct integers that appear exactly once.Since the... | 3 1
1 1 2
| 3 | 3 seconds | 256 megabytes | ['data structures', 'dp', '*2900'] |
C. Morse Codetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIn Morse code, an letter of English alphabet is represented as a string of some length from 1 to 4. Moreover, each Morse code representation of an English letter contains only dots and dashes. In this task... | Input3111 | Output137 | 2 seconds | 256 megabytes | ['binary search', 'data structures', 'dp', 'hashing', 'sortings', 'string suffix structures', 'strings', '*2400'] |
B. Wrong Answertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputConsider the following problem: given an array a containing n integers (indexed from 0 to n-1), find \max\limits_{0 \leq l \leq r \leq n-1} \sum\limits_{l \leq i \leq r} (r-l+1) \cdot a_i. In this problem... | 8
| 4 6 -8 7 -42 | 1 second | 256 megabytes | ['constructive algorithms', '*2000'] |
A2. Toy Traintime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice received a set of Toy Train™ from Bob. It consists of one train and a connected railway network of n stations, enumerated from 1 through n. The train occupies one station at a time and travels around... | 5 7
2 4
5 1
2 3
3 4
4 1
5 3
3 5
| 10 9 10 10 9 | 2 seconds | 256 megabytes | ['brute force', 'greedy', '*1800'] |
A1. Toy Train (Simplified)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is a simplified version of the task Toy Train. These two versions differ only in the constraints. Hacks for this version are disabled.Alice received a set of Toy Train™ from Bob. It consi... | 5 7
2 4
5 1
2 3
3 4
4 1
5 3
3 5
| 10 9 10 10 9 | 2 seconds | 256 megabytes | ['brute force', 'greedy', '*1700'] |
C. System Testingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya likes taking part in Codeforces contests. When a round is over, Vasya follows all submissions in the system testing tab.There are n solutions, the i-th of them should be tested on a_i tests, testi... | 2 2
49 100
| 1 | 1 second | 256 megabytes | ['implementation', '*1600'] |
B. Mike and Childrentime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMike decided to teach programming to children in an elementary school. He knows that it is not an easy task to interest children in that age to code. That is why he decided to give each child two sw... | 8
1 8 3 11 4 9 2 7
| 3 | 2 seconds | 256 megabytes | ['brute force', 'implementation', '*1200'] |
A. Technogoblet of Firetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputEverybody knows that the m-coder Tournament will happen soon. m schools participate in the tournament, and only one student from each school participates.There are a total of n students in those s... | 7 3 1
1 5 3 4 6 7 2
1 3 1 2 1 2 3
3
| 1 | 1 second | 256 megabytes | ['implementation', 'sortings', '*1100'] |
F. Secret Letterstime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputLittle W and Little P decided to send letters to each other regarding the most important events during a day. There are n events during a day: at time moment t_i something happens to the person p_i (p_... | 5 1 4
0 P
1 W
3 P
5 P
8 P
10
| 16 | 2 seconds | 512 megabytes | ['data structures', 'dp', 'greedy', '*3100'] |
E. The very same Munchhausentime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputA positive integer a is given. Baron Munchausen claims that he knows such a positive integer n that if one multiplies n by a, the sum of its digits decreases a times. In other words, S(an) = ... | 2
| 6 | 1 second | 256 megabytes | ['brute force', '*2600'] |
D. Power Treetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a rooted tree with n vertices, the root of the tree is the vertex 1. Each vertex has some non-negative price. A leaf of the tree is a non-root vertex that has degree 1.Arkady and Vasily play ... | 5
5 1 3 2 1
1 2
2 3
2 4
1 5
| 4 3 2 4 5 | 2 seconds | 256 megabytes | ['dfs and similar', 'dp', 'dsu', 'graphs', 'greedy', 'trees', '*2500'] |
C. Compress Stringtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSuppose you are given a string s of length n consisting of lowercase English letters. You need to compress it using the smallest possible number of coins.To compress the string, you have to represent ... | 3 3 1
aba
| 7 | 3 seconds | 256 megabytes | ['dp', 'strings', '*2100'] |
B. Once in a casinotime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne player came to a casino and found a slot machine where everything depends only on how he plays. The rules follow.A positive integer a is initially on the screen. The player can put a coin into the... | 3
223
322
| 2 1 1 2 -1 | 1 second | 256 megabytes | ['constructive algorithms', 'greedy', 'implementation', 'math', '*2700'] |
A. Diana and Lianatime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAt the first holiday in spring, the town Shortriver traditionally conducts a flower festival. Townsfolk wear traditional wreaths during these festivals. Each wreath contains exactly k flowers.The work... | 7 3 2 2
1 2 3 3 2 1 2
2 2
| 1 4 | 2 seconds | 256 megabytes | ['greedy', 'implementation', 'two pointers', '*1900'] |
H. Tripletime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have received your birthday gifts — n triples of integers! The i-th of them is \lbrace a_{i}, b_{i}, c_{i} \rbrace. All numbers are greater than or equal to 0, and strictly smaller than 2^{k}, where k is... | 1 1
1 2 3
1 0 1
| 2 4 | 1.5 seconds | 256 megabytes | ['fft', 'math', '*3200'] |
G. Get Ready for the Battletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecently Evlampy installed one interesting computer game, one of aspects of which is to split army into several groups and then fight with enemy's groups. Let us consider a simplified version... | 13 7
6 4 3 7 2 1 5
| 3 0 1 2 3 1 2 4 2 6 2 4 4 2 4 3 1 7 1 7 7 1 3 1 5 3 7 5 1 | 2 seconds | 256 megabytes | ['constructive algorithms', 'implementation', '*3100'] |
F. Niyaz and Small Degreestime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputNiyaz has a tree with n vertices numerated from 1 to n. A tree is a connected graph without cycles.Each edge in this tree has strictly positive integer weight. A degree of a vertex is the numb... | 5
1 2 1
1 3 2
1 4 3
1 5 4
| 10 6 3 1 0 | 3 seconds | 256 megabytes | ['data structures', 'dp', 'trees', '*3400'] |
E. Pavel and Trianglestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputPavel has several sticks with lengths equal to powers of two.He has a_0 sticks of length 2^0 = 1, a_1 sticks of length 2^1 = 2, ..., a_{n-1} sticks of length 2^{n-1}. Pavel wants to make the maxim... | 5
1 2 2 2 2
| 3 | 2 seconds | 256 megabytes | ['brute force', 'dp', 'fft', 'greedy', 'ternary search', '*1900'] |
D. Frets On Firetime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMiyako came to the flea kingdom with a ukulele. She became good friends with local flea residents and played beautiful music for them every day.In return, the fleas made a bigger ukulele for her: it h... | Input63 1 4 1 5 937 70 28 17 | Output5 10 18 | 1.5 seconds | 256 megabytes | ['binary search', 'sortings', '*1800'] |
C. Ramesses and Corner Inversiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputRamesses came to university to algorithms practice, and his professor, who is a fairly known programmer, gave him the following task.You are given two matrices A and B of size n \times m,... | 3 3
0 1 0
0 1 0
1 0 0
1 0 0
1 0 0
1 0 0
| Yes | 1 second | 256 megabytes | ['constructive algorithms', 'greedy', 'implementation', 'math', '*1500'] |
B. Alyona and a Narrow Fridgetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlyona has recently bought a miniature fridge that can be represented as a matrix with h rows and 2 columns. Initially there is only one shelf at the bottom of the fridge, but Alyona can ins... | 5 7
2 3 5 4 1
| 3 | 1 second | 256 megabytes | ['binary search', 'flows', 'greedy', 'sortings', '*1300'] |
A. Ilya and a Colorful Walktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIlya lives in a beautiful city of Chordalsk.There are n houses on the street Ilya lives, they are numerated from 1 to n from left to right; the distance between every two neighboring houses i... | 5
1 2 3 2 3
| 4 | 2 seconds | 256 megabytes | ['greedy', 'implementation', '*1100'] |
F2. Tree Cutting (Hard Version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an undirected tree of n vertices. Some vertices are colored one of the k colors, some are uncolored. It is guaranteed that the tree contains at least one vertex of each of t... | 5 2
2 0 0 1 2
1 2
2 3
2 4
2 5
| 1 | 2 seconds | 256 megabytes | ['combinatorics', 'dfs and similar', 'dp', 'trees', '*2700'] |
F1. Tree Cutting (Easy Version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an undirected tree of n vertices. Some vertices are colored blue, some are colored red and some are uncolored. It is guaranteed that the tree contains at least one red verte... | 5
2 0 0 1 2
1 2
2 3
2 4
2 5
| 1 | 2 seconds | 256 megabytes | ['dfs and similar', 'trees', '*1800'] |
E. Yet Another Ball Problemtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe king of Berland organizes a ball! n pair are invited to the ball, they are numbered from 1 to n. Each pair consists of one man and one woman. Each dancer (either man or woman) has a monoc... | 4 3
| YES 3 1 1 3 3 2 2 3 | 3 seconds | 256 megabytes | ['constructive algorithms', 'implementation', '*1700'] |
D2. Coffee and Coursework (Hard Version)time limit per test2.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is the constraints.Polycarp has to write a coursework. The coursework consists of m pages.Polycarp also has n cups of coffee.... | 5 8
2 3 1 1 2
| 4 | 2.5 seconds | 256 megabytes | ['binary search', 'greedy', '*1700'] |
D1. Coffee and Coursework (Easy version)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is the constraints.Polycarp has to write a coursework. The coursework consists of m pages.Polycarp also has n cups of coffee. Th... | 5 8
2 3 1 1 2
| 4 | 1 second | 256 megabytes | ['brute force', 'greedy', '*1700'] |
C. Palindromic Matrixtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's call some square matrix with integer values in its cells palindromic if it doesn't change after the order of rows is reversed and it doesn't change after the order of columns is reversed.For ... | 4
1 8 8 1 2 2 2 2 2 2 2 2 1 8 8 1
| YES 1 2 2 1 8 2 2 8 8 2 2 8 1 2 2 1 | 2 seconds | 256 megabytes | ['constructive algorithms', 'implementation', '*1700'] |
B. Tanya and Candiestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputTanya has n candies numbered from 1 to n. The i-th candy has the weight a_i.She plans to eat exactly n-1 candies and give the remaining candy to her dad. Tanya eats candies in order of increasing the... | 7
5 5 4 5 5 5 6
| 2 | 1 second | 256 megabytes | ['implementation', '*1200'] |
A. Water Buyingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp wants to cook a soup. To do it, he needs to buy exactly n liters of water.There are only two types of water bottles in the nearby shop — 1-liter bottles and 2-liter bottles. There are infinitely ... | 4
10 1 3
7 3 2
1 1000 1
1000000000000 42 88
| 10 9 1000 42000000000000 | 1 second | 256 megabytes | ['math', '*800'] |
G. Recursive Queriestime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a permutation p_1, p_2, \dots, p_n. You should answer q queries. Each query is a pair (l_i, r_i), and you should calculate f(l_i, r_i).Let's denote m_{l, r} as the position of the maxi... | 4 5
3 1 4 2
2 1 1 2 1
2 3 4 4 1
| 1 6 8 5 1 | 4 seconds | 256 megabytes | ['data structures', '*2500'] |
F. Crisp Stringtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a string of length n. Each character is one of the first p lowercase Latin letters.You are also given a matrix A with binary values of size p \times p. This matrix is symmetric (A_{ij} = A_... | 7 3
abacaba
0 1 1
1 0 0
1 0 0
| 7 | 2 seconds | 256 megabytes | ['bitmasks', 'dp', '*2500'] |
E. Decypher the Stringtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem. Remember to flush your output while communicating with the testing program. You may use fflush(stdout) in C++, system.out.flush() in Java, stdout.flush() in Python ... | yzx
aab
baa
aba | ? baa ? aba ? aab ! xyz | 2 seconds | 256 megabytes | ['bitmasks', 'chinese remainder theorem', 'constructive algorithms', 'interactive', 'math', '*2200'] |
D. Magic Gemstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputReziba has many magic gems. Each magic gem can be split into M normal gems. The amount of space each magic (and normal) gem takes is 1 unit. A normal gem cannot be split.Reziba wants to choose a set of mag... | 4 2
| 5 | 3 seconds | 256 megabytes | ['dp', 'math', 'matrices', '*2100'] |
C. Magic Shiptime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou a captain of a ship. Initially you are standing in a point (x_1, y_1) (obviously, all positions in the sea can be described by cartesian plane) and you want to travel to a point (x_2, y_2). You know th... | 0 0
4 6
3
UUU
| 5 | 2 seconds | 256 megabytes | ['binary search', '*1900'] |
B. Emotestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n emotes in very popular digital collectible card game (the game is pretty famous so we won't say its name). The i-th emote increases the opponent's happiness by a_i units (we all know that emotes in ... | 6 9 2
1 3 3 7 4 2
| 54 | 1 second | 256 megabytes | ['greedy', 'math', 'sortings', '*1000'] |
A. Best Subsegmenttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given array a_1, a_2, \dots, a_n. Find the subsegment a_l, a_{l+1}, \dots, a_r (1 \le l \le r \le n) with maximum arithmetic mean \frac{1}{r - l + 1}\sum\limits_{i=l}^{r}{a_i} (in floating-poin... | 5
6 1 6 6 0
| 2 | 1 second | 256 megabytes | ['implementation', 'math', '*1100'] |
F. Please, another Queries on Array?time limit per test5.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a_1, a_2, \ldots, a_n.You need to perform q queries of the following two types: "MULTIPLY l r x" — for every i (l \le i \le r) multiply a_i by x. "TOTIENT l... | Input4 45 9 1 2TOTIENT 3 3TOTIENT 3 4MULTIPLY 4 4 3TOTIENT 4 4 | Output112 | 5.5 seconds | 256 megabytes | ['bitmasks', 'data structures', 'divide and conquer', 'math', 'number theory', '*2400'] |
E. Arithmetic Progressiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is an interactive problem!An arithmetic progression or arithmetic sequence is a sequence of integers such that the subtraction of element with its previous element (x_i - x_{i - 1}, where ... | 4
0
1
14
24
9
19
| > 25 > 15 ? 1 ? 2 ? 3 ? 4 ! 9 5 | 2 seconds | 256 megabytes | ['binary search', 'interactive', 'number theory', 'probabilities', '*2200'] |
D. Flood Filltime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a line of n colored squares in a row, numbered from 1 to n from left to right. The i-th square initially has the color c_i.Let's say, that two squares i and j belong to the same connected com... | 4
5 2 2 1
| 2 | 2 seconds | 256 megabytes | ['dp', '*1900'] |
C. Trailing Loves (or L'oeufs?)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output The number "zero" is called "love" (or "l'oeuf" to be precise, literally means "egg" in French), for example when denoting the zero score in a game of tennis. Aki is fond of numbers, esp... | Input6 9 | Output1 | 2 seconds | 256 megabytes | ['brute force', 'implementation', 'math', 'number theory', '*1700'] |
B. Yet Another Array Partitioning Tasktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAn array b is called to be a subarray of a if it forms a continuous subsequence of a, that is, if it is equal to a_l, a_{l + 1}, \ldots, a_r for some l, r.Suppose m is some known c... | 9 2 3
5 2 5 2 4 1 1 3 2
| 21 3 5 | 2 seconds | 256 megabytes | ['constructive algorithms', 'greedy', 'sortings', '*1500'] |
A. Got Any Grapes?time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Duck songFor simplicity, we'll assume that there are only three types of grapes: green grapes, purple grapes and black grapes.Andrew, Dmitry and Michal are all grapes' lovers, however their prefere... | Input1 6 24 3 3 | OutputYES | 1 second | 256 megabytes | ['brute force', 'greedy', 'implementation', '*800'] |
B. Sasha and Magnetic Machinestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne day Sasha visited the farmer 2D and his famous magnetic farm. On this farm, the crop grows due to the influence of a special magnetic field. Maintaining of the magnetic field is provide... | 5
1 2 3 4 5
| 14 | 1 second | 256 megabytes | ['greedy', 'number theory', '*1300'] |
A. Sasha and His Triptime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputSasha is a very happy guy, that's why he is always on the move. There are n cities in the country where Sasha lives. They are all located on one straight line, and for convenience, they are numbered... | 4 2
| 4 | 1 second | 256 megabytes | ['dp', 'greedy', 'math', '*900'] |
E. Treetime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a tree with n nodes and q queries.Every query starts with three integers k, m and r, followed by k nodes of the tree a_1, a_2, \ldots, a_k. To answer a query, assume that the tree is rooted at r.... | 7 2
5 4
2 6
5 3
1 2
7 5
4 6
3 3 2 7 4 3
3 1 4 6 2 1
| 2 0 | 1.5 seconds | 256 megabytes | ['data structures', 'dfs and similar', 'dp', 'graphs', 'trees', '*2500'] |
D. Destroy the Colonytime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThere is a colony of villains with several holes aligned in a row, where each hole contains exactly one villain.Each colony arrangement can be expressed as a string of even length, where the i-th c... | abba
2
1 4
1 2
| 2 0 | 2 seconds | 512 megabytes | ['combinatorics', 'dp', 'math', '*2600'] |
C. Creative Snaptime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.Let we represent their base with an array, where each position can be occupied by many avengers, but ... | 2 2 1 2
1 3
| 6 | 1 second | 256 megabytes | ['binary search', 'brute force', 'divide and conquer', 'math', '*1700'] |
B. Average Superhero Gang Power time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputEvery superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operat... | 2 4 6
4 7
| 11.00000000000000000000 | 1 second | 256 megabytes | ['brute force', 'implementation', 'math', '*1700'] |
A. Superhero Transformationtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputWe all know that a superhero can transform to certain other superheroes. But not all Superheroes can transform to any other superhero. A superhero with name s can transform to another superher... | a
u
| Yes | 1 second | 256 megabytes | ['implementation', 'strings', '*1000'] |
H. Modest Substringstime limit per test5 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputYou are given two integers l and r.Let's call an integer x modest, if l \le x \le r.Find a string of length n, consisting of digits, which has the largest possible number of substrings, which make ... | 1
10
3
| 3 101 | 5 seconds | 1024 megabytes | ['dp', 'strings', '*3500'] |
G. Tree-Tac-Toe time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe tic-tac-toe game is starting on a tree of n vertices. Some vertices are already colored in white while the remaining are uncolored.There are two players — white and black. The players make moves alt... | 2
4
1 2
1 3
1 4
NNNW
5
1 2
2 3
3 4
4 5
NNNNN
| White Draw | 3 seconds | 256 megabytes | ['constructive algorithms', 'games', 'trees', '*3100'] |
F. Nearest Leaftime limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputLet's define the Eulerian traversal of a tree (a connected undirected graph without cycles) as follows: consider a depth-first search algorithm which traverses vertices of the tree and enumerates them in... | 5 3
1 10
1 1
3 2
3 3
1 1 5
5 4 5
4 1 2
| 3 0 13 | 4 seconds | 512 megabytes | ['data structures', 'trees', '*2600'] |
E. Magic Stonestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGrigory has n magic stones, conveniently numbered from 1 to n. The charge of the i-th stone is equal to c_i.Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index i, whe... | 4
7 2 4 12
7 15 10 12
| Yes | 1 second | 256 megabytes | ['constructive algorithms', 'math', 'sortings', '*2200'] |
D. Jongmahtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are playing a game of Jongmah. You don't need to know the rules to solve this problem. You have n tiles in your hand. Each tile has an integer between 1 and m written on it.To win the game, you will need ... | Input10 62 3 3 3 4 4 4 5 5 6 | Output3 | 3 seconds | 256 megabytes | ['dp', '*2200'] |
C. Meaningless Operationstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputCan the greatest common divisor and bitwise operations have anything in common? It is time to answer this question.Suppose you are given a positive integer a. You want to choose some integer b f... | 3
2
3
5
| 3 1 7 | 1 second | 256 megabytes | ['constructive algorithms', 'math', 'number theory', '*1500'] |
B. Tapetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a long stick, consisting of m segments enumerated from 1 to m. Each segment is 1 centimeter long. Sadly, some segments are broken and need to be repaired.You have an infinitely long repair tape. You want... | Input4 100 220 30 75 80 | Output17 | 1 second | 256 megabytes | ['greedy', 'sortings', '*1400'] |
A. Paritytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an integer n (n \ge 0) represented with k digits in base (radix) b. So,n = a_1 \cdot b^{k-1} + a_2 \cdot b^{k-2} + \ldots a_{k-1} \cdot b + a_k.For example, if b=17, k=3 and a=[11, 15, 7] then n=1... | Input13 33 2 7 | Outputeven | 1 second | 256 megabytes | ['math', '*900'] |
F. Sasha and Algorithm of Silence's Soundstime limit per test1.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne fine day Sasha went to the park for a walk. In the park, he saw that his favorite bench is occupied, and he had to sit down on the neighboring one. He sat down and began ... | Input1 51 2 3 4 5 | Output15 | 1.5 seconds | 256 megabytes | ['data structures', 'trees', '*3200'] |
E. Sasha and a Very Easy Testtime limit per test2.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputEgor likes math, and not so long ago he got the highest degree of recognition in the math community — Egor became a red mathematician. In this regard, Sasha decided to congratulate Egor a... | 5 100
4 1 2 3 5
5
3 1 5
1 2 3 6
3 1 2
1 1 5 1
3 2 4
| 15 10 21 | 2.5 seconds | 256 megabytes | ['data structures', 'number theory', '*2700'] |
D. Sasha and Interesting Fact from Graph Theorytime limit per test2.5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOnce, during a lesson, Sasha got bored and decided to talk with his friends. Suddenly, he saw Kefa. Since we can talk endlessly about Kefa, we won't even start doing tha... | 3 2 1 3
| 5 | 2.5 seconds | 256 megabytes | ['brute force', 'combinatorics', 'dp', 'math', 'trees', '*2400'] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.