By Fefer_Ivan, 5 years ago, In English,

436A - Feed with Candy

Tutorial author: Fefer_Ivan

In this problem types of eaten candies must alternate. It means that the type of first eaten candy dictated the types of all the following candies. There are only two possible types so we should consider each type as a type of first eaten candy separatelly and then pick the most optimal. So, what if Om Nom wants to eat a candy of type t and can jump up to h? It is obvious that best option is to eat a candy with maximal mass among all the candies he can eat at this time.

436B - Om Nom and Spiders

Tutorial author: Fefer_Ivan

Let us number columns with integers from 0 from left to right and rows from 0 from top to bottom. In the cell (x, y) at the time t only four spiders can be at this cell:

  • Spider, which is moving left and started at (x, y + t).
  • Spider, which is moving right and started at (x, y - t).
  • Spider, which is moving up and started at (x + t, y).
  • Spider, which is moving down and started at (x - t, y).

Let iterate through all possible starting positions of Om Nom. Consider that he starts at column y. At time 0 all spiders are on their initial positions and Om Nom is at (0, y). There is no spiders at row 0, so at time 0 Om Nom can not meet any spiders. When Om Nom is at cell (x, y), it means that x units of time passed after the start. So to calculate the number of spiders, that Om Nom meets it is enought to check only 4 cells stated above.

436C - Dungeons and Candies

Tutorial author: Fefer_Ivan

Let's consider a weighted undirected graph with k + 1 vertex. Label the vertices with numbers from 0 to k. Vertices from 1 to k correspond to levels. For each pair of levels i and j add an edge between vertices i and j with weight equal to the cost of transferring one level as a difference from the other level. For each level i add an edge from vertex 0 to vertex i with weight equal to n·m, i.e. cost of transmitting the whole level. Each way to transmit levels defined an spanning tree of this graph. So to solve the problem, we must find a minimal spanning tree of this graph.

436D - Pudding Monsters

Tutorial author: Fefer_Ivan

This problem can be solved using dynamic programming. Let's introduce some designations: sum(l, r) — number of special cells on the segment [l, r], zi — maximal number of covered special cells using only first i monsters, di — maximal number of covered special cells using only first i monsters and with i-th monster not moving.

How to calculate di. Let's denote i-th monster position as r. Let's iterate through all special cells to the left of i-th monster. Let's denote current special cell position as l. Let's consider the situation when this cell is the leftmost special cell in the block of monsters with i-th monster in it. So we need r - l additional monsters to get to this cell from monster i. So the value of di can be updated with zi - (r - l) + sum(l, r).

Now, after we computed new value of di, we need to update some values of zj. Let's denote i-th monster position as l. Let's iterate through all special cells to the right of i-th monster. Let's denote current special cell position as r. Let's consider the situation when this cell is the rightmost special cell in the block of monsters with i-th monster in it. So we need r - l additional monsters to get to this cell from monster i. So we can update the value zi + (r - l) with di + sum(l + 1, r). Also, zi should be updated with zi - 1.

So the solution works in O(n·m) because for each of n monsters we iterate through all m special cells and for a fixed monster-cell pair all computing is done in O(1).

There are some details about monsters, that are merged at the initial state, but they are pretty easy to figure out.

436E - Cardboard Box

Tutorial author: Gerald, Nerevar

In this task you have to come with the proper greedy algorithms. Several algorithms will fit, let's describe one of them:

  • From that point we will consider that the levels are sorted by increasing value of b.
  • Let's look at some optimal solution (a set of completed levels). From levels that we completed for two stars, select the level k with the largest b[k]. It turns out that all levels that stand before k (remember, the levels are sorted) should be completed for at least one star. Otherwise, we could complete some of the previous levels instead of the level k. This won't increase the cost.
  • Let's fix a prefix of the first L levels and solve the problem with the assumption that each of the selected levels should be completed. Additionally, we will assume that all levels that are completed for two stars are within this prefix (as was shown before, such prefix of L levels always exists for some optimal solution).
  • As we will surely complete this L levels, we can imagine that we have initially completed all of the for just one star. So, we have w - L more stars to get. We can get these stars either by completing some of the levels that are outside our prefix for one star, or by completing some of the first L levels for two stars instead of one star.
  • It's clear that we just have to choose w - L cheapest options, which correspond to w - L smallest numbers among the following: b[i] - a[i] for i ≤ L and a[i] for i > L. Computing the sum of these smallest values can be done with a data structure like Cartesian tree or BIT.

The described solution has time completixy of O(n log n).

436F - Banners

Tutorial author: Gerald, Nerevar

Task F was the hardest one in the problemset. To better understand the solution, let's look at the task from the geometrical point of view. Imagine that people are point in the Opc plane (value of p and q are points' coordinates). Then for each line horizontal c = i we have to find such vertical line p = j that maximizes some target function. The function is computed as follows: (number of points not below c = i, multiplied by w·i) plus (number of points below c = i and not to the left of p = j, multiplied by j).

Let's move scanning line upwards (consider values c = 0, then c = 1, etc). For each value of p we will store the value d[p] — the value of the target function with the current value of c and this value of p. The problem is: if we have such array d[] for the value c, how to recompute it for the value c + 1?

Let's look at all people that will be affected by the increase of c: these are the people with b[i] = c. With the current c they are still using free version, after the increase they won't. Each of these people makes the following effect to the array: d[1] +  = 1, d[2] +  = 2, ..., d[b[i]] +  = b[i]

Now the task can be reduced to the problem related with data structures. There are two types of queries: add the increasing arithmetical progression to the prefix of the array and retrieve the maximum value of the array. One of the way to solve it is to use sqrt-decomposition.

Let's divide all queries into groups of size sqrt(q). Let's denote the queries from the group as a sequence: p1, p2, ..., pk (k = sqrt(q)). For query pi we should perform assignments d[1] +  = 1, d[2] +  = 2, ..., d[pi] +  = pi. Imagine we already preformed all the queries. Each value of new array d[] can be represented as d[i] = oldD[i] + i·coef[i], where coef[i] is the number of pj (pj > i).

One can notice that array coef contains at most sqrt(q) distinct values, additionally this array can be splitted into O(sqrt(q)) parts such that all elements from the same part will be the same. This is the key observation. We will divide array coef into parts. And for each part will maintain lower envelope of the lines y = d[i] + i·x. So, we will have O(sqrt(q)) lower envelopes. Each envelope will help us to get maximum value among the segment of array d[i](oldD[i] + i·coef[i]). As for each i from some segment factor coef[i] is containt we can just pick y-coordinate with x = coef[i] of corresponding lower envelope.

Described solution has time complexity of O(MAXX·sqrt(MAXX)), where MAXX is the maximum value among a[i] and b[i]. With best regards, Ivan.

Read more »

Tutorial of Zepto Code Rush 2014
  • Vote: I like it  
  • +117
  • Vote: I do not like it  

By viktork, 5 years ago, translation, In English,

A coder can apply his breathtaking coding skills not only in different search engines but also in the mobile game industry. It is an option in Russia. If you do not believe — check this out: ZeptoLab company that created the world famous Cut the Rope game offers you the opportunity to see this for yourself. And yes, we are in Moscow.

It's not a secret that those who strive to achieve top coding skills — work hard, including work on his self-education. Here in ZeptoLab we aim to create the area that strongly encourages self-development. Specifically, we have recently purchased a company library with everything necessary to get new knowledge, an improvised reading room with sofas and armchairs.

We also conduct developer's contest inside the company so that our ZeptoCoders could solve non-trivial problems and impress each other with zeroes and ones. The winners get glory, valuable gifts and name-encrusted weapon (it's a joke, it’s not weapon)

We have recently opened our own algorithmic school here in ZebtoLab and the teacher is no other than the creator and the head of the whole wide Codeforces, Mike Mirzayanov! He is well-known among developers: Mike has trained a team that became the world champion in programming, so it's not hard to imagine the opportunities opened for ZeptoLab developers and the whole company. It's the first time that Mike teaches in such format, there are hardly any more examples of such corporate education systems in Russia and throughout the world.

Algorithms play an important role for us as the requirements for developers are quite tough: ideally, the application should output 60 frames per second on the target gadget. All game logic calculations should be very quick and preferably, with simple and not amortized complexity. Besides, we can afford a fine pre-processing to transport some calculations to the stage at which resources for the game are prepared. Understanding this facts, alongside with many more is the key to the quick gameplay. That is why we support the algorithmist's movement.

It's the first time when Zeptolab holds an algorithmic development contest based on Codeforces. Ingenious problems, fierce developer rivalry and cool prizes are waiting for you:

  • 1st prize: Ipad Air, plush Om Nom, the championship T-shirt
  • 2nd-3rd prize: Ipad Mini, plush Om Nom, the championship T-shirt
  • 4-th-30-th prize: plush Om Nom, the championship T-shirt
  • 31st-50th prize: the championship T-shirt

And just for some suspense, we add another prize:

We will randomly give the IPad Mini Retina to the person who makes it to the top 50 list of the contest champion. The IPad winner will be chosen like this: we sum up the times of all successful attempts of three top winners (in seconds starting from the start of the contest) and take a row with number s % 47 + 4, where s is the resulting sum. Being true coders. If the resulting line divides the place, then the priority goes to the earlier person to submit his last solved problem.

Besides, the person who shows good results in the contest will have the opportunity to apply for a job in our company by a simplified scheme. If you'd be interested to try working in the ZeptoLab team, tick the corresponding square at the registration.

You can find out more about what working with us is like at

What to apply to ZeptoLab?

The championship will be conducted in a single round. The contest will go by the Codeforces rules. The round will be rated and both divisions can participate.

The date and time of the contest is: June 13, 2014, 15:30PM — 18PM (UTC).

The problem scores are: 1000-1000-1500-2500-2500-3000.

The contest is over! Thanks for all the participants! We hope you like the problems and the contest! Our special congratulations to the winners:

  • The 1st place — KAN (Nikolay Kalinin, Russia, Nizhniy Novgorod) — iPad Air
  • The 2nd place — winger (Vladislav Isenbaev, USA, Facebook) — iPad Mini
  • The 3rd place — tourist (Gennady Korotkevich, Russia, Saint Peterburg, ITMO) — iPad Mini

All the participants on the places 1-30 will receive presents: plush Om Nom and the championship T-shirt. All the participants on the places 31-50 will receive championship T-shirt!

Additional prize will be received to the the 21st place winner: package.zaic (Vadim Zaycev, Russia, Novosibirsk, NSU).

Read more »

Announcement of Zepto Code Rush 2014
  • Vote: I like it  
  • +726
  • Vote: I do not like it