seland's blog

By seland, 4 years ago, In English,

545A - Toy Cars

We can find all information about i-th car collisions in the i-th row of the matrix A. More specific, if there is at least one 1 or 3 at i-th row, then i-th car isn't good (it was turned over in at least one collision). Otherwise, i-th car is good. We just need to check this condition for each car.

545B - Equidistant String

One can see, that if si = ti for some i, then the value of pi isn't important for us. Really, if we make pi equal to si then it also be equal to ti. And if we make pi not equal to si then it also be not equal to ti. So, we have an answer that is closer or further to both of s and t.

So we interested about such position i that si ≠ ti. If we make pi equal to si we make p further from t. If we make pi equal to ti we make p further from s. It means that we need to divide these positions into two equal parts to have equidistant string. For example, we can make first of these positions closer to s, second closer to t and so on. If the number of these positions is even, we find an answer, if it is odd, answer doesn't exist.

Time complexity — O(n).

545C - Woodcutters

One can solve this problem using dynamic programming or greedy algorithm. Start with DP solution.

Define stayi, lefti and righti as maximal count of trees that woodcutters can fell, if only trees with number from 1 to i exist, and i-th tree isn't cutted down, i-th tree is cutted down and fallen left, i-th tree is cutted down and fallen right correspondingly. Now we can compute this values for each i from 1 to n by O(n) time because for each next we need only two previous value. Answer is maximum of stayn, leftn, rightn.

Also this problem can be solved by the next greedy algoritm. Let's fell leftmost tree to the left (it always doesn't make an answer worse). After that, try to fell the next tree. If we can fell it to the left, let's do it (because it also always doesn't make an answer worse). If we can't, then try to fell it to the right. If it is possible, let's do it. Last step is correct because felling some tree to the right may only prevent the next tree's fallen. So we may "exchange" one tree to another without worsing an answer.

Time complexity — O(n).

545D - Queue

We can solve this problem by greedy algorithm. Let's prove that it is always possible find an answer (queue with the maximal number of not disappointed people), where all not disappointed people are at the begin of queue. Assume the contrary — there are two position i and j such that i < j, persons at position from i to j - 1 are disappointed, but j-th person isn't. Then just swap persons at positions i and j. After that all persons from i to j - 1 will be still disappointed (or become not disappointed) and j-th person will be still not disappointed. So the answer isn't maked worse.

So, we need to find person with minimal ti, that can be served now and will be not disappointed. We can do that by sorting all the people by time ti and try to serve them one by one. If somebody will be disappointed, we may send he to the end of queue, and doesn't add his serve time to the waiting time.

Time complexity — O(n + sort).

545E - Paths and Trees

It's true, that Dijkstra modification, where in case of equal distances we take one with shorter last edge, find an answer.

For prove that let's do some transformation with graph. At first, find all shortest paths from u to other vertices. Define di as the length of shortest path from u to i. After that, we can delete some edges. Specifically, we can delete an edge with ends in x and y and weight w if |dx - dy| ≠ w, because it isn't contained in any shortest path, so it isn't contained in shortest path tree. After that, we can direct all edges from vertices with less distance to vertices with greater distance (because of all weight are positive). It's easy to prove, that if we take one edge that entering each vertex, we have a shortest path tree. Then we only need to take for each vertex minimal egde, that entering this vertex. Why? Because we have to take at least one edge, that entering each vertex to make a graph connected. We can't take edges with less weights than minimal. And if we take minimal edges, that entering each vertex we will have an shortest path tree. So that is minimal possible total wieght of shortest path tree.

You can see, that Dijkstra with modification do exactly the same things.

Time complexity —

Read more »

  • Vote: I like it  
  • +38
  • Vote: I do not like it  

By seland, 4 years ago, translation, In English,

Hello everyone!

I am glad to announce that soon will Codeforces Round #303 for Div.2 paricipants, the author of which I am. Traditionally Div.1 participants can take part out of the competition.

This is my first round, and I hope that it will be interesting.

Round wouldn't take place without the help of the Codeforces team! Great thanks to zlobober for helping me preparing the round and delinur for translation. Special thanks to everyone who puts his effort into the creation and maintenance of Codeforces and Polygon systems.

Score distribution will be announce later.

Good luck and inspiration!

UPD Score distribution will be — 500-1000-1750-1750-2500.

UPD Congratulations for winners in Div.2:

  1. Bell-sama
  2. anko
  3. BobDylan
  4. Gusheng
  5. Diguised
  6. imyyimdog

And in Div.1:

  1. langtrunghieu
  2. Laakeri
  3. Um_nik
  4. KrK

UPD Link for editorial.

Read more »

  • Vote: I like it  
  • +174
  • Vote: I do not like it  

By seland, 4 years ago, In Russian,

Что-то сегодня было не так с добавлением задач, или что-то не так со мной. При добавление задачи в мешап по ссылке из дескриптора контеста, скачанного с Полигона, выдаёт ошибку: "Невозможно найти/получить дескриптор задачи".

Пробую создавать тренировку — действую как написано в инструкции справа. В итоге получаю несколько неожиданностей — во-первых, при нажатии на обновление контеста меня перебрасывало на другие страницы Codeforces, которые были открыты в том же браузере. Но, что более грустно, так и не получилось создать тренировку. Говорит:

"Не удалось выпустить релиз соревнования из-за ошибок валидации: Can't download statement of contest from '': Received unexpected Response {code=403, size=961, s='<ti...body>'}."

При этом пакеты всех задач из контеста были готовы.

Еще одной неприятностью для меня стала невозможность удалять файлы из корня песочницы и невозможность удалять папки в принципе.

В общем, хотелось бы всё-таки понять, что случилось, и как создать тренировку.

Буду благодарен за помощь в этом вопросе!

Read more »

  • Vote: I like it  
  • +4
  • Vote: I do not like it