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 |
|---|---|---|---|---|---|
G. Another Meme Problemtime limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputLet's call a fraction \frac{x}{y} good if there exists at least one another fraction \frac{x'}{y'} such that \frac{x}{y} = \frac{x'}{y'}, 1 \le x', y' \le 9, the digit denoting x' is contained in... | 42
| 150 | 4 seconds | 512 megabytes | ['dp', '*2700'] |
F. Crossword Experttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputToday Adilbek is taking his probability theory test. Unfortunately, when Adilbek arrived at the university, there had already been a long queue of students wanting to take the same test. Adilbek has ... | 3 5
2 2 2
| 750000007 | 2 seconds | 256 megabytes | ['combinatorics', 'dp', 'number theory', 'probabilities', 'two pointers', '*2400'] |
E. Count The Rectanglestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n segments drawn on a plane; the i-th segment connects two points (x_{i, 1}, y_{i, 1}) and (x_{i, 2}, y_{i, 2}). Each segment is non-degenerate, and is either horizontal or vertical — f... | 7
-1 4 -1 -2
6 -1 -2 -1
-2 3 6 3
2 -2 2 4
4 -1 4 3
5 3 5 1
5 2 1 2
| 7 | 2 seconds | 256 megabytes | ['bitmasks', 'brute force', 'data structures', 'geometry', 'sortings', '*2200'] |
D. 1-2-K Gametime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice and Bob play a game. There is a paper strip which is divided into n + 1 cells numbered from left to right starting from 0. There is a chip placed in the n-th cell (the last one).Players take turns, A... | Input40 33 33 44 4 | OutputBobAliceBobAlice | 2 seconds | 256 megabytes | ['games', 'math', '*1700'] |
C. From S To Ttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given three strings s, t and p consisting of lowercase Latin letters. You may perform any number (possibly, zero) operations on these strings.During each operation you choose any character from p, ... | 4
ab
acxb
cax
a
aaaa
aaabbcc
a
aaaa
aabbcc
ab
baaa
aaaaa
| YES YES NO NO | 1 second | 256 megabytes | ['implementation', 'strings', '*1300'] |
B. Yet Another Crosses Problemtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a picture consisting of n rows and m columns. Rows are numbered from 1 to n from the top to the bottom, columns are numbered from 1 to m from the left to the right. Each cell... | 9
5 5
..*..
..*..
*****
..*..
..*..
3 4
****
.*..
.*..
4 3
***
*..
*..
*..
5 5
*****
*.*.*
*****
..*.*
..***
1 4
****
5 5
.....
..*..
.***.
..*..
.....
5 3
...
.*.
.*.
***
.*.
3 3
.*.
*.*
.*.
4 4
*.**
....
*.**
*.**
| 0 0 0 0 0 4 1 1 2 | 2 seconds | 256 megabytes | ['implementation', '*1300'] |
A. Remove a Progressiontime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a list of numbers from 1 to n written from left to right on the blackboard.You perform an algorithm consisting of several steps (steps are 1-indexed). On the i-th step you wipe the i-th ... | 3
3 1
4 2
69 6
| 2 4 12 | 2 seconds | 256 megabytes | ['math', '*800'] |
C. Scissors and Tapetime limit per test1 secondmemory limit per test1024 megabytesinputstandard inputoutputstandard outputYou are given a piece of paper in the shape of a simple polygon S. Your task is to turn it into a simple polygon T that has the same area as S.You can use two tools: scissors and tape. Scissors can ... | 6 0 0 6 0 6 4 5 4 5 9 0 9
4 0 0 7 0 7 7 0 7
| scissors 0 5 3 0 0 3 0 3 4 3 3 4 0 4 0 0 3 3 0 6 0 6 4 3 6 4 3 4 3 0 4 0 4 5 4 5 9 0 9 tape 5 1 2 5 3 4 3 0 3 0 0 4 0 3 4 0 7 0 7 4 4 0 3 4 0 7 4 3 7 3 7 4 7 7 3 7 3 3 7 0 7 0 3 4 0 0 7 0 7 7 0 7 | 1 second | 1024 megabytes | ['*special problem', 'constructive algorithms', 'geometry'] |
B. Magic Treetime limit per test2 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputWe have a magic tree: a rooted tree on n vertices. The vertices are numbered 1 through n. Vertex 1 is the root.The magic tree gives us magic fruit. The fruit only grows in vertices of the tree other than ... | 6 4 10
1
2
1
4
4
3 4 5
4 7 2
5 4 1
6 9 3
| 9 | 2 seconds | 1024 megabytes | ['*special problem', 'data structures', 'dp', 'trees'] |
A. Amusement Parktime limit per test3 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputYou have been hired to supervise the project of a new amusement park. The park will have a special gimmick: directed slides that can get customers from one attraction to another quickly and in an ente... | 2 1
1 2
| 1 | 3 seconds | 1024 megabytes | ['*special problem', 'dp', 'math'] |
C. Cubewordtime limit per test1.7 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputA cubeword is a special type of a crossword. When building a cubeword, you start by choosing a positive integer a: the side length of the cube. Then, you build a big cube consisting of a \times a \times a... | 1
radar
| 1 | 1.7 seconds | 1024 megabytes | ['*special problem', 'brute force', 'dp', 'meet-in-the-middle'] |
B. Dynamic Diametertime limit per test6 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputYou are given a weighted undirected tree on n vertices and a list of q updates. Each update changes the weight of one edge. The task is to output the diameter of the tree after each update.(The dist... | 4 3 2000
1 2 100
2 3 1000
2 4 1000
2 1030
1 1020
1 890
| 2030 2080 2050 | 6 seconds | 1024 megabytes | ['*special problem', 'data structures', 'dfs and similar', 'divide and conquer', 'trees'] |
A. Building Skyscraperstime limit per test3.5 secondsmemory limit per test1024 megabytesinputstandard inputoutputstandard outputWe are going to build a new city: the Metropolis. The city is going to be built on an infinite square grid. The finished city will consist of n skyscrapers, each occupying a different cell of ... | 3
2
0 0
0 1
0 2
| YES 1 2 3 | 3.5 seconds | 1024 megabytes | ['*special problem'] |
B. Tokitsukaze and Mahjongtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputTokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or sou... | 1s 2s 3s
| 0 | 1 second | 256 megabytes | ['brute force', 'implementation', '*1200'] |
A. Tokitsukaze and Enhancementtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputTokitsukaze is one of the characters in the game "Kantai Collection". In this game, every character has a common attribute — health points, shortened to HP.In general, different values of H... | 33
| 0 A | 1 second | 256 megabytes | ['brute force', '*800'] |
F. Tokitsukaze and Powerstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTokitsukaze is playing a room escape game designed by SkywalkerT. In this game, she needs to find out hidden clues in the room to reveal a way to escape.After a while, she realizes that the onl... | 1 2 1
| -1 | 3 seconds | 256 megabytes | ['number theory', 'probabilities', '*3400'] |
E. Tokitsukaze and Explosiontime limit per test6 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputTokitsukaze and her friends are trying to infiltrate a secret base built by Claris. However, Claris has been aware of that and set a bomb which is going to explode in a minute. Although they... | 3 1
2 0
0 2
-1 0
| 0.0000000000 | 6 seconds | 256 megabytes | ['binary search', 'greedy', '*3100'] |
D. Tokitsukaze and Strange Rectangletime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n points on the plane, the i-th of which is at (x_i, y_i). Tokitsukaze wants to draw a strange rectangular area and pick all the points in the area.The strange area is encl... | Input31 11 21 3 | Output3 | 3 seconds | 256 megabytes | ['data structures', 'divide and conquer', 'sortings', 'two pointers', '*2000'] |
C. Tokitsukaze and Dueltime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output"Duel!"Betting on the lovely princess Claris, the duel between Tokitsukaze and Quailty has started.There are n cards in a row. Each card has two sides, one of which has color. At first, some of th... | 4 2
0101
| quailty | 1 second | 256 megabytes | ['brute force', 'games', 'greedy', '*2300'] |
B. Tokitsukaze, CSL and Stone Gametime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputTokitsukaze and CSL are playing a little game of stones.In the beginning, there are n piles of stones, the i-th pile of which has a_i stones. The two players take turns making moves. To... | 1
0
| cslnb | 1 second | 256 megabytes | ['games', '*1800'] |
A. Tokitsukaze and Discard Itemstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecently, Tokitsukaze found an interesting game. Tokitsukaze had n items at the beginning of this game. However, she thought there were too many items, so now she wants to discard m (1 \l... | 10 4 5
3 5 7 10
| 3 | 1 second | 256 megabytes | ['implementation', 'two pointers', '*1400'] |
C. Candies!time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputConsider a sequence of digits of length 2^k [a_1, a_2, \ldots, a_{2^k}]. We perform the following operation with it: replace pairs (a_{2i+1}, a_{2i+2}) with (a_{2i+1} + a_{2i+2})\bmod 10 for 0\le i<2^{k-1}. ... | 8
8 7 3 1 7 0 9 4
3
1 8
2 5
7 7
| 3 1 0 | 2 seconds | 256 megabytes | ['data structures', 'dp', 'implementation', 'math', '*1400'] |
B. Number Circletime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given n numbers a_1, a_2, \ldots, a_n. Is it possible to arrange them in a circle in such a way that every number is strictly less than the sum of its neighbors?For example, for the array [1, 4, ... | 3
2 4 3
| YES 4 2 3 | 1 second | 256 megabytes | ['greedy', 'math', 'sortings', '*1100'] |
A. Keanu Reevestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter playing Neo in the legendary "Matrix" trilogy, Keanu Reeves started doubting himself: maybe we really live in virtual reality? To find if this is true, he needs to solve the following problem.Let's ... | 1
1
| 1 1 | 1 second | 256 megabytes | ['strings', '*800'] |
E. Problem from Red Pandatime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAt Moscow Workshops ICPC team gets a balloon for each problem they solved first. Team MSU Red Panda got so many balloons that they didn't know how to spend them. So they came up with a problem w... | 3
0 1 2
| 3 | 1 second | 256 megabytes | ['combinatorics', '*3300'] |
D. Make Equaltime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given n numbers a_1, a_2, \dots, a_n. In one operation we can add to any one of those numbers a nonnegative integer power of 2.What is the smallest number of operations we need to perform to make a... | 4
228 228 228 228
| 0 | 4 seconds | 256 megabytes | ['dp', '*3100'] |
C. Array Beautytime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet's call beauty of an array b_1, b_2, \ldots, b_n (n > 1) — \min\limits_{1 \leq i < j \leq n} |b_i - b_j|.You're given an array a_1, a_2, \ldots a_n and a number k. Calculate the sum of beauty over al... | 4 3
1 7 3 5
| 8 | 5 seconds | 256 megabytes | ['dp', '*2500'] |
B. Count Pairstime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a prime number p, n integers a_1, a_2, \ldots, a_n, and an integer k. Find the number of pairs of indexes (i, j) (1 \le i < j \le n) for which (a_i + a_j)(a_i^2 + a_j^2) \equiv k \bmod p.Inp... | 3 3 0
0 1 2
| 1 | 4 seconds | 256 megabytes | ['math', 'matrices', 'number theory', 'two pointers', '*2300'] |
A2. Add on a Tree: Revolutiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputNote that this is the second problem of the two similar problems. You can hack this problem if you solve it. But you can hack the previous problem only if you solve both problems.You are giv... | 5
1 2 2
2 3 4
3 4 10
3 5 18
| NO | 1 second | 256 megabytes | ['constructive algorithms', 'dfs and similar', 'implementation', 'trees', '*2500'] |
A1. Add on a Treetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputNote that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems.You are given a tree with n nodes. In the beginning, 0 is written on all edges.... | 2
1 2
| YES | 1 second | 256 megabytes | ['trees', '*1600'] |
G. Gang Uptime limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThe leader of some very secretive organization has decided to invite all other members to a meeting. All members of the organization live in the same town which can be represented as n crossroads connected by... | 3 2 4 2 3
3 3 3 3
1 2
2 3
| 52 | 4 seconds | 512 megabytes | ['flows', 'graphs', '*2500'] |
F. Expected Square Beautytime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet x be an array of integers x = [x_1, x_2, \dots, x_n]. Let's define B(x) as a minimal size of a partition of x into subsegments such that all elements in each subsegment are equal. For examp... | 3
1 1 1
1 2 3
| 166666673 | 2 seconds | 256 megabytes | ['dp', 'math', 'probabilities', '*2500'] |
E. Tree Paintingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a tree (an undirected connected acyclic graph) consisting of n vertices. You are playing a game on this tree.Initially all vertices are white. On the first turn of the game you choose one ... | 9
1 2
2 3
2 5
2 6
1 4
4 9
9 7
9 8
| 36 | 2 seconds | 256 megabytes | ['dfs and similar', 'dp', 'trees', '*2100'] |
D. Subarray Sortingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given an array a_1, a_2, \dots, a_n and an array b_1, b_2, \dots, b_n.For one operation you can sort in non-decreasing order any subarray a[l \dots r] of the array a.For example, if a = [4, 2... | 4
7
1 7 1 4 4 5 6
1 1 4 4 5 7 6
5
1 1 3 3 5
1 1 3 3 5
2
1 1
1 2
3
1 2 3
3 2 1
| YES YES NO NO | 2 seconds | 256 megabytes | ['data structures', 'sortings', '*2400'] |
C. Vasya And Arraytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasya has an array a_1, a_2, \dots, a_n.You don't know this array, but he told you m facts about this array. The i-th fact is a triple of numbers t_i, l_i and r_i (0 \le t_i \le 1, 1 \le l_i < r_i \le ... | 7 4
1 1 3
1 2 5
0 5 6
1 6 7
| YES 1 2 2 3 5 4 4 | 1 second | 256 megabytes | ['constructive algorithms', 'greedy', 'implementation', '*1800'] |
B. Letters Shoptime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe letters shop showcase is a string s, consisting of n lowercase Latin letters. As the name tells, letters are sold in the shop.Letters are sold one by one from the leftmost to the rightmost. Any custo... | 9
arrayhead
5
arya
harry
ray
r
areahydra
| 5 6 5 2 9 | 2 seconds | 256 megabytes | ['binary search', 'implementation', 'strings', '*1300'] |
A. Stickers and Toystime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYour favorite shop sells n Kinder Surprise chocolate eggs. You know that exactly s stickers and exactly t toys are placed in n eggs in total.Each Kinder Surprise can be one of three types: it can c... | 3
10 5 7
10 10 10
2 1 1
| 6 1 2 | 2 seconds | 256 megabytes | ['math', '*900'] |
F. Vus the Cossack and a Graphtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVus the Cossack has a simple graph with n vertices and m edges. Let d_i be a degree of the i-th vertex. Recall that a degree of the i-th vertex is the number of conected edges to the i-th ... | 6 6
1 2
2 3
3 4
4 5
5 3
6 5
| 5 2 1 3 2 5 3 5 4 6 5 | 4 seconds | 256 megabytes | ['dfs and similar', 'graphs', 'greedy', 'implementation', '*2400'] |
E. Vus the Cossack and a Fieldtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVus the Cossack has a field with dimensions n \times m, which consists of "0" and "1". He is building an infinite field from this field. He is doing this in this way: He takes the current ... | 2 2 5
10
11
1 1 8 8
2 4 5 6
1 2 7 8
3 3 6 8
5 6 7 8
| 32 5 25 14 4 | 2 seconds | 256 megabytes | ['divide and conquer', 'implementation', 'math', '*2500'] |
D. Vus the Cossack and Numberstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVus the Cossack has n real numbers a_i. It is known that the sum of all numbers is equal to 0. He wants to choose a sequence b the size of which is n such that the sum of all numbers is 0 a... | 4
4.58413
1.22491
-2.10517
-3.70387
| 4 2 -2 -4 | 1 second | 256 megabytes | ['constructive algorithms', 'greedy', 'math', '*1500'] |
C. Vus the Cossack and Stringstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVus the Cossack has two binary strings, that is, strings that consist only of "0" and "1". We call these strings a and b. It is known that |b| \leq |a|, that is, the length of b is at most ... | 01100010
00110
| 3 | 1 second | 256 megabytes | ['implementation', 'math', '*1800'] |
A. Vus the Cossack and a Contesttime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVus the Cossack holds a programming competition, in which n people participate. He decided to award them all with pens and notebooks. It is known that Vus has exactly m pens and k noteboo... | 5 8 6
| Yes | 1 second | 256 megabytes | ['implementation', '*800'] |
G2. Playlist for Polycarp (hard version)time limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is constraints.Polycarp loves to listen to music, so he never leaves the player, even on the way home from the university. Poly... | 3 3
1 1
1 2
1 3
| 6 | 5 seconds | 256 megabytes | ['combinatorics', 'dp', '*2600'] |
G1. Playlist for Polycarp (easy version)time limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is constraints.Polycarp loves to listen to music, so he never leaves the player, even on the way home from the university. Poly... | 3 3
1 1
1 2
1 3
| 6 | 5 seconds | 256 megabytes | ['bitmasks', 'combinatorics', 'dp', '*2100'] |
F. Two Pizzastime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA company of n friends wants to order exactly two pizzas. It is known that in total there are 9 pizza ingredients in nature, which are denoted by integers from 1 to 9.Each of the n friends has one or more ... | 3 4
2 6 7
4 2 3 9 5
3 2 3 9
100 1 7
400 3 3 2 5
100 2 9 2
500 3 2 9 5
| 2 3 | 4 seconds | 256 megabytes | ['bitmasks', 'brute force', '*2100'] |
E. Polycarp and Snakestime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter a hard-working week Polycarp prefers to have fun. Polycarp's favorite entertainment is drawing snakes. He takes a rectangular checkered sheet of paper of size n \times m (where n is the numb... | 1
5 6
...a..
..bbb.
...a..
.cccc.
...a..
| YES 3 1 4 5 4 2 3 2 5 4 2 4 5 | 4 seconds | 256 megabytes | ['brute force', 'implementation', '*2000'] |
D. Extra Elementtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputA sequence a_1, a_2, \dots, a_k is called an arithmetic progression if for each i from 1 to k elements satisfy the condition a_i = a_1 + c \cdot (i - 1) for some fixed c.For example, these five sequence... | 5
2 6 8 7 4
| 4 | 2 seconds | 256 megabytes | ['implementation', 'math', '*1700'] |
C2. Exam in BerSU (hard version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is constraints.If you write a solution in Python, then prefer to send it in PyPy to speed up execution time.A session has begun at Bela... | 7 15
1 2 3 4 5 6 7
| 0 0 0 0 0 2 3 | 2 seconds | 256 megabytes | ['brute force', 'data structures', 'greedy', 'math', '*1700'] |
C1. Exam in BerSU (easy version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between easy and hard versions is constraints.A session has begun at Beland State University. Many students are taking exams.Polygraph Poligrafovich is going to exami... | 7 15
1 2 3 4 5 6 7
| 0 0 0 0 0 2 3 | 2 seconds | 256 megabytes | ['greedy', 'sortings', '*1200'] |
B. Email from Polycarptime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMethodius received an email from his friend Polycarp. However, Polycarp's keyboard is broken, so pressing a key on it once may cause the corresponding symbol to appear more than once (if you press... | 4
hello
hello
hello
helloo
hello
hlllloo
hello
helo
| YES YES NO NO | 3 seconds | 256 megabytes | ['implementation', 'strings', '*1200'] |
A. Ropewalkerstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp decided to relax on his weekend and visited to the performance of famous ropewalkers: Agafon, Boniface and Konrad.The rope is straight and infinite in both directions. At the beginning of the perf... | 5 2 6 3
| 2 | 1 second | 256 megabytes | ['math', '*800'] |
E3. Daleks' Invasion (hard)time limit per test10 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWith your help, Heidi has prepared a plan of trap placement and defence. Yet suddenly, the Doctor popped out of the TARDIS and told her that he had spied on the Daleks' preparations, and the... | Input3 31 2 82 3 33 1 4 | Output488 | 10 seconds | 256 megabytes | ['data structures', 'dsu', 'graphs', 'trees', '*2400'] |
E2. Daleks' Invasion (medium)time limit per test15 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter a successful field test, Heidi is considering deploying a trap along some Corridor, possibly not the first one. She wants to avoid meeting the Daleks inside the Time Vortex, so for a... | Input3 31 2 82 3 33 1 4 | Output4 | 15 seconds | 256 megabytes | ['dfs and similar', 'graphs', 'shortest paths', 'trees', '*2100'] |
E1. Daleks' Invasion (easy)time limit per test6 secondsmemory limit per test128 megabytesinputstandard inputoutputstandard outputHeidi found out that the Daleks have created a network of bidirectional Time Corridors connecting different destinations (at different times!). She suspects that they are planning another inv... | Input3 31 2 82 3 33 1 4 | Output4 | 6 seconds | 128 megabytes | ['graphs', 'trees', '*1900'] |
D2. Parallel Universes (Hard)time limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputHeidi enjoyed performing the simulation because she knew exactly when a new universe would be formed and where, and when a non-existent link would be broken and where.However, the multivers... | 2 1 2
| 2 | 4 seconds | 256 megabytes | ['math', 'matrices', '*3100'] |
D1. Parallel Universes (Easy)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Third Doctor Who once correctly said that travel between parallel universes is "like travelling sideways". However, he incorrectly thought that there were infinite parallel universes, wh... | 5 2 10 4
0 1
1 1
0 4
1 2
| 4 1 5 2 4 2 5 3 | 1 second | 256 megabytes | ['implementation', '*1600'] |
C2. Heidi and the Turing Test (Medium)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Cybermen solved that first test much quicker than the Daleks. Luckily for us, the Daleks were angry (shocking!) and they destroyed some of the Cybermen.After the fighting stopp... | 5 1
1 1
1 -1
-1 1
-1 -1
2 0
| 3 | 2 seconds | 256 megabytes | ['data structures', '*2200'] |
C1. Heidi and the Turing Test (Easy)time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe Cybermen and the Daleks have long been the Doctor's main enemies. Everyone knows that both these species enjoy destroying everything they encounter. However, a little-known fact ... | 2
0 0
0 1
0 2
1 0
1 1
1 2
2 0
2 1
2 2
| 1 1 | 3 seconds | 256 megabytes | ['implementation', '*1600'] |
B3. The Doctor Meets Vader (Hard)time limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThe rebels have saved enough gold to launch a full-scale attack. Now the situation is flipped, the rebels will send out the spaceships to attack the Empire bases!The galaxy can be repre... | 6 7
1 2
2 3
3 4
4 6
6 5
4 4
3 6
4 2 2
1 10 2 5
3 8 2 7
5 1 0 2
6 5 4 1
3 7 6
5 2 3
4 2
3 2
| 2 | 4 seconds | 512 megabytes | ['flows', 'shortest paths', '*2700'] |
B2. The Doctor Meets Vader (Medium)time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThanks to the Doctor's help, the rebels managed to steal enough gold to launch a full-scale attack on the Empire! However, Darth Vader is looking for revenge and wants to take back hi... | 6 7
1 2
2 3
3 4
4 6
6 5
4 4
3 6
4 2 7 3
1 10 2
3 8 2
5 1 0
6 5 4
3 7
5 2
| 12 | 3 seconds | 256 megabytes | ['flows', 'graph matchings', 'graphs', 'shortest paths', 'sortings', '*2200'] |
B1. The Doctor Meets Vader (Easy)time limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputHeidi and Doctor Who hopped out of the TARDIS and found themselves at EPFL in 2018. They were surrounded by stormtroopers and Darth Vader was approaching. Miraculously, they managed to ... | 5 4
1 3 5 2 4
0 1
4 2
2 8
9 4
| 1 9 11 9 11 | 4 seconds | 256 megabytes | ['binary search', 'sortings', '*1400'] |
A3. Heidi Learns Hashing (Hard)time limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputNow Heidi is ready to crack Madame Kovarian's hashing function.Madame Kovarian has a very strict set of rules for name changes. Two names can be interchanged only if using the following h... | 10 5
bgcbaaaaaa
cccaaaaaaa
| 5 2 | 5 seconds | 256 megabytes | ['fft', 'math', 'number theory', '*3100'] |
A2. Heidi Learns Hashing (Medium)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputAfter learning about polynomial hashing, Heidi decided to learn about shift-xor hashing. In particular, she came across this interesting problem.Given a bitstring y \in \{0,1\}^n find o... | 4
1010
| 3 | 2 seconds | 256 megabytes | ['brute force', 'number theory', '*2100'] |
A1. Heidi Learns Hashing (Easy)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputMelody Pond was stolen from her parents as a newborn baby by Madame Kovarian, to become a weapon of the Silence in their crusade against the Doctor. Madame Kovarian changed Melody's name t... | 19
| 1 8 | 1 second | 256 megabytes | ['brute force', 'math', 'number theory', '*1200'] |
H. Subsequences (hard version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between the easy and the hard versions is constraints.A subsequence is a string that can be derived from another string by deleting some or no symbols without changing ... | 4 5
asdf
| 4 | 2 seconds | 256 megabytes | ['dp', 'strings', '*1900'] |
G. Candy Box (hard version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem is a version of problem D from the same contest with some additional constraints and tasks.There are n candies in a candy box. The type of the i-th candy is a_i (1 \le a_i \le n)... | 3
8
1 0
4 1
2 0
4 1
5 1
6 1
3 0
2 0
4
1 1
1 1
2 1
2 1
9
2 0
2 0
4 1
4 1
4 1
7 0
7 1
7 0
7 1
| 3 3 3 3 9 5 | 2 seconds | 256 megabytes | ['greedy', 'implementation', 'sortings', '*2000'] |
F. Topforces Strikes Backtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputOne important contest will take place on the most famous programming platform (Topforces) very soon!The authors have a pool of n problems and should choose at most three of them into this conte... | 3
4
5 6 15 30
4
10 6 30 15
3
3 4 6
| 30 31 10 | 3 seconds | 256 megabytes | ['brute force', 'math', 'sortings', '*2100'] |
E. Subsequences (easy version)time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThe only difference between the easy and the hard versions is constraints.A subsequence is a string that can be derived from another string by deleting some or no symbols without changing ... | 4 5
asdf
| 4 | 2 seconds | 256 megabytes | ['dp', 'graphs', 'implementation', 'shortest paths', '*2000'] |
D. Candy Box (easy version)time limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis problem is actually a subproblem of problem G from the same contest.There are n candies in a candy box. The type of the i-th candy is a_i (1 \le a_i \le n).You have to prepare a gift usi... | 3
8
1 4 8 4 5 6 3 8
16
2 1 3 3 4 3 4 4 1 3 2 2 2 4 1 1
9
2 2 4 4 4 7 7 7 7
| 3 10 9 | 3 seconds | 256 megabytes | ['greedy', 'sortings', '*1400'] |
C. Computer Gametime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVova is playing a computer game. There are in total n turns in the game and Vova really wants to play all of them. The initial charge of his laptop battery (i.e. the charge before the start of the game)... | 6
15 5 3 2
15 5 4 3
15 5 2 1
15 5 5 1
16 7 5 2
20 5 7 3
| 4 -1 5 2 0 1 | 3 seconds | 256 megabytes | ['binary search', 'math', '*1400'] |
B. Equalize Pricestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThere are n products in the shop. The price of the i-th product is a_i. The owner of the shop wants to equalize the prices of all products. However, he wants to change prices smoothly.In fact, the owne... | 4
5 1
1 1 2 3 1
4 2
6 4 8 5
2 2
1 6
3 5
5 2 5
| 2 6 -1 7 | 1 second | 256 megabytes | ['math', '*900'] |
A. Nearest Interesting Numbertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPolycarp knows that if the sum of the digits of a number is divisible by 3, then the number itself is divisible by 3. He assumes that the numbers, the sum of the digits of which is divisible... | 432
| 435 | 1 second | 256 megabytes | ['implementation', '*800'] |
F. Maximum Sinetime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have given integers a, b, p, and q. Let f(x) = \text{abs}(\text{sin}(\frac{p}{q} \pi x)).Find minimum possible integer x that maximizes f(x) where a \le x \le b.InputEach test contains multiple test ... | 2
0 3 1 3
17 86 389 995
| 1 55 | 3 seconds | 256 megabytes | ['binary search', 'data structures', 'number theory', '*2700'] |
E. Product Oriented Recurrencetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputLet f_{x} = c^{2x-6} \cdot f_{x-1} \cdot f_{x-2} \cdot f_{x-3} for x \ge 4.You have given integers n, f_{1}, f_{2}, f_{3}, and c. Find f_{n} \bmod (10^{9}+7).InputThe only line contains fiv... | 5 1 2 5 3
| 72900 | 1 second | 256 megabytes | ['dp', 'math', 'matrices', 'number theory', '*2300'] |
D. Complete Mirrortime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have given tree consist of n vertices. Select a vertex as root vertex that satisfies the condition below. For all vertices v_{1} and v_{2}, if distance(root, v_{1}) = distance(root, v_{2}) then de... | 7
1 2
2 3
3 4
4 5
3 6
6 7
| 3 | 1 second | 256 megabytes | ['constructive algorithms', 'dfs and similar', 'dp', 'hashing', 'implementation', 'trees', '*2400'] |
C. Beautiful Lyricstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given n words, each of which consists of lowercase alphabet letters. Each word contains at least one vowel. You are going to choose some of the given words and make as many beautiful lyrics as... | 14
wow
this
is
the
first
mcdics
codeforces
round
hooray
i
am
proud
about
that
| 3 about proud hooray round wow first this is i that mcdics am | 1 second | 256 megabytes | ['data structures', 'greedy', 'strings', '*1700'] |
B. Plus from Picturetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a given picture with size w \times h. Determine if the given picture has a single "+" shape or not. A "+" shape is described below: A "+" shape has one center nonempty cell. There should b... | 5 6
......
..*...
.****.
..*...
..*...
| YES | 1 second | 256 megabytes | ['dfs and similar', 'implementation', 'strings', '*1300'] |
A. Filling Shapestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou have a given integer n. Find the number of ways to fill all 3 \times n tiles with the shape described in the picture below. Upon filling, no empty spaces are allowed. Shapes cannot overlap. This pi... | 4
| 4 | 1 second | 256 megabytes | ['dp', 'math', '*1000'] |
E2. A Story of One Country (Hard)time limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThis problem differs from the previous problem only in constraints.Petya decided to visit Byteland during the summer holidays. It turned out that the history of this country is quite un... | 4
0 0 1 2
0 2 1 3
1 0 2 1
1 1 2 3
| YES | 4 seconds | 512 megabytes | ['brute force', 'greedy', 'sortings', '*3000'] |
E1. A Story of One Country (Easy)time limit per test4 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputThis problem differs from the next problem only in constraints.Petya decided to visit Byteland during the summer holidays. It turned out that the history of this country is quite unusua... | 4
0 0 1 2
0 2 1 3
1 0 2 1
1 1 2 3
| YES | 4 seconds | 512 megabytes | ['brute force', 'divide and conquer', 'sortings', '*2500'] |
D. Irrigationtime limit per test2.5 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputMisha was interested in water delivery from childhood. That's why his mother sent him to the annual Innovative Olympiad in Irrigation (IOI). Pupils from all Berland compete there demonstrating their skil... | 6 4 10
3 1 1 1 2 2
7
8
9
10
11
12
13
14
15
16
| 4 3 4 2 3 4 1 2 3 4 | 2.5 seconds | 512 megabytes | ['binary search', 'data structures', 'implementation', 'sortings', 'trees', 'two pointers', '*2200'] |
C. Flagtime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputInnokenty works at a flea market and sells some random stuff rare items. Recently he found an old rectangular blanket. It turned out that the blanket is split in n \cdot m colored pieces that form a rectangle wi... | 4 3
aaa
bbb
ccb
ddd
| 6 | 2 seconds | 512 megabytes | ['brute force', 'combinatorics', 'dp', 'implementation', '*1900'] |
B. Split a Numbertime limit per test2 secondsmemory limit per test512 megabytesinputstandard inputoutputstandard outputDima worked all day and wrote down on a long paper strip his favorite number n consisting of l digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.To so... | 7
1234567
| 1801 | 2 seconds | 512 megabytes | ['greedy', 'implementation', 'strings', '*1500'] |
A. Chunga-Changatime limit per test1 secondmemory limit per test512 megabytesinputstandard inputoutputstandard outputSoon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhi... | 5 4 3
| 3 1 | 1 second | 512 megabytes | ['greedy', 'math', '*1000'] |
B. Nick and Arraytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputNick had received an awesome array of integers a=[a_1, a_2, \dots, a_n] as a gift for his 5 birthday from his mother. He was already going to explore its various properties but after unpacking he was di... | 4
2 2 2 2
| -3 -3 -3 -3 | 1 second | 256 megabytes | ['greedy', 'implementation', '*1500'] |
A. Alex and a Rhombustime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputWhile playing with geometric figures Alex has accidentally invented a concept of a n-th order rhombus in a cell grid.A 1-st order rhombus is just a square 1 \times 1 (i.e just a cell).A n-th order r... | 1
| 1 | 1 second | 256 megabytes | ['dp', 'implementation', 'math', '*800'] |
E. Alesya and Discrete Mathtime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputWe call a function good if its domain of definition is some set of integers and if in case it's defined in x and x-1, f(x) = f(x-1) + 1 or f(x) = f(x-1).Tanya has found n good functions f_{1}... | 5 5
? 1 0
? 1 1
? 2 1
? 2 2
? 3 2
? 3 3
? 4 3
? 4 4
? 5 4
? 5 5
!
0 1
1 2
2 3
3 4
4 5
| 0 1 1 2 2 3 3 4 4 4 5 | 5 seconds | 256 megabytes | ['divide and conquer', 'interactive', '*3200'] |
D. Fedor Runs for Presidenttime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputFedor runs for president of Byteland! In the debates, he will be asked how to solve Byteland's transport problem. It's a really hard problem because of Byteland's transport system is now a tr... | 2
1 2
| 2 | 2 seconds | 256 megabytes | ['data structures', 'dp', 'trees', '*2700'] |
C. Serge and Dining Roomtime limit per test4 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSerge came to the school dining room and discovered that there is a big queue here. There are m pupils in the queue. He's not sure now if he wants to wait until the queue will clear, so he wants... | 1 1
1
1
1
1 1 100
| 100 | 4 seconds | 256 megabytes | ['binary search', 'data structures', 'graph matchings', 'greedy', 'implementation', 'math', 'trees', '*2200'] |
B. Tolik and His Uncletime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet... | 2 3
| 1 1 1 3 1 2 2 2 2 3 2 1 | 1 second | 256 megabytes | ['constructive algorithms', '*1800'] |
A. Valeriy and Dequetime limit per test6 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecently, on the course of algorithms and data structures, Valeriy learned how to use a deque. He built a deque filled with n elements. The i-th element is a_i (i = 1, 2, \ldots, n). He gradually ta... | 5 3
1 2 3 4 5
1
2
10
| 1 2 2 3 5 2 | 6 seconds | 256 megabytes | ['data structures', 'implementation', '*1500'] |
H. Stock Exchangetime limit per test6 secondsmemory limit per test16 megabytesinputstandard inputoutputstandard outputWarning: This problem has an unusual memory limit!Bob decided that he will not waste his prime years implementing GUI forms for a large corporation and instead will earn his supper on the Stock Exchange... | 1
3 10
1 16
| 3 1 | 6 seconds | 16 megabytes | ['binary search', 'flows', 'graphs', '*3500'] |
G. The Awesomest Vertextime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given a rooted tree on n vertices. The vertices are numbered from 1 to n; the root is the vertex number 1.Each vertex has two integers associated with it: a_i and b_i. We denote the set o... | Input5 61 1 2 210 -3 -7 -3 -1010 3 9 3 62 12 21 2 62 11 2 52 1 | Output10091169240 | 5 seconds | 256 megabytes | ['data structures', 'dfs and similar', '*3000'] |
F2. Long Colorful Striptime limit per test6 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is the second subtask of problem F. The only differences between this and the first subtask are the constraints on the value of m and the time limit. It is sufficient to solve this subtask i... | 3 3
1 2 3
| 5 | 6 seconds | 256 megabytes | ['dp', '*2600'] |
F1. Short Colorful Striptime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputThis is the first subtask of problem F. The only differences between this and the second subtask are the constraints on the value of m and the time limit. You need to solve both subtasks in orde... | 3 3
1 2 3
| 5 | 3 seconds | 256 megabytes | ['combinatorics', 'dfs and similar', 'dp', '*2200'] |
E. Archaeologytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice bought a Congo Prime Video subscription and was watching a documentary on the archaeological findings from Factor's Island on Loch Katrine in Scotland. The archaeologists found a book whose age and o... | cacbac
| aba | 1 second | 256 megabytes | ['brute force', 'constructive algorithms', 'greedy', 'strings', '*1900'] |
D. Prime Graphtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputEvery person likes prime numbers. Alice is a person, thus she also shares the love for them. Bob wanted to give her an affectionate gift but couldn't think of anything inventive. Hence, he will be giving h... | 4
| 5 1 2 1 3 2 3 2 4 3 4 | 1 second | 256 megabytes | ['constructive algorithms', 'greedy', 'math', 'number theory', '*1500'] |
C. Tilestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputBob is decorating his kitchen, more precisely, the floor. He has found a prime candidate for the tiles he will use. They come in a simple form factor — a square tile that is diagonally split into white and black... | 2 2
| 16 | 1 second | 256 megabytes | ['combinatorics', 'greedy', 'math', '*1300'] |
B. WOW Factortime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputRecall that string a is a subsequence of a string b if a can be obtained from b by deletion of several (possibly zero or all) characters. For example, for the string a="wowwo", the following strings are sub... | vvvovvv
| 4 | 1 second | 256 megabytes | ['dp', 'strings', '*1300'] |
A. Prime Ministertime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice is the leader of the State Refactoring Party, and she is about to become the prime minister. The elections have just taken place. There are n parties, numbered from 1 to n. The i-th party has rece... | 3
100 50 50
| 2 1 2 | 1 second | 256 megabytes | ['greedy', '*800'] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.