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

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

Привет! В 05.08.2020 17:35 (Московское время) начнётся Codeforces Round 661 (Div. 3) — очередной Codeforces раунд для третьего дивизиона. В этом раунде будет 6 или 7 задач (или 8), которые подобраны по сложности так, чтобы составить интересное соревнование для участников с рейтингами до 1600. Однако все желающие, чей рейтинг 1600 и выше могут зарегистрироваться на раунд вне конкурса.

Раунд пройдет по правилам образовательных раундов. Таким образом, во время раунда задачи будут тестироваться на предварительных тестах, а после раунда будет 12-ти часовая фаза открытых взломов. Я постарался сделать приличные тесты — так же как и вы буду расстроен, если у многих попадают решения после окончания контеста.

Вам будет предложено 6 или 7 (или 8) задач и 2 часа на их решение.

Штраф за неверную попытку в этом раунде (и последующих Div. 3 раундах) будет равняться 10 минутам.

Напоминаем, что в таблицу официальных результатов попадут только достоверные участники третьего дивизиона. Как написано по ссылке — это вынужденная мера для борьбы с неспортивным поведением. Для квалификации в качестве достоверного участника третьего дивизиона надо:

  • принять участие не менее чем в двух рейтинговых раундах (и решить в каждом из них хотя бы одну задачу),
  • не иметь в рейтинге точку 1900 или выше.

Независимо от того являетесь вы достоверными участниками третьего дивизиона или нет, если ваш рейтинг менее 1600, то раунд для вас будет рейтинговым.

Спасибо MikeMirzayanov за платформы, помощь с идеями для задач и координацию моей работы. Спасибо моим очень хорошим друзьям Дарье nooinenoojno Степановой, Михаилу awoo Пикляеву, Максиму Neon Мещерякову и Ивану BledDest Андросову за помощь в подготовке и тестирование раунда. Также спасибо Артему Rox Плоткину и Дмитрию _overrated_ Умнову за обсуждение идей и тестирование раунда!

Удачи!

UPD: Огромное спасибо Ивану Gassa Казменко за тестирование раунда и исправление некоторых проблем в условиях и в раунде в целом!

UPD2: Разбор опубликован!

  • Проголосовать: нравится
  • +424
  • Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится -135 Проголосовать: не нравится

sweeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeet

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

<almost-copy-pasted-part>

»
4 года назад, # |
  Проголосовать: нравится -99 Проголосовать: не нравится

This is a new announcement ?!?

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

»
4 года назад, # |
  Проголосовать: нравится -13 Проголосовать: не нравится

is it rated?!

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

Good frequency of contests in August.

»
4 года назад, # |
  Проголосовать: нравится -14 Проголосовать: не нравится

10 MINUTE PENALTY

oh no...

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

When you understand,, 6 CF contest in next 12 days..Feeling be like °(^▿^)/°

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

What a frequency of contest! That makes me love codeforces. We already have 6 contests this month and now we get one more. When comes to frequency codeforces have no match. It might be possible we will some more contests except currently showing in the calendar like this one.

»
4 года назад, # |
  Проголосовать: нравится -19 Проголосовать: не нравится

You forgot %almost-copy_paste/>

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

This will be my first unrated div3 contest :) I hope one day I will say my first unrated div2 contest.

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

.

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

    No :)

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

    Yes, the round is rated for anyone below 1600 rating, including those who are still unrated/haven't participated in any rated rounds.

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

    Greetings everyone, I, as the writer of this comment and a completely new account that is obviously not an alternate account of another very high rated person on the platform Codeforces, find the website of codeforces.com particularly confusing and novel. Because there seems to absolutely nothing in the statement that tells me if this round has a probability of affecting my rating, I request that one of the more experienced members such as (insert annoying tags of lgm) tell me if the codeforces round of the number 661 variety could possibly have a nonzero probability of affecting my rating

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

This will be my first rated contest :/

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

Good Luck Everyone!

»
4 года назад, # |
  Проголосовать: нравится -10 Проголосовать: не нравится

I'll be competing in this contest as well and is it okay to get cold feet? Is there any tips that anyone wants to suggest will be a big help.

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

    There is no need to worry about anything. In fact, nobody cares if you participate or not, or for your results. Just relax, and enjoy the time.

»
4 года назад, # |
Rev. 2   Проголосовать: нравится -30 Проголосовать: не нравится

!

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

Waiting for short and interesting problems.Good luck and have fun!

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

Question: What if my presented rating is lower than 1600 but my real rating** is over 1600 (which it is)? How will my rating be calculated?

**Real rating: after the update to rating for new users, it says specifically what rating is used for calculation and what it being presented. My actual rating, which is used for calculation, is over 1600.

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

    Register the contest. If you are contestant then you are rated. Unrated if you are Out of Competition.

    I think you'll be rated if your presented rating is lower than $$$1600$$$.

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

    is there a way to see your hidden rating?

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

To all the bhagwa holders ..... Jai Shree Ram . Wish you all high ratings on Hindutv Divas

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

"Note that the penalty for the wrong submission in this round (and the following Div. 3 rounds) is 10 minutes." Can someone please explain what this means?

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

    For any wrong submission you will gain 10 minutes penalty. Penalty is used to rank contestents with same number of solved problems.

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

"A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. A parent of a vertex v is the last different from v vertex on the path from the root to the vertex v. Children of vertex v are all vertices for which v is the parent. A vertex is a leaf if it has no children. The weighted tree is such a tree that each edge of this tree has some weight."

Why dont you include this in the end ? Almost Everyone knows what a tree is.

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

Nice problemset!

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

again long queue issue!!

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

long queues plz fix ASAP

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

This my best ever performance, please it shouldn't be unrated...

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

Codeforces for 3/4 of the contest and Queueforces for the last 1/4 :(

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

Plz fix long queue mike, this is ruin all 2hrs hard work. It is worst than occurring at the start of the contest.

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

Queueforces Reloading....

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

+15 min will not help much as every minute is counted while evaluating.

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

    but it will not let hard word of people be soiled like mine. what else do you expect?

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

For past 1.5 hours, I was trying to solve problem E1 and E2 thinking that path weight for each leaf has to be less than S. :Facepalm:

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

    Exactly Same Bro.

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

    I also thought the same

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

    I coded the solution of E1 thinking this was the problem. Then noticed that, the second sample case doesn't match with my "correct" output.

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

      Yes, same here. Can you share your approach for the wrong problem we were trying to solve?

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

        Deleted

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

        Run a dfs and maintain a set of all ancestor edges. After reaching a node, while the sum of this set is greater than S, remove the largest element (and subtract from our current total) and insert the halved element (and sum up with our current total). Code

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

          I am not sure if that will always give the most optimal. The problem here might be- you are not taking advantage of the edges which are near to roots in any ways(reducing them will have benefit on more number of paths).

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

            During the contest, I didn't prove the solution that came to my mind. And yes, you're right. It's not optimal. Here's a test case:

            1
            4 2
            1 2 1
            2 3 2
            2 4 2
            

            My code will output 2 but in the optimal solution we can halve just the first edge.

            By the way, what was your solution?

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

        My approach was a little high on memory, first for each leaf node I made a list of all the edges which make up the path for that leaf node and then sort all the nodes in each path by there their weight and then traverse this list of paths. In order to fix the path in the current iteration, start performing operations from the back for each path(as it has got the highest weight in that path) until its sum is less than s. We'll precompute the sum for each path beforehand obviously.

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

        What do you think would be the best intended solution for that?? I was able to come with a solution of complexity O(log(n)*n*n) but couldn't optimise further

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

          Can you share your idea. I was unable to come up with any solution that runs in polynomial time.

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

            The maximum possible number of moves is n*log(1e6) and for each node, the maximum possible move is sub[node]*log(1e6)... considering all possible decompositions, what I intended to return was a vector of size(maximum_no_of_moves for each node) and using dp to build the optimal answer for the parent node over all its possible decompositions.

            Since sigma(sub[node]*log(1e6)) is O(n^2*log(n))... the intended time complexity was O(n^2*log(n))

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

      same here. answer for that version was 6, right?

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

    Same here bro, just read the problem again after reading your comment , maybe its high time for me to get glasses

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

    I do not get it. We had to find the minimum number of moves in which we select an edge and divide its weight by 2, such that at the end, path weight from root to all leaves is at most S. Is that not it? Or I misunderstood the question? Because for some reason, I cannot understand why that second TC has answer of 8.

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

      okay, I just realised what an idiot I was for misreading the question. But seriously, can that line sum of weight of ALL paths not be made bold? I am sure a lot of people like me could not do it because of that.

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

        Wait, it was ALL PATHS ?:/( Same boat)

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

        i still dont understand the problem, can you explain please?

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

          I hope you read it once.
          What they meant was find weight of path from root to all leaves. Let us say the sum of all weight of ALL these paths is s. You have to reduce it to below capital S (which is given in the input). And what a lot of people(like me) understood was, reduce the weight of each path from root to leaf SEPARATELY to a value less than S.
          I hope you understood

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

            oh ok i think i understand now, i had a similar misunderstanding also

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

            actaully im still a bit confused. In sample 2 there are two leaves, 2 and 4. The sum of the weight of the two edges connecting root and leaf 2 is 223, and root to leaf 4 is 65. The sum of these two is 288, which can be reduced to less than 50 in well under the 8 moves. So i still dont quite understand.

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

              it is 8 moves. You will have to use a max priority queue. So, each time pick the edge with most weight, divide by 2 and insert it back and keep doing it till total sum is less than S. In this case the sequence will be — 123 -> 100 -> 61-> 55 -> 50 -> 30 -> 27 -> 25. After this edges will be having weights as 15,10,13,12 which makes the sum = 50.

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

    Looking for the solution in the comments and saw this, I feel so dumb...

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

    Same lol, was thinking why is the third hardest problem in a Div3 contest that hard.

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

Comparing last few contest problemset,This one is well distributed.Awesome

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

I think D was a subproblem of 1370E - Binary Subsequence Rotation.

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

ABCD is simple and good.

E2 is a good problem after E1.

661.png

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

How to solve E1?

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

    After calculating the value just greedily take the vertex that gives biggest delta(v). delta(v) = (num[v] — num[v] / 2) * leaves[v] where leaves[v] = number of leaves in subtree of v.

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

    Run a DFS to store, how many leaves are there in the subtree of a node

    Now store {impact, index} of each edge in priority queue

    impact for edge {a,b,w} (a is parent of b) is $$$sub[b] * (w - \frac{w}{2})$$$

    Greedily calculate the answer.

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

      I did the same thing, yet I got tle.

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

      I implemented my solution using a priority queue like you said and it was accepted. However, during the contest I used a list for all the possible moves and sorted it once and then did greedy, but I got TLE. Any reason for why adding the edges into a priority queue and then popping is significantly faster than adding to a list and sorting at the end? If I'm not mistaken both should be O(n*log(n)) time complexity.

      I'm also using Python which could slow down my times, but priority queue implementation was still much faster...

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

what was your approach for D?

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

    you can solve it using std::set

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится -12 Проголосовать: не нравится

    Binary Searcch! IF number of subsequence is k and the answer exist then with k+1 subsequences partition to the answer exist , this was key intuition behind this problem.

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

      Can be solved in O(n) by greedily placing each digit.

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

      How did you check for each k ?

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

        Take an array of the current k size b[k], visit each index of the array abs see current known subsequences end with '0' or '1' if the current index is '0' and currentsubsequence i is also ending with 0 then you have to use a new subsequence. this way iterate whole sequence and at each iteration count how many subsequences are formed till now. this value is always equal so no need of binary seach , thus it is solvable in linear time read comments above.

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

    Maintain two sets v[0] and v[1](initially both empty). v[x] denotes the set of all those subsequence ids for which the next expected number is x. Iterate through the string. Let's say the current bit is 0, then if v[0] is non-empty, take out one of the element of v[0] and put it into v[1]. If v[0] is empty, create a new subsequence and insert it into v[1].

    Time complexity: O(n) using vector.

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

    At any point you should be knowing if a particular sub-sequence is having 0 or 1 as its last element

    this can be done with the help of set. Just make 2 sets for 0 and 1

    Then when iterating through string if the element we need to work on is 0 than check if there is any sub-sequence with last element 1. Than we can insert 0 in that sub-sequence than update our set of 0 and 1. If no such sub-sequence exist than find the maximum sub-sequence we are having right now and add 1 to it and update our sets one again.

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

      looks pretty cool can you explain the logic?

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

        I used 2 std::queue to store the subsequences that currently end with 0 or 1. Iterate over string, if it's a 0 and queue of subsequences ending in 1 is empty then you need a new subsequence, so assign this digit to the new subsequence,new subsequence number is num and add the num to queue of zeros, if the queue of ones is not empty then you can add this digit to any subsequence stored in queue of ones (use q.front()) and then you need to pop this sequence number from one and add to zero. because you just added a 0. Do the same in case you encounter a 1.and always save the answer of ith character to ans arrays ith position which is num.

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

My Video Solution for Problem C Problem D

»
4 года назад, # |
  Проголосовать: нравится -8 Проголосовать: не нравится

Editorial please!!!!

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

Can someone help me, please. I cant understand why i get WA on test 2 on D

89051411

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

E2 and F are nice questions, looking forward to solving them in practice.

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

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

E1 anyone please?

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

Probably I haven't managed to understand the problem statement but why is the solution of the second graph in problem E1's example 8? I mean we have 1-3: 100, 2-3:123, 1-4:10 and 4-5:55 If we make 100->25(2 steps) 123->15(3 steps) and 55->27(1 step) then 1-4-5 is 37 and 1-3-2 is 40 which is below the s = 50 limit and it's 6 steps altogether which is less than the claimed solution of 8. Am I missing something here?

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

    The sum of the weights of all paths from the root to the leaves should be at most $$$S$$$.

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

      Ah, not each of them root to leaf path individually but the sum of them all. Ah why can't I read the problem statement... Thanks for the clarification!

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

For E1, I got TLE. The idea was to find how many leaves each node has and do a weighted sum accounting for those leaves (so real_weight[vertex] = weight[edge_to_vertex] * number_of_leaves[vertex]). In the end, I stored the elements in a set and kept reducing the largest element by a factor of 2.

Could someone suggest what could be causing the timeout issues? Link

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

Did anyone get WA on test 2 on problem D ?

edit — Shit I forgot an 'else' keyword :'D

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

How to solve E1 ?

I used priority queue but it gave WA in test set 2. If possible, you may look into my code. Thank you in advance.

My E1 solution
  • »
    »
    4 года назад, # ^ |
    Rev. 3   Проголосовать: нравится +26 Проголосовать: не нравится

    I made the same mistake, at this line: PriorityQueue<long[]> pq = new PriorityQueue<>((o1, o2) -> (int) (o2[1] * o2[0] - o1[1] * o1[0]));, your comparator should maximize the amount reduced per operation, (weight of edge + 1) / 2 * number of leaves in subtree, not the amount the edge is currently contributing to the sum. There's a difference between the two.

    My Submission

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

I solved E1 using priority queue using a custom comparator function. Can I use a similar approach with 2 priority queues(one for each cost type)? Please help a bit!

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

Nice problems! Thank you for great round! Waiting for editorial :)!

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

Hello! Firstly, i want to say that in my opinion this was one of the most balanced rounds that were recently organized and it had a really good problemset so i enjoyed it a lot, nice work! Then i wanted to ask the community whether this extension for rating prediction works good and determines correctly the rating change after a round : https://cf-predictor-frontend.herokuapp.com/.

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

Do we get the editorial after the hacking phase?

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

My greedy implementation of D was too messy and I couldn't even pass the sample test cases. Is there a cleaner implementation of D?

»
4 года назад, # |
  Проголосовать: нравится -8 Проголосовать: не нравится

Kudos to BledDest and MikeMirzayanov por excellent round coordination!

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

Kudos to BledDest, Gassa and MikeMirzayanov for excellent round coordination!

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

And as usual Python screws me over with TLE in E1 after a textbook solution.

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

I approached problem D using binary search and set data structure but it TLEd unfortunately. I just wanted to know if my implementation was wrong or it was just too slow to pass the time limit. I kept two different sets for indices of ones and zeros. I take the smallest index from one set and then binary search the next index from the other set until there are no more elements that can be assigned to the same subsequence. Here is my submission link.

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

Why regular codeforces.com not opening from laptop? I cannot open the site for last four hours. I had to even give contest on m1.codeforces.com and writing the comment from phone. It still isn't working. Is it only me or anyone else?

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

Very nice problemset

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

Why dsu didn't work in problem F.

My submission 89050221

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

    Idk what ur approach is but it's supposed to be pure dp. Maybe you are allowing segments to intersect inside of one?

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

      i am finding all invalid pair and add a edge between them ...then i am finding the maximum independent set;

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

How to solve E2 ?

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

    I can try to explain and prove my solution ^_^

    Let's define impact of an edge as $$$(w-\left\lfloor\frac{w}{2}\right\rfloor)*l$$$, where $$$w$$$ is the current weight of that edge, and $$$l$$$ is the number of leaves in the subtree of that edge. So $$$w$$$ occurs in sum $$$l$$$ times.

    Now let's find out, after performing, say, $$$i$$$ moves on edges with $$$c==1$$$ and $$$c==2$$$, the maximum sum of impact we can obtain. The resultant sum obviously decreases by sum of impact.

    Now, we do dp. $$$dp[i].first=max(dp[i-1].first+b1[dp[i-1].second.first+1], dp[i-2].first+b2[dp[i-2].second.second+1)$$$

    where, $$$dp[i]=$$$ {maximum sum of impact for cost $$$i$$$, {number of moves with $$$c==1$$$ type edges, number of moves with $$$c==2$$$ type edges}}

    $$$b1[j]=$$$ maximum sum of impact with $$$j$$$ moves of $$$c==1$$$ type. Similar for $$$b2[j]$$$.

    Now an insight: The number of moves is bounded above by $$$nlog(nW_{max})\leq50n$$$ for the given constraints.

    So now we can just do linear search and output the answer just when sum$$$-dp[i].first$$$ becomes less than or equal to $$$S$$$.

    Even though DP relation is intuitive, here is the proof:

    Obviously, the $$$j^{th}$$$ move can either be $$$1$$$ or $$$2$$$ type, so we max over those. Now, lets say for $$$1$$$ type, we do not take the $$$(dp[j-1].second.first+1)^{th}$$$ $$$1$$$-type move:

    UPD: A part of the previous proof was wrong. Here is the complete correct proof for the DP recurrence.

    Structure theorem: Let number of $$$1$$$ and $$$2$$$-type moves $$$(n_1[i], n_2[i])$$$. Then for adjacent elements

    $$$|n_1[i]-n_1[i-1]|\leq1$$$

    $$$0<=n_2[i]-n_2[i-1]<=1$$$

    (can be proved by easy induction)

    From here, we can easily compare the optimal solution and the solution of our DP+Greedy.

    This proof took me very long (almost all night) so please upvote if you found it useful ^_^ 89052626

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

      Hi , your explanation was really clear. I came up with a solution inspired from yours, I used your idea to calculate b1[] and b2[] where b1[i] is the maximum impact while using i operations of cost 1 (and cost 2 for b2[i] ).But instead of dp , I binary searched for the number of operations , which is < nlog(nWmax) as you said , for a fixed number of operations , say x , there is x+1 ways to construct a solution : take i + (x-1)mod 2 from cost 1 and (x-i) / 2 from cost 2 with 0 <= i <= x . For each of these possibilities , we can calculate the maximum impact which is y = b1[i + (x-1)mod2] + b2[(x-i) / 2] , if Sum_impact — y <= s for any i then x is valid. It works in O(nlog(nWmax)*log(nlog(nWmax))) Hope i explained it well .

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

        Thanks.

        Actually, what you came up with is coincidentally also the editorial's solution. Also, I have not come across any other DP solution so I hope it passes systests :P (although the proof seems solid).

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

Can someone tell what's wrong in my solution for problem C?

My submission:89060049

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

How to solve F ?

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

will there be a tutorial for this contest like the last one??

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

Can E2 be solved using priority_queue (maintain 2 priority queue each for cost1 and cost0)? I solved E1 using a priority queue. Here is the E1 submission. If anyone had done E2 using priority queue please let me know. Other approaches are also welcomes********

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

    You do same solution as same E1 except with two different priority queues, one for each cost, storing amount in vector after x turns, then just do 2 pointers.

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

    My messy solution for E2 using just greedy approach with 2 priority queues 89027488. Not sure if it really works though.

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

      Can you tell me what I have done wrong. here is my submission it is giving WA on the 21st test case.

      My main idea is to use 2 coins in every iteration so either of priority queue is used and in the end if only one coin can give me total<=S then break or if one 1 coin and one 2 coins can give me summation<=S given that no 2 of 1 coins can be able to do so then break. Isn't this idea has to be working?

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

    E1 and E2 can be solved using the same approach, with some extra work in E2. I didn't use priority queue though. In E1, I sorted all the contribution of all edges. Now the problem is what length of prefix of this sorted list you need to take to make the total weight $$$\leq S$$$.

    In E2, I made two different sorted list, each for one of the two cost types. Now for each prefix length $$$k$$$ of the first list, find out the cost of taking $$$k$$$ moves from this list and remaining from the other list. The minimum cost is the answer.

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

Please tell me what's wrong in my E1 solution

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

My solution for F.

Assume there is an interval $$$[0, inf]$$$ at index $$$0$$$, which we can select into the subset always. Now we can express a valid solution as a rooted tree, where the nodes represent the selected intervals (the root will be interval $$$0$$$). An interval $$$p$$$ will be the parent of an interval $$$u$$$ if $$$u$$$ is inside $$$p$$$ and there is no selected interval $$$q$$$ such that $$$u$$$ is inside $$$q$$$ and $$$q$$$ is inside $$$p$$$. In a valid subtree, the children of interval $$$u$$$ will be non-intersecting. Suppose, $$$f(u)$$$ is the maximum number edges in a valid subtree of interval $$$u$$$. Then the answer to the problem will be $$$f(0)$$$. We can solve the problem with DP.

Let's compute $$$f(u)$$$. Let, $$$C$$$ be the list of intervals that are inside $$$u$$$. Sort them according to the right-bound of the intervals. A subsequence of these list will be the children of $$$u$$$ in the tree. If the rightmost child is the $$$i$$$-th interval in $$$C$$$, the answer will be $$$g(i) = 1+f(C[i])+max_{r[C[j]] < l[C[i]]}g(j)$$$. If we loop over all such $$$j$$$, the solution will be $$$O(n^3)$$$. We can optimize it to $$$O(n^2\log(n))$$$, by noticing that all such $$$j$$$ form a prefix in $$$C$$$. We can keep the prefix max of $$$g$$$ and find the rightmost possible $$$j$$$ for an $$$i$$$ by asking a lower bound of $$$l[C[i]]$$$ on $$$C$$$.

89025065

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

Can someone explain the approach for Problem C-Boats Competition?

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

My video solutions to all problems + screencast (where I placed 17th? place). Sorry for uploading it that late (currently slow internet connection)

Enjoy watching.

https://youtu.be/yWD-Hcl_0Sk

UPD:

After a system testing, I'm 15th

»
4 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
#include<bits/stdc++.h>
using namespace std;


int main()
{
 cout<<1000<<endl;
 for(long long i=0;i<1000;i++){
   cout<<50<<endl;
 for(long long j=0;j<50;j++)
 {
   cout<<1<<" ";
 }
 if(i==999)
 break;
 cout<<endl;
 }
}

why this hack is giving invalid input for problem c?

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

My c++ code is working fine in local ide, but in Codeforces it is showing runtime error on test case 1.Can anybody help me to figure out where is the problem & how to fix "uninitialized value usage" error.Here is my submission link: [https://codeforces.com/contest/1399/submission/89073584]

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

Thanks for the great round!

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

i will be expert after this round .thanks for arranging such a round

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

Извините, а когда рейтинг меняется? Я тут новичок, не очень понимаю почему до сих пор рейтинг не изменился...

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

why my code is giving TLE for E1 can any one help please 89089825

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

    Check for the case 5 100 1 2 10 2 3 10 3 4 10 3 5 10

    If the frequency of nodes visited is correct in your implementation (dfs1). I think the fault is there

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

    Maybe because of map. You can use arrays instead of map.

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

What is the Time Complexity of this Solution ? Can anyone help ? For D : Gave Tle on 6

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

when the ratings will update, i have been waiting for 1 hour. :(

UPD: sorry for my impatience, and thx for this gr8 contest)

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

Can someone look at my solution for problem E1 . Idea is exactly the same mentioned in the editorial but getting wrong answer on test case 5 . Couldn't figure it out myself.

https://codeforces.com/contest/1399/submission/89098897

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

Can someone look at my solution for problem E1 . Idea is exactly the same mentioned in the editorial but getting wrong answer on test case 5 . Couldn't figure it out myself.

https://codeforces.com/contest/1399/submission/89098897

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

My solution for E1 failed system tests on test 21 (WA). I would really appreciate if someone could help in debugging. TIA

Submission link : https://codeforces.com/contest/1399/submission/89036745

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

Can someone help me out with my submission for the E1 problem 89161963. Its producing wrong output for test case 2 and apparently there is some problem with initialSiz( i.e. the variable for deciding if zero moves would suffice).