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

Автор vovuh, история, 7 лет назад, перевод, По-русски

1133A - Middle of the Contest

Идея: MikeMirzayanov

Разбор
Решение

1133B - Preparation for International Women's Day

Идея: MikeMirzayanov

Разбор
Решение

1133C - Balanced Team

Идея: MikeMirzayanov

Разбор
Решение

1133D - Zero Quantity Maximization

Идея: BledDest

Разбор
Решение

1133E - K Balanced Teams

Идея: MikeMirzayanov

Разбор
Решение

1133F1 - Spanning Tree with Maximum Degree

Идея: MikeMirzayanov

Разбор
Решение

1133F2 - Spanning Tree with One Fixed Degree

Идея: MikeMirzayanov

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

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

Explanation of f2 is copy-paste of f1, please fix it

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

F2 tutorial is missing (F1 has been repeated). Also, The problem F1 really should've been ahead of the problem E (if you want to sort the problems according to their difficulties).

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

vovuh , F2 tutorial is missing

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

Can F2 be solved by finding articulation edges / bridges in the graph and as soon as we find bridge edge we merge them and after that we pick any random adjacent edges of vertex 1 so as to make its degree exactly d. and after make the whole tree connected using kruskal type algorithm? Here is my submission for reference of what i am talking. I am getting wrong answer on test 37. Pls tell if i am wrong. Thanks

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

    The idea for F2 is that if we remove vertex 1 then the graph will be K components and if K > D there is NO answer otherwise we should connect this K components with D edges after that we can choose any MST of the remaining graph.

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

    hope this test case will help you to understand why you are getting wa :) 7 8 4 1 2 1 3 1 4 1 5 1 6 1 7 7 6 5 4

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

    The problem is that bridges tell us only that if that edge is removed,the graph will become disconnected, if u remove some set of edges which are not bridges it is still possible that the graph may become disconnected, that is why the above logic doesn't work.

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

Turns out that my solution for D with maps having long double keys passed. I checked the test cases and would suggest the problem setters to do the same too. From what it appears, the cases seem weird. I've linked a screenshot regarding my concerns.

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

why does this solution gets TLE whereas this solution gets Accepted?

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

MikeMirzayanov you Have Mistakenly provide E question tutorial in F question. Can you please explain 1133F2 — Spanning Tree with One Fixed Degree solution idea.

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

"How to do transitions from dpi,j? The first transition is pretty intuitive: just skip the i-th (0-indexed) student. Then we can set dp[i+1][j+1]:=max(dp[i+1][j+1],dp[i,j])."

i think it should be dp[i+1][j] as by skipping ith student we are not increasing size. MikeMirzayanov

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

    I think it's a typo. It should be dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j+1])

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

    I also stumbled upon this, will wait for the clarification of right transition..

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

      I'll will put the way I interpreted it.

      When you are in a given state (i , j) (where the students in [1,...,i] are the possible students you can use and 'j' is the maximum quantity of teams you can use) you have to take the best between pick or not the student 'i'.

      When you dont't pick student 'i' you will have to pick the solution for the case in which you have the students in [1,...,(i — 1)] as possible students to take and 'j' as the maximum quantity of teams you can use. This describe exactly what is in the state (i — 1 , j).

      When you pick student 'i' you have to see what is the best way to pick it. So you look at the states when you allow (j — 1) teams as maximum quantity of teams and students in [1,...,z] (with z <= i) as possible students (states of the form (z , j — 1) with z <= i). When you pick a state like that you could create a new team and put the maximum quantity of possible students (which are in [(z + 1),...,i]) in it to get a candidate for the state (i , j). But remember that you want the student 'i' to be in it. So you want to see only states (z , j — 1) (with z <= i) such that you could create a new team and put all students in [(z + 1),...,i] in it.

      With a good care this can be done in O(n*k): 51128813

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

I will fix F2 tutorial in a few hours. Please wait a bit.

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

In D, why we should ensure numerator is non-negative?

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

@Vovuh How is ur editorial of F2 different from this? . Aren't they same?

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

In div2 D, Why does use of unordered_map gives a TLE but normal map works fine ? Solution 51071398 gives TLE with unordered_map but this 51071641 gets Accepted with map

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

How to do problem C using binary search?

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

For problem D we can prevent precision error by using BigDecimal for example in java, the largest fraction is 1000000000 / 999999999 = 1.000000001000000001000000001, the numbers after the 1. well represent the rounding we will use inside the BigDecimal class, 51105537

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

In E. Why can't we just simply use two pointers. My idea is to sort this array then use two pointers as below a[n+1] = 2e9; for(int l = 1, r = 1; l <= r && r <= n+1;) { if(a[r] — a[l] <= 5) r++; else{ len[m++] = r-l; l = r; } } sort(len, len+m, greater()); for(int i = 0; i < k; ++i) ans += len[i]; But I get wrong answer on test 25. Can some one help me?

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

DP in editorial for E is something different from its definition.

In that solution we just skip intermediate students (i, i + cnt_i), but in this case dp[i + z][j + 1] (z = 1 ... cnt_i — 1) is not increased as it should be.

Consider following example: n=3, k=1 a[] = 1 1 1

Then editorial code outputs: dp[i][j]=

0 0 
0 0 
0 0 
0 3

But by definition dp[1][1] = dp[2][1] = 1, because we form one team from these students.

Can someone please explain what dp[i][j] really stands for?

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

can E be solved using divide and conquer after sorting?

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

Can anybody tell me why this solution got TLE my submission

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

Can someone explain why the maximum number of students is possible only when there are exactly k teams as written in the solution for E?

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

f2 is missing!

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

my solution for F1 https://mirror.codeforces.com/contest/1133/submission/51458164 is giving correct output on my computer but I am getting wrong answer on codeforces. I am not able to understand the reason. Can anyone help me out ?

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

In problem E, why can't we just loop k times, in each loop get the team with max members under the given condition, take the remaining students and continue till k teams are formed. My submission

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

Can any one help why my binary search solution isn't working? https://mirror.codeforces.com/contest/1133/submission/55474924

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

    When passing a vector to a function, you should pass it by reference, otherwise it may lead to TLE, just like it did for you (read more here). Also, in your binary search function, you do not define your variable "ans" when you create it, which can be problematic if you never set the value during your binary search.

    I would also suggest using standard C++ lower_bound or upper_bound functions when doing a binary search on a sorted array (or in your case, a vector). It might take some time and practice to learn how to use them but it will be really useful and you won't have to write your own binary searches when it is unnecessary.

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

For 1133E — K Balanced Teams, I've used a backward DP that's my best friend, unlike the forward DP given in the editorial.

Here is my submission.

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

    Can you explain your solution?

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

      It's pretty much like in the editorial. The $$$cnt_i$$$ in my solution represents the number of students in a team, if the $$$i^{th}$$$ student is the last one in it.

      And the dp goes in the similar manner. The $$$dp_{i,j}$$$ represents the maximum total number of students, in upto j teams, while considering the first $$$i$$$ students.

      You can decide to take or not take a student, and the dp simply states that, in the for loops.

      It's been 3 months so I had to look into the solution itself again to understand what I'd done. Do let me know if you need more clarification.

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

Can someone help me figure out why am I getting TLE. I have written almost the same code as in the solution provided.84302770

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

    You can solve that problem C by map easily.

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

Why in solution he shuffles the output ?

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

My idea forD, we can simply store -bi/ai in long long double in a map and then iterate to find the value for which maximum indices have the same value and it shall work https://mirror.codeforces.com/contest/1133/submission/264512885

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

    Sounds good,but I found a slightly different way to think about it.It's a bit more of a greedy "expand and re-base" strategy. ​After sorting the skills, I use two pointers, k and i. Pointer k holds the first student in my current team, and i is the one I use to look for new members. As long as the current student a[i] is within 5 points of skill from a[k], I add them to the team, essentially expanding my window. ​The neat part is what happens when a student a[i] is too far away. Instead of the typical window-shrinking, I just save the size of my best team so far, move the starting pointer k forward, and then backtrack i one step. This lets me check that same student a[i] again, but now with the new, more skilled student at a[k] as the team's anchor.More clearly I'm trying to build the longest possible team from the current k.Here is my code with O(N*logN)time complexity

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

Vovuh can stay on top of the contributors table just by organizing 1/2 Div. 3 rounds per month xD