contest_id stringlengths 1 4 | index stringclasses 43
values | title stringlengths 2 63 | statement stringlengths 51 4.24k | tutorial stringlengths 19 20.4k | tags listlengths 0 11 | rating int64 800 3.5k ⌀ | code stringlengths 46 29.6k ⌀ |
|---|---|---|---|---|---|---|---|
91 | E | Igloo Skyscraper | Today the North Pole hosts an Olympiad in a sport called... toy igloo skyscrapers' building!
There are $n$ walruses taking part in the contest. Each walrus is given a unique number from $1$ to $n$. After start each walrus begins to build his own igloo skyscraper. Initially, at the moment of time equal to $0$, the heig... | We are given the array where the value in each cell is described by the formula depends on T $val_{i} = a_{i} + b_{i} * T$ (in geometry mean it is a line equation). Lt's divide the array in blocks of size $d$ ~ $sqrt(n)$: $[0;d)$, $[d, d * 2)$, $[d * 2, d * 3)$, ..., $[d * k, n)$. Now let's precalculate for each block ... | [
"data structures",
"geometry"
] | 2,500 | null |
92 | A | Chips | There are $n$ walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number $2$ sits to the left of the walrus number $1$, the walrus number $3$ sits to the left of the walrus number $2$, ..., the walrus number $1$ sits to the left of the walrus number $n$.
The presenter has $m$ chip... | In these problems you should only realize what was written is the statement. | [
"implementation",
"math"
] | 800 | null |
92 | B | Binary Number | Little walrus Fangy loves math very much. That's why when he is bored he plays with a number performing some operations.
Fangy takes some positive integer $x$ and wants to get a number one from it. While $x$ is not equal to $1$, Fangy repeats the following action: if $x$ is odd, then he adds $1$ to it, otherwise he di... | In these problems you should only realize what was written is the statement. In problem B wasn't recommended to use BigInteger in Java because of slow speed. | [
"greedy"
] | 1,300 | null |
93 | A | Frames | Throughout Igor K.'s life he has had many situations worthy of attention. We remember the story with the virus, the story of his mathematical career and of course, his famous programming achievements. However, one does not always adopt new hobbies, one can quit something as well.
This time Igor K. got disappointed in ... | The problem is easy, but there were many tricky cases - and contestants show it successful :) I added almost all these cases to the pretests because I didn't want to arrange Beta Round 60. So let's solve the problem. At first notice that the answer is not greater than 3 because we always can do three selections (maybe,... | [
"implementation"
] | 1,700 | null |
93 | B | End of Exams | Students love to celebrate their holidays. Especially if the holiday is the day of the end of exams!
Despite the fact that Igor K., unlike his groupmates, failed to pass a programming test, he decided to invite them to go to a cafe so that each of them could drink a bottle of... fresh cow milk. Having entered the cafe... | Greedy algorithm solves this problem. We should consecutively try to pour milk from each bottle into each available cup and in maximal possible amount. Also we always need to know, how much milk is in each bottle and each cup, for each cup - bottles from which we have poured milk, and for each bottle - cups into which ... | [
"greedy"
] | 1,900 | null |
93 | C | Azembler | After the Search Ultimate program that searched for strings in a text failed, Igor K. got to think: "Why on Earth does my program work so slowly?" As he double-checked his code, he said: "My code contains no errors, yet I know how we will improve Search Ultimate!" and took a large book from the shelves. The book read "... | I don't know why so few coders have solved it. Small limitations for $n$ and big time limit - 5 seconds - hint that it's backtracking. Also, no need to be a soothsayer to understand that maximal answer is about 5. Solving it is clear. You should keep all current registers at the vector and call some function that goes ... | [
"brute force",
"implementation"
] | 2,500 | null |
93 | D | Flags | When Igor K. was a freshman, his professor strictly urged him, as well as all other freshmen, to solve programming Olympiads. One day a problem called "Flags" from a website called Timmy's Online Judge caught his attention. In the problem one had to find the number of three-colored flags that would satisfy the conditio... | I think my solution is not optimal, it's too long. Many solutions submitted during the contest are shorter. But I tell you about my solution. At first I solve the problem for the number of stripes equals $N$ (or $L = R$). Let $f\left(N\right)$ is the number of flags with exactly $N$ stripes where symmetrical flags are ... | [
"dp",
"math",
"matrices"
] | 2,500 | null |
93 | E | Lostborn | Igor K. very much likes a multiplayer role playing game WineAge II. Who knows, perhaps, that might be the reason for his poor performance at the university. As any person who plays the game, he is interested in equipping his hero with as good weapon and outfit as possible.
One day, as he was reading the game's forum y... | This problem can be solved using inclusion-exclusion principle. If $f_{a_{1}a_{2}...a_{k}}\left(n\right)$ is the answer, then the following formula works: $f_{a_{1}a_{2}...a_{k}}\left(n\right)=f_{a_{2}a_{3}...a_{k}}\left(n\right)-f_{a_{2}a_{3}...a_{k}}\left(\left|{\frac{n}{a_{1}}}\right|\right)$. But if you write only ... | [
"dp",
"math",
"number theory"
] | 2,600 | null |
94 | A | Restoring Password | Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had ... | Password was very easy to restore. You should just iterate over groups of 10 characters in the first string and over all codes. Then, if some number's code is equal to the group - print that number. | [
"implementation",
"strings"
] | 900 | null |
94 | B | Friends | One day Igor K. stopped programming and took up math. One late autumn evening he was sitting at a table reading a book and thinking about something.
The following statement caught his attention: "Among any six people there are either three pairwise acquainted people or three pairwise unacquainted people"
Igor just co... | Let's construct the graph where vertices correspond to the people and edges correspond to the relationships. Then paint each edge in this way: edge will be red if the men connected by it are friends and black otherwise. Now let's think what is "three pairwise acquainted people" and "three pairwise unacquainted people".... | [
"graphs",
"implementation",
"math"
] | 1,300 | null |
95 | A | Hockey | Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name $w$ and the collection of forbidden substrings $s_{1}, s_{2}, ..., s_{n}$. All those strings consist of uppercase and low... | Let B[i] = true, if character in position i is in some substring of W which is in dictionary. For each B[i] = true, do next: \cdot If S[i] = letter and letter = 'a', then S[i] = 'b', \cdot If S[i] = letter and letter != 'a' then S[i] = 'a'; \cdot If S[i] != letter, then S[i] = letter. | [
"implementation",
"strings"
] | 1,600 | null |
95 | B | Lucky Numbers | Petya loves lucky numbers. Everybody knows that positive integers are \underline{lucky} if their decimal representation doesn't contain digits other than $4$ and $7$. For example, numbers $47$, $744$, $4$ are lucky and $5$, $17$, $467$ are not.
Lucky number is \underline{super lucky} if it's decimal representation con... | Notice, that answer will looks like this: to some position result will be equal with input string (that part must be lucky), next digit well be greater, the rest of digits are not important. That guarantees us that result will be greater than or equal to N. As rightest this position will be as number will be lesser. So... | [
"dp",
"greedy"
] | 1,800 | null |
95 | C | Volleyball | Petya loves volleyball very much. One day he was running late for a volleyball match. Petya hasn't bought his own car yet, that's why he had to take a taxi. The city has $n$ junctions, some of which are connected by two-way roads. The length of each road is defined by some positive integer number of meters; the roads c... | At first in this simple problem you need to find shortest path between all pair of junctions. That can't be done using O(N^3) algorithms, so you must use Dijkstra algorithm to find this in O(N*N*logN) time. Next part of this problem is to create new matrix, G[i][j] = C[i], if D[i][j] <= R[i], else G[i][j] = INF. Here D... | [
"shortest paths"
] | 1,900 | null |
95 | D | Horse Races | Petya likes horse racing very much. Horses numbered from $l$ to $r$ take part in the races. Petya wants to evaluate the probability of victory; for some reason, to do that he needs to know the amount of nearly lucky horses' numbers. A \underline{nearly lucky} number is an integer number that has at least two lucky digi... | Traditionally I remain that answer is Result(0..R) - Result(0..L-1). Let we have array DP[x][y][z] - number of x-digits number if last lucky digit was on position y, bool z (0 or 1) - was the pair of lucky digits with less than or equal distance then K (call it lucky pair)? Now, let S - string which represent number N.... | [
"dp",
"math"
] | 2,500 | null |
95 | E | Lucky Country | Petya loves lucky numbers. Everybody knows that positive integers are \underline{lucky} if their decimal representation doesn't contain digits other than $4$ and $7$. For example, numbers $47$, $744$, $4$ are lucky and $5$, $17$, $467$ are not.
One night Petya was sleeping. He was dreaming of being the president of so... | Let A[i] - sorted array of sizes of different connection components, C[i] - number of connection components of size A[i]. Sum for all C[i]*A[i] is equal to N. Size of A will be O(sqrt(N)). Let all C[i] = (2^k)-1, i. e. C[i] = 1 + 2 + 4 + 8 + \dots + 2^(k-1). Obviously, that if chose some subset of this powers we can ... | [
"dp",
"dsu",
"graphs"
] | 2,500 | null |
96 | A | Football | Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If... | In this problem you must find longest substring consisting of equal characters and compare it with 7. | [
"implementation",
"strings"
] | 900 | null |
96 | B | Lucky Numbers (easy) | Petya loves lucky numbers. Everybody knows that positive integers are \underline{lucky} if their decimal representation doesn't contain digits other than $4$ and $7$. For example, numbers $47$, $744$, $4$ are lucky and $5$, $17$, $467$ are not.
Lucky number is \underline{super lucky} if it's decimal representation con... | If the length of input number |N| is odd, then, obviously, resulting number will have length |N|+1 and will be like this: 4444 \dots 7777, at first (|N|+1)/2 digits 4, then the same number of 7's. If the number has even length, then, probably, resulting number will have size |N|, or |N|+2. So, length of the resulting n... | [
"binary search",
"bitmasks",
"brute force"
] | 1,300 | null |
97 | A | Domino | Little Gennady was presented with a set of domino for his birthday. The set consists of $28$ different dominoes of size $2 × 1$. Both halves of each domino contain one digit from $0$ to $6$.
\begin{verbatim}
0-0 0-1 0-2 0-3 0-4 0-5 0-6
1-1 1-2 1-3 1-4 1-5 1-6
2-2 2-3 2-4 2-5 2-6
3-3 3-4 3-5 3-6
4-4 4-5 4-6
5-5 5-6
6-6... | We need to assign some number from 0 to 6 to each of the 14 squares. Note that if you take the solution and apply some permutation of digits to the field, you obtain another correct solution. So, the solution is characterized by division of 14 squares to pairs. If we have such a partition, then it is possible to genera... | [
"brute force",
"implementation"
] | 2,400 | null |
97 | D | Robot in Basement | The Professor has lost his home robot yet again. After some thinking Professor understood that he had left the robot in the basement.
The basement in Professor's house is represented by a rectangle $n × m$, split into $1 × 1$ squares. Some squares are walls which are impassable; other squares are passable. You can get... | A naive solution works in $O(nmk)$. This solution stores all the start positions into an array and next iterates over all commands and shifts positions in needed directions. After every move it checks that all positions lie on the exit cell. This solution doesn't fit into time limits. An author's solution speed up the ... | [
"bitmasks",
"brute force",
"implementation"
] | 2,700 | null |
98 | A | Help Victoria the Wise | Vasilisa the Wise from a far away kingdom got a present from her friend Helga the Wise from a farther away kingdom. The present is a surprise box, yet Vasilisa the Wise doesn't know yet what the surprise actually is because she cannot open the box. She hopes that you can help her in that.
The box's lock is constructed... | In this problem you were required to find the number of sufficiently different colorings of a cube faces with predefined six colors. The most trivial solution is to introduce some ordering of the cube faces (say, 0 - front, 1 - back, 2 - up, 3 - down, 4 - left, 5 - right), then consider 720 = 6! arrangements of colors ... | [
"brute force",
"implementation"
] | 1,700 | null |
98 | B | Help King | This is the modification of the problem used during the official round. Unfortunately, author's solution of the original problem appeared wrong, so the problem was changed specially for the archive.
Once upon a time in a far away kingdom lived the King. The King had a beautiful daughter, Victoria. They lived happily, ... | Unfortunately, initial author's solution for this problem appeared wrong. However, the optimality of the below algo was proved by Knuth and Yao in 1976. Limitation for n in the problem now changed to 10000. The process of tossing a coin and making decisions regarding which alternative to choose may be naturally describ... | [
"implementation",
"probabilities",
"trees"
] | 2,200 | null |
98 | C | Help Greg the Dwarf | A very unusual citizen lives in a far away kingdom — Dwarf Gracula. However, his unusual name is not the weirdest thing (besides, everyone long ago got used to calling him simply Dwarf Greg). What is special about Dwarf Greg — he's been living for over 200 years; besides, he lives in a crypt on an abandoned cemetery an... | For this problem I assumed numerical solution. But there are several cases to consider. Below without loss of generality we assume a <= b. 1. l <= a <= b. In this case the answer is restricted by the length of the coffin, so the answer is l and it is clear that the coffin l x l can be brought through the corridor (a, b... | [
"geometry",
"ternary search"
] | 2,500 | null |
98 | D | Help Monks | In a far away kingdom is the famous Lio Shan monastery. Gods constructed three diamond pillars on the monastery's lawn long ago. Gods also placed on one pillar $n$ golden disks of different diameters (in the order of the diameters' decreasing from the bottom to the top). Besides, gods commanded to carry all the disks f... | This problem was about famous puzzle "Hanoi towers", but diameters of some discs might be equal. How to solve that? A good thing to do is to write BFS solution to check optimality of your ideas for small inputs (by the way, BSF works quickly for almost all towers that have up to 10 discs) and then try to create an algo... | [
"constructive algorithms"
] | 2,500 | null |
98 | E | Help Shrek and Donkey | Shrek and the Donkey (as you can guess, they also live in the far away kingdom) decided to play a card game called YAGame. The rules are very simple: initially Shrek holds $m$ cards and the Donkey holds $n$ cards (the players do not see each other's cards), and one more card lies on the table face down so that both pla... | This problem was about optimally playing this simple-at-first-glance game. The key thing to recognize in the statement was that it is not always optimal to name card which you don't have. Sometimes it is optimal to confuse the opponent by naming card which you have on hand. In this case... yes, he may think that the ca... | [
"dp",
"games",
"math",
"probabilities"
] | 2,700 | null |
99 | A | Help Far Away Kingdom | In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there.
Most damage those strange creatures inflicted upon the kingdom was that they loved high precision numbers. As a result, the Ki... | Here the problem was to round a number up according to the usual mathematical rules with the exception that if the last digit of integer part is equal to 9, you should output "GOTO Vasilisa.". One may notice that to check whether number's fractional part is not less than 0.5 only one digit just after the decimal point ... | [
"strings"
] | 800 | null |
99 | B | Help Chef Gerasim | In a far away kingdom young pages help to set the table for the King. As they are terribly mischievous, one needs to keep an eye on the control whether they have set everything correctly. This time the royal chef Gerasim had the impression that the pages have played a prank again: they had poured the juice from one cup... | The problem was to accurately check what is required in the problem statement. First of all, check whether all volumes in the input are equal. In this case output "Exemplary pages.". Otherwise find two cups with largest and smallest volumes. Suppose their numbers are a and b, and their volumes are v[a] and v[b]. Now su... | [
"implementation",
"sortings"
] | 1,300 | null |
101 | A | Homework | Once when Gerald studied in the first year at school, his teacher gave the class the following homework. She offered the students a string consisting of $n$ small Latin letters; the task was to learn the way the letters that the string contains are written. However, as Gerald is too lazy, he has no desire whatsoever to... | Lets count up the number of entries to string of every letter. Let Gerald choose $x$ letter and lose them. Obvious thet if he lose $x$ rarest letters then overall number of losed letter do not increase, and then if he can lose some $x$ lettes, he can lose $x$ rarest ones. Thus it's easy to determine if Gerald can loses... | [
"greedy"
] | 1,200 | null |
101 | B | Buses | Little boy Gerald studies at school which is quite far from his house. That's why he has to go there by bus every day. The way from home to school is represented by a segment of a straight line; the segment contains exactly $n + 1$ bus stops. All of them are numbered with integers from $0$ to $n$ in the order in which ... | For every slop from $0$ to $n$ lets calculate $k_{x}$ - number of ways come to them. Consider the $i$-th bus. Number of ways come to stop $t_{i}$ applied $i$-th bus is uqual to number of way to embus to $i$-th bus. One can embus to $i$-th bus on the stops $s_{i}, s_{i} + 1, ..., t_{i} - 1$. Thus number of ways come to ... | [
"binary search",
"data structures",
"dp"
] | 1,700 | null |
101 | C | Vectors | At a geometry lesson Gerald was given a task: to get vector $B$ out of vector $A$. Besides, the teacher permitted him to perform the following operations with vector $А$:
- Turn the vector by $90$ degrees clockwise.
- Add to the vector a certain vector $C$.
Operations could be performed in any order any number of tim... | Lets formulate the problem in complex number. Consider complex numbers $a = x_{A} + iy_{A}$, $b = x_{B} + iy_{B}$ and $c = x_{C} + iy_{C}$. One can do operation $A \rightarrow A + C$ and $A \rightarrow iA$. If we apply this transform some times in some order to $A$, we will get number $A \cdot i^{k} + aC + biC - c... | [
"implementation",
"math"
] | 2,000 | null |
101 | D | Castle | Gerald is positioned in an old castle which consists of $n$ halls connected with $n - 1$ corridors. It is exactly one way to go from any hall to any other one. Thus, the graph is a tree. Initially, at the moment of time $0$, Gerald is positioned in hall $1$. Besides, some other hall of the castle contains the treasure ... | Remunerate vertexes in such a way, that start Gerald vertex have got number $0$. Consider that vertex $0$ is the root of tree, and lets consider its children. Let Gerald first go to vertex $x$. Then he must to travel throw hole subtree, otherwise he will not visit all vertex in subtree. Then he come back to $0$ and go ... | [
"dp",
"greedy",
"probabilities",
"sortings",
"trees"
] | 2,300 | null |
101 | E | Candies and Stones | Little Gerald and his coach Mike play an interesting game. At the beginning of the game there is a pile consisting of $n$ candies and a pile consisting of $m$ stones. Gerald and Mike move in turns, Mike goes first. During his move Mike checks how many candies and stones Gerald has eaten. Let Gerald eat $a$ candies and ... | Essence of problem is that there is a board $n \times m$ in cell of wich placed numbers. And one must go from cell $(0, 0)$ to cell $(n - 1, m - 1)$, doing moves to one cell up and right (that is, increasing by $1$ on of coordinates), maximizing sum o number on the cell in the path. Gerald's problems is determine $m ... | [
"divide and conquer",
"dp"
] | 2,500 | null |
102 | A | Clothes | A little boy Gerald entered a clothes shop and found out something very unpleasant: not all clothes turns out to match. For example, Gerald noticed that he looks rather ridiculous in a smoking suit and a baseball cap.
Overall the shop sells $n$ clothing items, and exactly $m$ pairs of clothing items match. Each item h... | In this problem constraints are allow to look throw all triples of clothes. For every triple one can check if all elements of tripe areturn out to match with others, and anong those triples find one whith minimal cost. | [
"brute force"
] | 1,200 | null |
102 | B | Sum of Digits | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number $n$. How many times can Gerald put a spell on it until the number becomes one-... | Initial number consist of no more then $100000$ digits. Therefore after first transform resulting number will be no more then $900000$, and then it will constist of no more then $6$ digits. Thus after next transform number will be no more then $54$ and so it will be two-digit or one-digit. Sum of digits of a two-digit ... | [
"implementation"
] | 1,000 | null |
103 | A | Testing Pants for Sadness | The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of $n$ questions; the questions are to be answered strictly in the order in which they are given, from question $1$... | We can't move to the $i + 1$-th question before clicking all answers at $i$-th question. We will move to the very beginning clicking at $a_{i} - 1$ answers and only one will move us to the next step. Every way from beginning to $i$-th question have length equal to $i - 1$ plus one for click. There is a simple formula f... | [
"greedy",
"implementation",
"math"
] | 1,100 | null |
103 | B | Cthulhu | ...Once upon a time a man came to the sea. The sea was stormy and dark. The man started to call for the little mermaid to appear but alas, he only woke up Cthulhu...
Whereas on the other end of the world Pentagon is actively collecting information trying to predict the monster's behavior and preparing the secret super... | Look at the formal part of statement. Cthulhu is a simple cycle with length of 3 or more and every vertix of the cycle should be a root of some tree. Notice this two important facts: a) Cthulhu is a connected graph b) Cthulhu is a graph with only cycle If we add only one edge to tree (not a multiedge nor loop) then we ... | [
"dfs and similar",
"dsu",
"graphs"
] | 1,500 | null |
103 | C | Russian Roulette | After all the events in Orlando we all know, Sasha and Roma decided to find out who is still the team's biggest loser. Thankfully, Masha found somewhere a revolver with a rotating cylinder of $n$ bullet slots able to contain exactly $k$ bullets, now the boys have a chance to resolve the problem once and for all.
Sasha... | Let's solve the problem when value $n$ is even. Obviously, if $k = 1$ we should put a bullet at most right position. For example, choose $n = 8$ and our answer string will be: .......X Let's find probability of winning at this situation. We will write zeros at losing positions and ones at winning positions: 10101010 Th... | [
"constructive algorithms",
"greedy"
] | 1,900 | null |
103 | D | Time to Raid Cowavans | As you know, the most intelligent beings on the Earth are, of course, cows. This conclusion was reached long ago by the Martian aliens, as well as a number of other intelligent civilizations from outer space.
Sometimes cows gather into cowavans. This seems to be seasonal. But at this time the cows become passive and r... | Let's solve this problem by offline. Read all queries and sort them by increasing $b$. After that there are many effective solutions but I tell you a most simple of them. Look at two following algorithms: 1. For each $(a, b)$-query calculate the answer by the simple way: for(int i = a; i < n; i += b) ans += a[i]; 2. Fi... | [
"brute force",
"data structures",
"sortings"
] | 2,100 | null |
103 | E | Buying Sets | The Hexadecimal virus loves playing with number sets — intersecting them, uniting them. One beautiful day she was surprised to find out that Scuzzy, her spherical pet cat, united all sets in one and ate the result! Something had to be done quickly and Hexadecimal rushed to the market.
The market has $n$ sets of number... | Construct bipartite graph $G_{1}$ with available sets on the left side and the numbers on the right side. We put an edge from a set to all the numbers contained in it. By Hall's theorem it follows from "the union of any k sets contains no less than k distinct numbers (for every positive integer k)" that there exists pe... | [
"flows",
"graph matchings"
] | 2,900 | null |
104 | A | Blackjack | One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!
Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to... | Obviously, suits are not change the answer. Look at all possible situations: [0 - 10] - zero ways. [11] - four ways using aces. [12 - 19] - four ways using cards from 2 to 9. [20] - 15 ways, they are described in statement. [21] - four ways using aces. [22 - 25] - zero ways. Complexity is $O(1)$. | [
"implementation"
] | 800 | null |
105 | A | Transmigration | In Disgaea as in most role-playing games, characters have skills that determine the character's ability to use certain weapons or spells. If the character does not have the necessary skill, he cannot use it. The skill level is represented as an integer that increases when you use this skill. Different character classes... | In this problem you should do just that is written in the statement. At the first you should read all skills and multiply all levels of them by koefficient $k$. Next you should drop all skills which have level less than 100. After that you should add all new skills from the second list but only those thah are not prese... | [
"implementation"
] | 1,700 | null |
105 | B | Dark Assembly | Dark Assembly is a governing body in the Netherworld. Here sit the senators who take the most important decisions for the player. For example, to expand the range of the shop or to improve certain characteristics of the character the Dark Assembly's approval is needed.
The Dark Assembly consists of $n$ senators. Each ... | Solution of this problem is search maximum for all cases of sweets' distribution. Common count of the distributions is $C_{k + n - 1}^{n - 1}$, thah id always no mare than 6435. Let us define as current some distribution and calculate values $z_{i} = min(l_{i} + c_{i} \times 0.1, 1.0)$, where $z_{i}$ is probability t... | [
"brute force",
"probabilities"
] | 1,800 | null |
105 | C | Item World | Each item in the game has a level. The higher the level is, the higher basic parameters the item has. We shall consider only the following basic parameters: attack (atk), defense (def) and resistance to different types of impact (res).
Each item belongs to one class. In this problem we will only consider three of such... | There you can see that if at least one item has empty slots then you can redistribute the residents in any order. This assertion can be easily proved. In other case you cannot move residents. Yet another thing that you can see here. In the optimal equipment all items have maximal possible paremeters. Moreover this item... | [
"brute force",
"implementation",
"sortings"
] | 2,200 | null |
105 | D | Entertaining Geodetics | The maps in the game are divided into square cells called Geo Panels. Some of these panels are painted. We shall assume that the Geo Panels without color are painted the transparent color.
Besides, the map has so-called Geo Symbols. They look like pyramids of different colors (including Geo Symbols of the transparent ... | This problem can be solved by data structure like disjoint set union (dsu) with compression paths heuristic. Every vertex of dsu is geo-panel and every connected component is the set of one-colored geo-panels. All important information stores in the leader of component. It is size of group (count of geo-panels in it), ... | [
"brute force",
"dsu",
"implementation"
] | 2,700 | null |
105 | E | Lift and Throw | You are given a straight half-line divided into segments of unit length, which we will call positions. The positions are numbered by positive integers that start with $1$ from the end of half-line, i. e. $1$, $2$, $3$ and so on. The distance between the positions is the absolute difference between the respective number... | At the beginning you should estimate maximal answer what you can get. It equals 42. This answer you can get from following obvious maximal test: 8 10 10 9 10 10 10 10 10 Common number of states in which character can be without regard to position is 8. 2 for moved/not-moved multiply to 4 for nobody-lifted/lifted-A/lift... | [
"brute force"
] | 2,500 | null |
106 | A | Card Game | There is a card game called "Durak", which means "Fool" in Russian. The game is quite popular in the countries that used to form USSR. The problem does not state all the game's rules explicitly — you can find them later yourselves if you want.
To play durak you need a pack of $36$ cards. Each card has a suit ("S", "H"... | Solution of this problem is written in the fourth paragraph of the statements. You should carefully read and implement it. Only one difficult part is how to to determine which card has higher rank. You can for every card iterate over array [ '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A' ] and determine numbers of ranks i... | [
"implementation"
] | 1,000 | null |
106 | B | Choosing Laptop | Vasya is choosing a laptop. The shop has $n$ laptops to all tastes.
Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in all other properties.
If all three properties of a laptop are \textbf{strictly less} than those ... | You can create array for all laptops where true for outdated laptop and false otherwise. Value of every cell of this array you can determine by iterating over all laptops and comparing all their parameters. At the end you should itarate over all laptops once again and choose cheapest one that is not outdated. | [
"brute force",
"implementation"
] | 1,000 | null |
106 | C | Buns | Lavrenty, a baker, is going to make several buns with stuffings and sell them.
Lavrenty has $n$ grams of dough as well as $m$ different stuffing types. The stuffing types are numerated from 1 to $m$. Lavrenty knows that he has $a_{i}$ grams left of the $i$-th stuffing. It takes exactly $b_{i}$ grams of stuffing $i$ an... | Let create array dp by size n x m. dp[i][j] means maximum number of tugriks that the baker can earn if he used i grams of dough and cook buns with stuffings of types 1..j. Initially dp[i][0] is 0 for all i. You can easily calculate this dp: dp[i][j] = max{ dp[i-c[j]*k][j-1] + d[j]*k } for every k from 0 to a[j]/b[j], f... | [
"dp"
] | 1,700 | null |
106 | D | Treasure Island | Our brave travelers reached an island where pirates had buried treasure. However as the ship was about to moor, the captain found out that some rat ate a piece of the treasure map.
The treasure map can be represented as a rectangle $n × m$ in size. Each cell stands for an islands' square (the square's side length equa... | Solution is simulation of all insrtuctions from all of local sights. But naive solution doesn't fit into time limit. You should speed up this solution and do every instruction in O(1). You can use one of following things. 1. For every position and every direction you can precalculate nearest position of sea. Now before... | [
"brute force",
"implementation"
] | 1,700 | null |
106 | E | Space Rescuers | The Galaxy contains $n$ planets, there are many different living creatures inhabiting each planet. And each creature can get into troubles! Space rescuers know it perfectly well and they are always ready to help anyone who really needs help. All you need to do is call for them.
Now the space rescuers plan to build the... | Author's solution is three ternary search for every demension that are nested within each other. It works because the function is convex. Maximum of convex functions also convex function. Author not very well imagine convex function in 3 dimrnsions, therefore you can read following proof that algorithm is correct: Let ... | [
"geometry",
"ternary search"
] | 2,100 | null |
107 | A | Dorm Water Supply | The German University in Cairo (GUC) dorm houses are numbered from $1$ to $n$. Underground water pipes connect these houses together. Each pipe has certain direction (water can flow only in this direction and not vice versa), and diameter (which characterizes the maximal amount of water it can handle).
For each house,... | The problem describes a graph of houses as nodes and one-way pipes as edges. The problem states that the graph will contain $1$ or more chains of nodes. The required is to find the start and end of every chain (consisting of more than $1$ node, which caused many hacks). The other requirement was to find the weakest edg... | [
"dfs and similar",
"graphs"
] | 1,400 | null |
107 | B | Basketball Team | As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC).
A team is to be formed of $n$ players, all of which are GUC students. However, the team might have players belonging to differe... | This problem is asking for the probability. Consider two sets of teams: the set of teams where Herr Wafa is the only student from his major and the set where at least one other student from Herr Wafa's major is present. These two sets don't intersect, so once we can compute the number of teams in the first set, A, and ... | [
"combinatorics",
"dp",
"math",
"probabilities"
] | 1,600 | null |
107 | C | Arrangement | In the year 2500 the annual graduation ceremony in the German University in Cairo (GUC) has run smoothly for almost 500 years so far.
The most important part of the ceremony is related to the arrangement of the professors in the ceremonial hall.
Traditionally GUC has $n$ professors. Each professor has his seniority l... | The problem asks for finding the lexicographically $n$-th permutation satisfying the input constraints. The trick which confused many contestants, as well as a few authors and testers, is that instead of having the restrictions formulated in a way $position[a[i]] < position[b[i]]$ the restrictions were element at posit... | [
"bitmasks",
"dp"
] | 2,400 | null |
107 | D | Crime Management | Zeyad wants to commit $n$ crimes in Egypt and not be punished at the end. There are several types of crimes. For example, bribery is a crime but is not considered such when repeated twice. Therefore, bribery is not considered a crime when repeated an even number of times. Speeding is a crime, but is not considered such... | At the first glance the upper limit for $n$ being $10^{18}$ looks huge. But in fact, combined with the fact, that the answer should be output modulo $12345$, it's should not scare you but rather hint that the problem has a DP approach. Like all DP problems the way to approach it is to split the problem into sub-problem... | [
"dp",
"graphs",
"matrices"
] | 2,400 | null |
107 | E | Darts | The night after the graduation ceremony graduate students of German University in Cairo (GUC) are playing darts. As there's no real dart board available, the photographs of members of the GUC upper management are being used.
So, $n$ rectangular photos are placed on the wall. They can overlap arbitrary and even coincid... | Before doing the coding let's do some math. The answer to this problem can be computed as the total area of all input rectangles / the area of the union of all input rectangles. One of the easy ways to understand it is the following. First notice that if all the rectangles are the same, the answer is always the number ... | [
"geometry",
"probabilities"
] | 2,700 | null |
108 | A | Palindromic Times | \underline{Tattah is asleep if and only if Tattah is attending a lecture.} This is a well-known formula among Tattah's colleagues.
On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling asleep, he was staring at the digital watch around Saher's wrist. He noticed that the ... | In this problem it was required to find next palindrome on a digital clock. Since the lowest unit of time used $1$ minute, and there are only $24 * 60$ minutes in a day, one could simply go through each minute starting from the time given in the input plus $1$ minute, until finding a palindrome. If no palindrome is fou... | [
"implementation",
"strings"
] | 1,000 | null |
108 | B | Datatypes | Tattah's youngest brother, Tuftuf, is new to programming.
Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to write programs in Gava.
Today, Tuftuf was introduced to Gava's unsigned integer datatypes. G... | Let us call a pair of datatypes $(a, b)$, where $a < b$, BAD if and only if there exists a number $x$ where $x$ fits in $a$ bits but $x * x$ does not fit in $b$ bits. The following observation helps in finding a solution to the problem. The best candidate for the number $x$ is the largest number fitting in $a$ bits, wh... | [
"math",
"sortings"
] | 1,400 | null |
109 | A | Lucky Sum of Digits | \underline{Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits \textbf{4} and \textbf{7}. For example, numbers \textbf{47}, \textbf{744}, \textbf{4} are lucky and \textbf{5}, \textbf{17}, \textbf{467} are not.}
Petya wonders ea... | Let result number contains $a$ digits $4$ and $b$ digits $7$. Obviously, that $a * 4 + b * 7 = n$. Loop through all values of $b$. If we know $b$, we can calculate $a$, $a={\frac{n-b x7}{4}}$. Among all pairs $(a;b)$ we need to choose one with $a + b$ minimum. Among all that pairs we need to choose one with $b$ minimum... | [
"brute force",
"implementation"
] | 1,000 | null |
109 | B | Lucky Probability | \underline{Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits \textbf{4} and \textbf{7}. For example, numbers \textbf{47}, \textbf{744}, \textbf{4} are lucky and \textbf{5}, \textbf{17}, \textbf{467} are not.}
Petya and his fr... | Let $L[i]$ - $i$-th lucky number, starting from 1 ($L[0] = 0$, $L[1] = 4$, $L[2] = 7$...). At first choose first $k$ lucky number, then second $k$ numbers and so on. For each of that group lets find answer, result will be a sum of each of this probabilities. Let index of current first number if $i$, last - $j$ ($j = i ... | [
"brute force",
"probabilities"
] | 1,900 | null |
109 | C | Lucky Tree | \underline{Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits \textbf{4} and \textbf{7}. For example, numbers \textbf{47}, \textbf{744}, \textbf{4} are lucky and \textbf{5}, \textbf{17}, \textbf{467} are not.}
One day Petya en... | Solve this problem using dynamic programming. Consider that root of a tree is vertex with number 1. Let $F(x)$ - number of vertex in subtree of vertex $x$ for which there is a path containing lucky edge. We will calculate $F(x)$ using recursion. If $x$ is a leaf, than $F(x) = 0$. Else, if there is an edge from $x$ that... | [
"dp",
"dsu",
"trees"
] | 1,900 | null |
109 | D | Lucky Sorting | \underline{Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits \textbf{4} and \textbf{7}. For example, numbers \textbf{47}, \textbf{744}, \textbf{4} are lucky and \textbf{5}, \textbf{17}, \textbf{467} are not.}
Petya got an arr... | At first, if our array is already sorted, just return $0$. Otherwise, if there is no lucky number in $A$, then output $- 1$. Otherwise, let $B$ is sorted $A$ (array from input). Now, for all numbers in $A$ we know a final position in $B$. Let $k$ is an index of minimal lucky number in $A$. If we want to place integer f... | [
"constructive algorithms",
"sortings"
] | 2,000 | null |
109 | E | Lucky Interval | \underline{Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits \textbf{4} and \textbf{7}. For example, numbers \textbf{47}, \textbf{744}, \textbf{4} are lucky and \textbf{5}, \textbf{17}, \textbf{467} are not.}
One day Petya ca... | That is only onw variation of solution, there are diffrent other, which uses same thinking. With constraints for $a$ and $b$ to $10^{7}$ problem can be solved using KMP algorithm: consider a string $F(1)F(2)F(3)F(4)...F(3 * 10^{7})$. We need to find first occurrence after index $a$ of string $F(a)F(a + 1)F(a + 2)...F(a... | [
"brute force",
"math"
] | 2,700 | null |
110 | A | Nearly Lucky Number | \underline{Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits \textbf{4} and \textbf{7}. For example, numbers \textbf{47}, \textbf{744}, \textbf{4} are lucky and \textbf{5}, \textbf{17}, \textbf{467} are not.}
Unfortunately, n... | In this problem you just need to find a number of lucky digits in $n$ and output $YES$ if it number is equal to $4$ or $7$, $NO$ otherwise. | [
"implementation"
] | 800 | null |
110 | B | Lucky String | \underline{Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits \textbf{4} and \textbf{7}. For example, numbers \textbf{47}, \textbf{744}, \textbf{4} are lucky and \textbf{5}, \textbf{17}, \textbf{467} are not.}
Petya recently l... | To solve this problem you need to notice that result is a prefix of string $abcdabcdabcd...abcd$ and output first $n$ characters of this string. | [
"constructive algorithms",
"strings"
] | 1,100 | null |
111 | A | Petya and Inequiations | Little Petya loves inequations. Help him find $n$ positive integers $a_{1}, a_{2}, ..., a_{n}$, such that the following two conditions are satisfied:
- $a_{1}^{2} + a_{2}^{2} + ... + a_{n}^{2} ≥ x$
- $a_{1} + a_{2} + ... + a_{n} ≤ y$ | It is easy to see that in order to maximize the sum of squares, one should make all numbers except the first one equal to 1 and maximize the first number. Keeping this in mind we only need to check whether the given value of y is large enough to satisfy a restriction that all n numbers are positive. If y is not to smal... | [
"greedy"
] | 1,400 | null |
111 | B | Petya and Divisors | Little Petya loves looking for numbers' divisors. One day Petya came across the following problem:
You are given $n$ queries in the form "$x_{i}$ $y_{i}$". For each query Petya should count how many divisors of number $x_{i}$ divide none of the numbers $x_{i - yi}, x_{i - yi + 1}, ..., x_{i - 1}$. Help him. | Let's create an array used[], j-th element of which will be the index of the last number from the input, which is divisible by j. Then for each query we'll iterate over all divisors of xi and for each k, which divides xi we'll check whether it is "unique". After that we'll update used[k]. | [
"binary search",
"data structures",
"number theory"
] | 1,900 | null |
111 | C | Petya and Spiders | Little Petya loves training spiders. Petya has a board $n × m$ in size. Each cell of the board initially has a spider sitting on it. After one second Petya chooses a certain action for each spider, and all of them humbly perform its commands. There are 5 possible commands: to stay idle or to move from current cell to s... | This problem has many different approaches. One of them uses the fact that the overall number of possible inputs is small and it is possible to compute the answer manually for all of them. One could also write a brute-force with a few optimizations, which works even without a precalc. However, the major part of all sol... | [
"bitmasks",
"dp",
"dsu"
] | 2,100 | null |
111 | D | Petya and Coloring | Little Petya loves counting. He wants to count the number of ways to paint a rectangular checkered board of size $n × m$ ($n$ rows, $m$ columns) in $k$ colors. Besides, the coloring should have the following property: for any vertical line that passes along the grid lines and divides the board in two non-empty parts th... | One can notice that if $m = 1$ then the answer is kn, because all colorings are possible. Now we'll assume that m > 1. Let's look on the first column of the board (i.e. the vertical cut will be made right next to the first column). Suppose there are x distinct colors in this column. Then in the rest of the board there ... | [
"combinatorics",
"dp"
] | 2,300 | null |
111 | E | Petya and Rectangle | Little Petya loves playing with rectangles. Mom bought Petya a rectangle divided into cells $n × m$ in size (containing $n$ rows, $m$ columns). Petya marked two different cells of the rectangle and now he is solving the following task:
Let's define a \underline{simple path} between those two cells as a sequence of dis... | Let the length of the maximal path be S. First, we'll estimate the value of S without specifying the longest path itself. Let's color our board into a chess-coloring. Obviously, each two neighboring cells in the path will have different color. Keeping this in mind we can make some estimation on the value of S. For exam... | [] | 2,900 | null |
112 | A | Petya and Strings | Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings \underline{lexicographically}. The letters' case does not matter, that is an uppercase letter is considered equivalent... | In this problem one could transform all letters in both strings to lower case and then compare the strings lexicographically. | [
"implementation",
"strings"
] | 800 | null |
112 | B | Petya and Square | Little Petya loves playing with squares. Mum bought him a square $2n × 2n$ in size. Petya marked a cell inside the square and now he is solving the following task.
The task is to draw a broken line that would go along the grid lines and that would cut the square into two equal parts. The cutting line should not have a... | One can notice that if we want to divide a square into two equal parts, then the cutting line should pass through the center of our square. Thus, if the marked cell contains the center of the square, then we can't make a cut, otherwise we can. | [
"implementation",
"math"
] | 1,200 | null |
113 | A | Grammar Lessons | Petya got interested in grammar on his third year in school. He invented his own language called Petya's. Petya wanted to create a maximally simple language that would be enough to chat with friends, that's why all the language's grammar can be described with the following set of rules:
- There are three parts of spee... | This task is an example of task that requires accurate realization. After reading the statement one can understand that we have to check whether the text from input represents exactly one correct sentence or no. If yes, therefore the text can be either a single word from our language or a following structure: {zero or ... | [
"implementation",
"strings"
] | 1,600 | null |
113 | B | Petr# | Long ago, when Petya was a schoolboy, he was very much interested in the Petr# language grammar. During one lesson Petya got interested in the following question: how many different continuous substrings starting with the $s_{begin}$ and ending with the $s_{end}$ (it is possible $s_{begin} = s_{end}$), the given string... | Let's find all occurrences of begin and end. Then we'll map the whole string to number 0. After this we will simply add one symbol per iteration to already seen sub-strings and map new strings to some non-negative integers. One can notice that we will never reach a situation when more then 2000 different strings exist,... | [
"brute force",
"data structures",
"hashing",
"strings"
] | 2,000 | null |
113 | C | Double Happiness | On the math lesson a teacher asked each pupil to come up with his own lucky numbers. As a fan of number theory Peter chose prime numbers. Bob was more original. He said that number $t$ is his lucky number, if it can be represented as:
\[
t = a^{2} + b^{2},
\]
where $a, b$ are arbitrary positive integers.Now, the boys... | In this task one have to find quantity of prime numbers that can be reproduced as sum of two perfect squares. Obviously, that $4k + 3$ prime numbers are not suitable as sum of two perfect squares can not be equal to 3 (of course, modulo 4). So, we can prove or use the well-known fact ( also known as Fermat theorem), th... | [
"brute force",
"math",
"number theory"
] | 2,200 | null |
113 | D | Museum | One day as Petya and his friend Vasya were having one of their numerous trips, they decided to visit a museum castle. The museum has a specific shape: it consists of $n$ rooms connected with $m$ corridors so that one can access any room from any other one.
After the two friends had a little walk around the museum, the... | Let's consider a pair (i, j) as a state - this means that now Petya is in room i, and Vasya is in room j. Therefore, their meeting is state (i, i) for some i. So, it's quite easy to build transition matrix - this means that for each state (i, j) we will know probability of reaching state (x, y) in one step, where $1 \... | [
"math",
"matrices",
"probabilities"
] | 2,700 | null |
113 | E | Sleeping | One day Vasya was lying in bed watching his electronic clock to fall asleep quicker.
Vasya lives in a strange country, where days have $h$ hours, and every hour has $m$ minutes. Clock shows time in decimal number system, in format H:M, where the string H always has a fixed length equal to the number of digits in the d... | Let's consider function $F(x)$ (where $x$ is some moment of time) $-$ amount of moments from 0..00:00..00 up to $x$ (and $x$ doesn't switch to next moment ) when n $k$ or more digits will be changed . The answer will be $F(h2: m2) - F(h1: m1)$, also it's necessary not to forget that if $h2: m2 < h1: m1$, then $F(h2: m2... | [
"combinatorics",
"implementation",
"math"
] | 2,700 | null |
114 | A | Cifera | When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million... | To solve this task, let's describe what is needed more formally. We should answer whether is number $l$ some positive degree of number $k$ or no. To answer this question we can proceed in 2 ways: 1) Using 64 bit data type, we can find minimal degree $h$ of number $k$, such that $k^{h} \ge l$. If $k^{h} = l$, then the... | [
"math"
] | 1,000 | null |
114 | B | PFAST Inc. | When little Petya grew up and entered the university, he started to take part in АСМ contests. Later he realized that he doesn't like how the АСМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff... | We can reformulate the statement more formally. In this case, we have a undirected graph, and we have to find some maximal clique in it. If we have a look to constraint $n \le 16$, then there can be noticed that we can iterate over all possbile subsets of vertices and find the answer. To do this, one can use bit mask... | [
"bitmasks",
"brute force",
"graphs"
] | 1,500 | null |
115 | A | Party | A company has $n$ employees numbered from $1$ to $n$. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee $A$ is said to be the \underline{superior} of another employee $B$ if at least one of the following is true:
- Employee $A$ ... | We let an employee without a manager called as root. There's an edge from a manager to an employee that he/she manages. First notice that the graph is a collection of directed trees. Hence, we can assign a depth label to each node - denoting the number of nodes on the simple path from the root to it. The answer is then... | [
"dfs and similar",
"graphs",
"trees"
] | 900 | null |
115 | B | Lawnmower | You have a garden consisting entirely of grass and weeds. Your garden is described by an $n × m$ grid, with rows numbered $1$ to $n$ from top to bottom, and columns $1$ to $m$ from left to right. Each cell is identified by a pair $(r, c)$ which means that the cell is located at row $r$ and column $c$. Each cell may con... | First, let's observe a particular strategy that turns out to be optimal at the end of our discussion. Suppose we're on a row, facing right. This strategy say that we need to move to the right as long as there is a weed to the right of us either on this row or on the row directly below us. The idea is that we need to mo... | [
"greedy",
"sortings"
] | 1,500 | null |
115 | C | Plumber | Little John aspires to become a plumber! Today he has drawn a grid consisting of $n$ rows and $m$ columns, consisting of $n × m$ square cells.
In each cell he will draw a pipe segment. He can only draw four types of segments numbered from $1$ to $4$, illustrated as follows:
Each pipe segment has two ends, illustrated... | To solve this problem, let's imagine that the left and top sides of the grid also determines whether the pipe adjacent to that side has an end connecting it to the side or not. There are 2^(N+M) ways to pick them. We claim that if we fix them (i.e., pick one of the possible 2^(N+M) ways, then the entire grid's pipes ar... | [
"math"
] | 2,200 | null |
115 | D | Unambiguous Arithmetic Expression | Let's define an unambiguous arithmetic expression (UAE) as follows.
- All non-negative integers are UAE's. Integers may have leading zeroes (for example, $0000$ and $0010$ are considered valid integers).
- If $X$ and $Y$ are two UAE's, then "$(X) + (Y)$", "$(X) - (Y)$", "$(X) * (Y)$", and "$(X) / (Y)$" (all without th... | This problem is solved using Dynamic Programming. The somewhat straightforward dynamic programming is to represent the state as {start_pos, end_pos}, which represents the number of unambiguous arithmetic expression on the substring of the input starting at start_pos and ending at end_pos. This however has a complexity ... | [
"dp",
"expression parsing"
] | 2,600 | null |
115 | E | Linear Kingdom Races | You are a car race organizer and would like to arrange some races in Linear Kingdom.
Linear Kingdom has $n$ consecutive roads spanning from left to right. The roads are numbered from $1$ to $n$ from left to right, thus the roads follow in the order of their numbers' increasing. There will be several races that may be ... | We process the roads one by one. Associated with each road is the races whose UBi is that road (i.e., races that 'ends' at that road). We will discuss the Dynamic Programming solution first, then improve it with a data structure into the optimal solution. Let's say we're going to process a road. Our state is this : DP[... | [
"data structures",
"dp"
] | 2,400 | null |
116 | A | Tram | Linear Kingdom has exactly one tram line. It has $n$ stops, numbered from $1$ to $n$ in the order of tram's movement. At the $i$-th stop $a_{i}$ passengers exit the tram, while $b_{i}$ passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passenger... | If we know the number of people inside the tram at all possible time, then the answer is the maximum of such. We observe that the number of people inside the tram changes only at tram stops. The conclusion is that the answer will be the maximum of the number of people inside the tram directly before arriving at a parti... | [
"implementation"
] | 800 | null |
116 | B | Little Pigs and Wolves | Once upon a time there were several little pigs and several wolves on a two-dimensional grid of size $n × m$. Each cell in this grid was either empty, containing one little pig, or containing one wolf.
A little pig and a wolf are adjacent if the cells that they are located at share a side. The little pigs are afraid o... | No... not maximum matching ;) So, an equivalent less-evil rewording of the problem would be: "Return the number of wolves that are adjacent to at least one pig". To see this, since each pig has at most one wolf adjacent to it (the constraints impose that) we don't need to worry at a single pig may get eaten by two diff... | [
"greedy",
"implementation"
] | 1,100 | null |
117 | A | Elevator | And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All $n$ participants who have made it to the finals found themselves in a huge $m$-floored $10^{8}$-star hotel. Of course the first thought to come in a place like this is "How about checking out the... | Consider three cases. $s = f$, $ans = t$. $s < f$, we must find the smallest non-negative $k$ such, that $t \le (s - 1) + 2(m - 1)k$. $ans = s - 1 + 2(m - 1)k + (f - s)$. $s > f$, similarly, we must find the smallest non-negative $k$ such, that $t \le 2(m - 1) - (s - 1) + 2(m - 1)k$. $ans = 2(m - 1) - (s - 1) + 2(m... | [
"implementation",
"math"
] | 1,300 | null |
117 | B | Very Interesting Game | In a very ancient country the following game was popular. Two people play the game. Initially first player writes a string $s_{1}$, consisting of exactly nine digits and representing a number that does not exceed $a$. After that second player looks at $s_{1}$ and writes a string $s_{2}$, consisting of exactly nine digi... | Suppose, that the first player made a move $x \le a$, then consider the remainder $rem = x \cdot 10^{9}%mod$. Obviously, if $(mod - rem)%mod \le b$, then the second player can win. Thus, we must iterate through all relevant values of $x$ (we don't need iterate through more than $mod$ values) and check whether the ... | [
"brute force",
"number theory"
] | 1,800 | null |
117 | C | Cycle | A \underline{tournament} is a directed graph without self-loops in which every pair of vertexes is connected by exactly one directed edge. That is, for any two vertexes $u$ and $v$ ($u ≠ v$) exists either an edge going from $u$ to $v$, or an edge from $v$ to $u$.
You are given a tournament consisting of $n$ vertexes. ... | If the tournament has at least one cycle, then there exist a cycle of length three. A constructive proof. Find any cycle in the tournament by using any standard algorithm, such as depth-first search. If there is no cycle, then output -1, else choose any three consecutive vertices of the cycle $v_{1}$ $v_{2}$ $v_{3}$ ($... | [
"dfs and similar",
"graphs"
] | 2,000 | null |
117 | D | Not Quick Transformation | Let $a$ be an array consisting of $n$ numbers. The array's elements are numbered from $1$ to $n$, $even$ is an array consisting of the numerals whose numbers are even in $a$ ($even_{i} = a_{2i}$, $1 ≤ 2i ≤ n$), $odd$ is an array consisting of the numberals whose numbers are odd in $а$ ($odd_{i} = a_{2i - 1}$, $1 ≤ 2i -... | Imagine a recursion tree our transformation $F$. This tree is binary. We write on the edges leading into the left subtree, zero, and on the edges, leading to the right, one. Now consider the path of some number $a$ (hereafter, we assume that we substracted one from all numbers in the array over which we make the conver... | [
"divide and conquer",
"math"
] | 2,500 | null |
117 | E | Tree or not Tree | You are given an undirected connected graph $G$ consisting of $n$ vertexes and $n$ edges. $G$ contains no self-loops or multiple edges. Let each edge has two states: on and off. Initially all edges are switched off.
You are also given $m$ queries represented as $(v, u)$ — change the state of all edges on the shortest ... | In this problem, suggested a solution using heavy light decomposition. Graph, given in problem statement, is a cycle, on which are suspended trees. For each tree construct the data structure (heavy light + segment tree), which can perform $change$ on the path from some vertex to any parent, and to maintain the amount o... | [
"data structures",
"divide and conquer",
"graphs",
"implementation",
"trees"
] | 2,900 | null |
118 | A | String Task | Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it:
- deletes all the vowels,
- inserts a character "." before each consonant,
- replaces all ... | First problem only is realization. In need read input string, delete all uppercase and lowercase vowels letter and print answer. | [
"implementation",
"strings"
] | 1,000 | null |
118 | B | Present from Lena | Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from $0$ to $n$ as the pattern. The digits will form a rhombus. The largest digit $n$ should be located in the centre. The digits should decrease as they approach the edges. For example, for $n = 5$ t... | Second problem is realization too. Good solution to calc count space in beginning of string. In handkerchief pattern there is 2 * n + 1 rows. In rows form 0 to N number of space is 2 * n - i. In rown number from N + 1 to 2 * N number of space is (I - N) * 2. | [
"constructive algorithms",
"implementation"
] | 1,000 | null |
118 | C | Fancy Number | A car number in Berland consists of exactly $n$ digits. A number is called beautiful if it has at least $k$ equal digits. Vasya wants to change the digits in his car's number so that the number became beautiful. To replace one of $n$ digits Vasya has to pay the sum of money, equal to the absolute difference between the... | In this task it need to find a minimal sum that to find a beautiful number of car. So, there are only 10 available digits. Let us try the minimum cost to have one of those digits repeat at least K times and the lexicographically minimum string that has such cost. Then we pick the best result among all digits. Therefore... | [
"brute force",
"greedy",
"sortings",
"strings"
] | 1,900 | null |
118 | D | Caesar's Legions | Gaius Julius Caesar, a famous general, loved to line up his soldiers. Overall the army had $n_{1}$ footmen and $n_{2}$ horsemen. Caesar thought that an arrangement is \textbf{not} beautiful if somewhere in the line there are strictly more that $k_{1}$ footmen standing successively one after another, or there are strict... | The problem is solved lazy dynamics. Let z[n1] [n2] [2] - a number of ways to place troops in a legion of Caesar. Indicate the following parameters, n1 - is a number of footmen, n2 - is a number of horseman, the third parameter indicates what troops put Caesar in the beginning of the line. If Caesar wants to put the fo... | [
"dp"
] | 1,700 | null |
118 | E | Bertown roads | Bertown has $n$ junctions and $m$ bidirectional roads. We know that one can get from any junction to any other one by the existing roads.
As there were more and more cars in the city, traffic jams started to pose real problems. To deal with them the government decided to make the traffic one-directional on all the roa... | We are given an undirected connected graph, it is necessary to orient its arc so as to obtain a strongly connected directed graph. There is theorem (on a theoretical basis for a written task) that a graph admits an orientation to a strongly connected digraph if and only if every edge is part of what a cycle. To test th... | [
"dfs and similar",
"graphs"
] | 2,000 | null |
119 | A | Epic Game | Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number $a$ and Antisimon receives number $b$. They also have a heap of $n$ stones. The players take turns to make a move and Simon starts. During a move a player should take... | It's enough just to model the described game to solve this problem. You can search a greatest common divisor in any reasonable way. | [
"implementation"
] | 800 | #include <iostream>
using namespace std;
int gcd(int x, int y)
{
return (x==0)? y : gcd(y % x, x);
}
int main()
{
int a, b, n;
cin >> a >> b >> n;
int k = 0;
while (n >= 0)
{
++k;
n -= gcd((k & 1) ? a : b, n);
}
if (k & 1) cout << 1; else cout << 0;
} |
119 | B | Before Exam | Vasya is about to take his first university exam in about several minutes. And it's not just some ordinary exam, it's on mathematical analysis. Of course, right now Vasya can only think of one thing: what the result of his talk with the examiner will be...
To prepare for the exam, one has to study proofs of $n$ theore... | Let's consider solution of the task for maximum level of profience (for minimum level solution is similar). It's clear that maximum level can be reached either in a card that has fallen one somebody's lot already or in a card about that we know nothing. In the first case we can just calculate levels of profiency for al... | [
"constructive algorithms",
"implementation",
"sortings"
] | 1,900 | #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int n, k, a[100], q, ans_mx = -1, ans_mn = 1E9, nmb;
bool used[100];
vector<int> rem;
int main()
{
cin >> n >> k; nmb = n / k;
for (int i = 0; i < n; ++i) cin >> a[i];
int f = 0;
cin >> q;
for (int i = ... |
119 | C | Education Reform | Yet another education system reform has been carried out in Berland recently. The innovations are as follows:
An academic year now consists of $n$ days. Each day pupils study exactly one of $m$ subjects, besides, each subject is studied for no more than one day. After the lessons of the $i$-th subject pupils get the h... | This problem can be solved by dynamic programming. Let's sort all subjects in order of complexity's non-increasing. Let $d < / span > [ < spanstyle = "" > i < / span > ][ < spanstyle = "" > j < / span > ][ < spanstyle = "" > z < / span > ]$ is the greatest summary number of exercises, that can be given, if timetable co... | [
"dp"
] | 2,000 | #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct TSubject
{
__int64 a, b;
int nmb, c;
} sb[100];
bool operator < (const TSubject &x, const TSubject &y)
{
return x.c < y.c;
}
int n, m, k, cur = 0;
__int64 d[50][101][51];
pair<int, int> p[50][101][51], state;
int main()
{... |
119 | D | String Transformation | Let $s$ be a string whose length equals $n$. Its characters are numbered from 0 to $n - 1$, $i$ and $j$ are integers, $0 ≤ i < j < n$. Let's define function $f$ as follows:
$f(s, i, j) = s[i + 1... j - 1] + r(s[j... n - 1]) + r(s[0... i])$.
Here $s[p... q]$ is a substring of string $s$, that starts in position $p$ an... | If lengths of input strings aren't equal, we can at once output "-1 -1" and complete execution of a program. Otherwise let number $n$ is equal to the length of input strings. Let's iterate through the number $i$. We should find (in $O(1)$) the such smallest number $j$, that substing $b[0... n - i - 1]$ can be represent... | [
"hashing",
"strings"
] | 2,500 | #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string a, b, s1, s2;
int main()
{
getline(cin, a);
getline(cin, b);
if (a.length() != b.length())
{
cout << "-1 -1";
return 0;
}
int n = a.length();
s1 = a; reverse(s1.begin(),s1.end()); s1 += ' '... |
120 | A | Elevator | A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails n... | You can either check all four cases or notice, that if we consider front/back equal to 0/1 (b) and decrease a by 1, then a XOR b became the answer (0/1). Time and memory consumption - $O(1)$. | [
"brute force",
"implementation",
"math"
] | 1,000 | null |
120 | B | Quiz League | A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts are allowed a minute on brainstorming and finding the right answer to the que... | Just write one loop: while $k$th question has already been asked, increase $k$ by one and if $k > n$ let $k = 1$. Time and memory consumpiton - $O(n)$. | [
"implementation"
] | 1,100 | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.