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

Автор natalina, история, 3 года назад, По-русски

1941A - Рудольф и билет

Автор: daha.002

Разбор
Решение
Оценка задачи

1941B - Рудольф и 121

Автор: Vladosiya

Разбор
Решение
Оценка задачи

1941C - Рудольф и некрасивая строка

Автор: Mordvin13

Разбор
Решение
Оценка задачи

1941D - Рудольф и игра с мячом

Автор: Alexey_Parsh

Разбор
Решение
Оценка задачи

1941E - Рудольф и k мостов

Автор: t0rtik

Разбор
Решение
Оценка задачи

1941F - Рудольф и дисбаланс

Автор: Vladosiya

Разбор
Решение
Оценка задачи

1941G - Рудольф и метро

Автор: natalina

Разбор
Решение
Оценка задачи
Разбор задач Codeforces Round 933 (Div. 3)
  • Проголосовать: нравится
  • +64
  • Проголосовать: не нравится

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

I have seen many people code segment tree solutions for E (including tourist).

Can someone please explain how segment tree was used in this question? PS: I understood the solution explained here using dp.

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

if I want to propose problems to div.3 , how I can do ?

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

Alternate G solution:

Use each subway line as nodes and each station as edges. The trick is to process each station only once.

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

I considered myself a pro at binary search and then problem F happended :/ Nevertheless learned something new. Thanks to the authors.

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

why my state dijsktra to G problem is TLE? 250857953

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

Problem E (Rudolf and k bridges) Video Editorial : Youtube link -- Click here

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

E can be solved in O(n) using deque

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

E can be solved in O(n) using deque

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

I really enjoyed solving problem D. I also think that B wasn't suitable for a div 3 B. C, B or maybe D should've been swapped with each other.

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

Problem C can also be solved with Aho Corasick Automaton. Build a $$$dp[n][m]$$$ where $$$n$$$ is the length of the string and $$$m$$$ is the number of states in the automaton, where $$$dp[i][j]$$$ tells us the minimum number of changes needed to be in state $$$j$$$ of the automaton (which represents some partial or complete matching with some pattern) considering the prefix $$$s[0...i]$$$. It's kinda overkill for this problem, but it's an interesting idea to know. Here's my submission 250707601.

For more details, refer to: CP Algorithms

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

Dislike if you are a ebantuza

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

Oh I solved prob E with just O(n*m) xD

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

    I saw your code but can you explain it to me please ? iam still learning ,thx.

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

      You can calculate the answer for one row in O(m) by using monotone deque (afterward, you can obviously find the minimum amongst all windows of size k in O(n)).

      How to calculate the answer for a row in O(m)?
      • »
        »
        »
        »
        3 года назад, скрыть # ^ |
        ← Rev. 2  
        Проголосовать: нравится 0 Проголосовать: не нравится

        yeah that's right

        the technique I used in that code is to find the nearest element on the left of i (call it j) which a[j]<a[i]

        and i learned it in cses book (it's free in web and it's pretty nice so i think you should learn in that book) — To Gordon

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

    Same, O(m) to find max on bridge, O(n) for each bridge

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

My approach to G was as follows: make a new graph $$$G'$$$ where each node represents an edge in the original graph. There will be an edge between nodes corresponding to $$$(u,v)$$$ and $$$(v,w)$$$, with weight 0 if they have the same color and 1 otherwise. Then I'm doing 0-1 BFS from $$$(b,x)$$$ for all $$$x$$$ which are neighbors of $$$b$$$. Can someone please help me in optimizing the creation of this graph, because currently my method to generate this new graph is giving TLE.

Link to submission — Here

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

Problem E can be solved using deque to calculate the minimum cost of each bridge in O(m), not O(mlogd); so the final complexity will be O(nm) My submission: https://codeforces.me/contest/1941/submission/250832314

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

ABC — average, div-4 level problems.

D — bad, why set a problem about naive simulation at this level? Also, editorial code has a $$$\log$$$ factor that is not reflected in the complexity analysis. It may not sound like a big deal to you, but beginners regularly get confused by such things.

E — bad, unusual distance definition. Also, the editorial solution has an extra $$$\log$$$ factor for no reason. Finding minimums/maximums in a sliding window is a well-known monotonic queue problem with equally short implementation. Div 3 rounds are supposed to be educational for beginners, please live up to the name.

F — bad, the unusual 2e9 limit was unnecessary. What are you, fishing for overflows? 1e8 was enough to TLE all convolution-based solutions, but you may as well have used 1e18 if you really wanted to avoid anything unintended. And once again, binary search is not necessary. Just sort both arrays and use two-pointers.

G — Good.

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

Can someone explain me jiangly's solution for problem G ? What was the approach and what does dist[{e, 0}] mean?

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

what is wrong in this code : https://codeforces.me/contest/1941/submission/250787705

Is my logic wrong or am I missing some edge cases. Please Help me . Thank you in advance!

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

    In addition to considering breaking down the maximum difference $$$(a_{i+1}-a_i)$$$, the second biggest difference between $$$a$$$ elements should also be factored in. Consider the test case:

    3 1 1
    1 7 12
    2
    2
    

    Also, when performing binary search (function f in your code), the boolean that it should answer would be: is there $$$d \in D$$$, $$$f \in F$$$ such that $$$max\left(d+f-a_i \, ,\, a_{i+1}-\left(d+f\right)\right) \leq mid$$$.

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

      can you suggest a way to correct the code or is my approach completely. I tried by myself but I am not getting any idea. Thank you

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

        I made modification to your code (251127599) and it runs correctly.

        To elaborate on how to binary search on getting an optimal split between $$$[a_i, a_{i+1}]$$$: for $$$d$$$ and $$$f$$$ we would want to minimize $$$|(\frac{a_i+a_{i+1}}{2} - (d+f))|$$$. For a $$$mid$$$, we seek $$$d$$$ and $$$f$$$ such that $$$a_i + a_{i+1}-mid \leq 2 \cdot (d+f) \leq a_i + a_{i+1}+mid$$$ If res is the minimum such $$$mid$$$ which satisfies, then the required imbalance between newly added problem and $$$a_i, a_{i+1}$$$ would be (a[i+1]-a[i]+res)/2

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

In my opinion the TL on G was very constrained. I had to switch to deque to make it pass. Was an extra logn deliberately disallowed?

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

    Can u please explain me the editorial elaborately.What are the new nodes created and how to make edges between them?

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

      You've got the original nodes (station vertices) and the newly created color vertices (corresponding to all the distinct colored edges possible).

      Now you draw an edge from the two groups (station to color and vice versa). An edge is drawn from station vertex a to color vertex b if and only if there is an edge color b incident to station vertex a.

      Now you perform simple BFS and report the destination distance/2. Note: You consider the edge weight to be 1. Now think why we divided by 2. Also think how this is a bipartite graph.

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

can someone explain to me this line of code ? for (string sul : {"mapie", "pie", "map"})

i dont understand the code of the editorial why they alwayes make it hard to read for beginners?

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

can someone help with problem E ? i get WA 251001023

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

Regarding problem F: It is relatively easy to see that we must decrease the maximal $$$ diff = a_{i}-a_{i-1} $$$, but my question is, what if there are more than 1 such $$$ j's $$$ where $$$ a_{j}-a_{j-1} = diff $$$. How do we choose which difference to take?

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

For $$$G$$$, I noticed that if a particular vertex has edges of colors $$$(c_1, c_2, c_3 ... c_k)$$$ then the sub-graphs of these colors can be reached by others of this set through at-most 1 different colored edge. So all we need to do is keep track of which "color" belongs which "clusters" (I call each such set a cluster), and vice versa. Then just expand the cloud of visited colors, till we reach a color which is connected to the destination.

As someone who has little math background and is algorithmically weak. I think it is quite intuitive and easier to come up with. Submission-->251004746

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

Why is problem F labeled as two-pointers? Can't think of a solution that uses the two pointers technique.

  • »
    »
    3 года назад, скрыть # ^ |
     
    Проголосовать: нравится +1 Проголосовать: не нравится
    We need to decrese the max gap right (the one having max A[i] - A[i-1])
    Now,we can just insert one element (What it would be!!)
        Obviously mid , mid = (A[i] + A[i-1]) / 2
    
    So indirectly , Question transform to  find (i,j) such that D[i] + F[j] is closest to mid
    This is two pointer right,  (Sort D and F and then find it right)
    
»
3 года назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +14 Проголосовать: не нравится

Very real-life G. In reality the answer is seldom greater than 4,at least in Shanghai, 4 applies to a suboptimal route from Fudan to SJTU: source Fudan U, dest Dongchuan Rd, Fudan U -L18> Jiangpu Park -L8> People's Sqr -L1> Xinzhuang -L5> Dongchuan Rd. But you can choose Zizhu Hi-tech Zone(L15 terminal) as the destination if you want to goto SJTU and reduce the answer to 3.

In Tokyo this answer might be larger

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

I found an interesting solution to the problem G . I reformulate the graph G to G' as follows:

1) Each colour is a node in the graph G'.

2) Each node which is an endpoint of atleast 2 edges of different color is also inserted as a node in my graph. These nodes are special as they "link" 2 different colors. Now for the type (2) nodes I insert an edge E of the original graph , with one endpoint at the node itself and the other endpoint at the color of the edge of our considered type (2) node in the original graph . For example: for the given sample input in the question n = 6 m = 6

(Edge , colour)

1 2 1

2 3 1

5 2 2

2 4 2

4 6 2

3 6 3

In the reformed graph G': Nodes : (color1) , (color2), (color3) , (2) , (3) , (6) Edges : (6->color3) , (6->color2),(2->color1),(2->color2) , (3->color1),(3->color3) Note : 2,3,6 were added as they were part of edges of atleast two distinct colors ,and their edges were added as shown above.

The approach seems long in writing but intuitively its quite simple. Each connected component of a colour is treated here as a SUPER NODE and the other nodes were added to simplify how the colours are connected amongst themselves.

As a multisource BFS is sufficient to find number of minimum colors required to go from set of colors to any particular colors the answer can be found easily.

The link to my submission:251061492

Here for type(2) nodes i insert their negatives , so that they dont collide with the colors. Please excuse me for the messy code.

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

Can someone explain me the intuition behind problem G's editorial?

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

can anyone please help me (i have read editorial & i m still stuck) my approach is getting WA on testcase 2 https://codeforces.me/contest/1941/submission/251049209 thanks in advance

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

    There are two problems here

    • the line if (b[i] > md) break; is wrong.

    consider this test

    1
    2 1 1
    1 100
    98
    1
    
    

    here is the answer is $$$98$$$, but your output is $$$99$$$. This happens because your code ignores any other value greater than the mid. However a pair of number might work but their summation is greater than mid, as in the above test

    • you are also getting the mid value wrong. In your code, int md = a[l] + a[r]/2;.

    Consider, $$$l=3, r = 5$$$, here $$$mid = 4$$$ however your $$$md = 5$$$ which is wrong value

    If anything isn't clear please don't hesitate to ask

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

that was good bruh ok let's go

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

В проблеме C, что если нам нужно удалить подпоследовательность вместо подстроки?

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

D is nice

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

Can anyone pls help me with my solution .idk wht i am doing wrong https://codeforces.me/contest/1941/submission/251038815

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

https://codeforces.me/contest/1941/submission/250877308

I implemented this solution but i am getting wrong answer :( i even checked with the editorial its the same :(

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

Could anyone please help me with the Problem 'C'. I am getting a wrong answer for test 2.

[contest:https://codeforces.me/contest/1941/problem/C]

Please find my submission below: 251308448

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

G просто скопипастили старую задачу с Информатикса. Вот это прикол, конечно

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

.

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

Nice problem E, got my first DP question correct.

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

Don't get terrified of G because it's the last problem, it can actually be solved in less than 30lines of code using simple bfs . it really confused me a while to check my solution because it's typically not that easy for the last question :)

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

Someone pls find the mistake in the code 336416497 for problem 1941F, tried everything