Блог пользователя ch_egor

Автор ch_egor, 7 лет назад, По-английски

Thanks for the participation!

1214A - Optimal Currency Exchange was authored and prepared by Helen Andreeva.

1214B - Badges was authored by jury and prepared by Chmel_Tolstiy.

1214C - Bad Sequence was authored by meshanya and prepared by GoToCoding.

1214D - Treasure Island was authored by meshanya and prepared by malcolm.

1214E - Petya and Construction Set was authored and prepared by voidmax.

1214F - Employment was authored and prepared by grphil.

1214G - Feeling Good was authored and prepared by isaf27.

1214H - Tiles Placement was authored and prepared by cdkrot.

Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
  • Проголосовать: нравится
  • +84
  • Проголосовать: не нравится

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

Я решил D совершенно по-другому: я пытался дойти до точки максимально "справа" и максимально "слева" и смотрел есть ли пересечение путей. Решение тут:60010755, задача засчитана. Может есть контер-тест для такого? Считать все возможные пути и авторское решение выглядят сложновато.

  • »
    »
    7 лет назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится +3 Проголосовать: не нравится

    Я сделал дфс, где для всех точек из которых достижима $$$(n, m)$$$ добавить +1 к $$$way[dist]$$$, где $$$dist$$$ — дистанция от точки $$$(1, 1)$$$.

    После чего сделаем $$$ans = min(ans, way[i])$$$ для всех $$$1 \le i \le n + m - 3$$$ (дистанции $$$0$$$ и $$$n + m - 2$$$ проверять не надо — таких точек всего по одной, это 1;1 и n;m).

    Собственно это упрощённое авторское решение — если какой то $$$way[i] == 1$$$, значит все пути проходят через эту точку (нет альтернативы на такой дистанции от 1;1) и можно её заблокировать.

»
7 лет назад, скрыть # |
Rev. 6  
Проголосовать: нравится +10 Проголосовать: не нравится

Alternative solution for D: Treasure Island if you're using a language where sets and tuples can be expensive (e.g. JVM), is to simply convert the grid to a 2D character array. Then you can iterate through the array twice, once in forward order, once in backward order. The first time, you mark $$$(1, 1)$$$ with e.g. a '0' character, and "spread" the '0' characters over the '.' characters. The second time, you do the same from the goal backward, except changing from '0' to '1'. Now the '1' characters represent the intersection of the two sets of accessibility.

It's basically a BFS/DFS variant that isn't actually either, but rather "reading-order first", taking advantage of the fact that successors always come later in reading order.

Sample code in Kotlin: #60063170

Problems like this and #1195E OpenStreetMap really makes me wish Project Valhalla was out already. Either that or it's time for me to learn another language :P

»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

я решал D почти схоже с этим но у меня WA что я делаю я сначала смотрю можно ли добраться из (1, 1) до (n, m) и если нет то ответ сразу 0 после нахожу все точки сочленения и сохраняю их затем я смотрю все (x, y) к которым можно добраться из точек (1, 1) и (n, m) затем перебираю все сохраненные ранее точки сочленения и проверяю входят ли они в ранее проверенные позиции достигаемые с начального и финишных точек если нет то убираю их из списка точек сочленения в конце после проверки если остается хотя бы одна точка сочленения то ответ 1 иначе 2

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +23 Проголосовать: не нравится

An easier solution for D:

You just need to run a maxflow.

My code: https://mirror.codeforces.com/contest/1214/submission/59996918

Sorry for my poor English.

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +26 Проголосовать: не нравится

A really simple solution for D: just run a dfs and check if the destination is reachable and mark all nodes you saw. For every path you find like this you can increase the result by one. 60075870

This solution works since the corresponding graph is planar, the start and destination both lie on the outer face, and the dfs is in fact a so called "right-first-dfs".

»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

D can actually be easily solved using Dinic's algorithm in O(N*M). At first, it's clear that max flow from (1, 1) to (n, m) will be the answer, as max flow equals min cut, which is exactly what we need to find in the problem. Now, here's why Dinicz will find max flow in this graph in O(N*M). All the edges' capacity is 1, so one faze of the algorithm will work in O(M), where M is the amount of edges in the graph. The other thing is that Dinicz will stop after the first faze. Each faze lengthens the shortest path from S to T int the net, meanwhile in this one all the paths are the shortest.

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

Was ternary search by the position of the pair of the first element in F an intended solution?

  • »
    »
    7 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    Normal ternary search is just not correct. For example on test:

    10 20
    2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 5
    10 10 10 10 10 4 4 4 4 4 4 4 4 4 4 4 5 4 4 4
    

    Solution 60008635 (AC on round) don't work. Because a lot of offsets give the same value, and this value is not optimal.

    However there are some other implementations, for example 60002491. There the search is for the number of people crossing 0=M bound, And for some values it calculates not the optimal score, but smth larger. And I'm curious how to challenge it :)

»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I see a submission using ternary search in F, why is it works? 60035603

»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

An alternative solution for D:: Use top down or bottom up approach to find the points (r,c) which can access (n,m) => those points which can traverse freely to (n,m). At this point we do not care where to create blockages.

Then observe that if we block any of the diagonal (0,0) gets cut off from (n,m). We use this fact and the information we extracted earlier to find the ans. Then use BFS from (0,0). Create a diagonal list say dp[]. As we are traversing each element, if the element (x,y) can access (n,m) we add 1 to dp[x+y].

Then we recur over this dp and find its minimum. That is the answer. https://mirror.codeforces.com/contest/1214/submission/60144916

»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

For the problem 1214D - Treasure Island, I'm getting a TLE on test 19 — 60144500. Can somebody please help me identify the error?

  • »
    »
    7 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    there are many things you should change (but the tle is probably due to huge constant factors...):

    try to avoid a set if it will contain 10^6 elements (which can happen if I understand your code correct). 10^6 elements in a set are really much...

    don't use new and delete in competitive programming. Use a vector and let it do the allocations. (this makes writing code much simpler)

    don't use pointers. Use references. (again this makes things for competitive programming easier to write and we almost never need pointers)

»
7 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

A can be solved in O(dlog(d))

My submission

»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can A problem be solved in O(1)?

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

I problem D what is the meaning of this statement "f answer is one, there must exist such cell (x,y) that each path from (1,1) to (n,m) goes through that cell. Also we can notice that in each path the cell (x,y) goes on the (x+y−1)th place."

»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Isn't the pic from the H editorial incorrect? There is a path 1->2->1 on the left of the diametr. Overall the editorial isn't clear. When we repeat the algorithm recursively, do we proccess it on each subtree coming out of the diametr?

»
7 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +3 Проголосовать: не нравится

Yet another solution to problem D — no graph algorithms required! Precompute $$$d_{i,j}$$$ — whether $$$(i,j)$$$ is reachable from $$$(1, 1)$$$. Now, greedily find two paths from $$$(n,m)$$$ to $$$(1,1)$$$, one where you prioritize moving along the x-axis, and another one where you prioritize moving along the y-axis. If these two paths intersect somewhere other than in $$$(1, 1)$$$ or $$$(n, m)$$$, you can block that cell and the answer is $$$1$$$, otherwise it's $$$2$$$.

Code: 60184416

  • »
    »
    7 лет назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    Nice solution!
    But why does it work?
    Can you please prove it (just the greedy part)?

    • »
      »
      »
      7 лет назад, скрыть # ^ |
       
      Проголосовать: нравится +14 Проголосовать: не нравится

      Proof by AC :)

      Just kidding, one direction is obvious, if this algorithm finds two disjoint paths, then clearly the solution is 2.

      The other part is not so obvious. It's enough to show that if the two greedy paths intersect, then every valid path has to pass through these intersection vertices. This is exactly the definition of a blocking vertex.

      I will show that all valid paths lie between the lowest and the highest path. Assume the contrary — some part of a valid path "sticks out", say, it sticks out below the lowest path. We can use this part which sticks out to find an even lower path, meaning that our original lowest path was wrong, a contradiction.

      This means that every path has to pass through every intersection vertex, because that's the only vertex between the two paths.

»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

For D, I have written a code which similar to "Permeability of soil" problem.

But I am getting WA. Can someone help me with it? 60012934

»
7 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I have been trying to pass problem D with the following approach: Check if there is not a path between (0,0) and (n-1, m-1), then the answer is 0. Check if there is not a path between (0,0) and (n-1, m-1) without using articulation points, then the answer is 1. Otherwise the answer is 2. Submission: https://mirror.codeforces.com/contest/1214/submission/61191311

I can't figure out my mistake on code,can anyone help me?

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can anyone explain me B question. I can't understand the test case

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

An alternate solution for problem D, Just block any whole path from ({1,1}->{n,m}) and if afterblocking all cells of that path you can reach target from source then answer can never be 1 it must be 2.

»
4 месяца назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Sorry for my poor English and necroposting.

Alternative solution for D. Create a graph consisting of valid paths, now our task is to find such node that removing causes $$$(1, 1)$$$ and $$$(n - 1, m - 1)$$$ to disconnect. We can use D&Q and DSU rollback for this, let $$$[l, r]$$$ range mean that we are considering all edges excluding edges that have endpoint of node in range $$$[l, r]$$$ then if we are at leaves, we simply check whether they are connected or not.

Submission: 361180231