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

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

Привет.

29 марта в Самарском университете состоялась ежегодная олимпиада по программированию (конечно, онлайн), и мы снова выкладываем ее в тренировки Codeforces. Тренировка пройдет в воскресенье, 5 апреля, в 11:00 MSK.

Ссылка на контест
Ссылка на виртуальное участие

Этот контест уже пятый год проводится личным. Поэтому просим всех тоже участвовать лично. Уровень олимпиадников в университете сильно упал, поэтому наиболее интересно должно быть синим и сине-зеленым участникам, но и для фиолетовых и оранжевых тоже кое-что есть.

Список наших предыдущих контестов
Список наших очень старых контестов (возможно, менее интересные, более простые, не переведены на английский)
  • Проголосовать: нравится
  • +51
  • Проголосовать: не нравится

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

Is there going to be any Editorial?

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

Reminder: it starts in 1 hour 30 minutes 10 minutes 1 minute.

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

How to solve L? I tried to write inclusion, exclusion dp just like knapsack using recursion. But couldn't implement it right.

Can you briefly tell what you did? Thank you!

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

    Sort the array $$$a$$$ in decreasing order. Obviously, if you choose to fight exactly $$$k$$$ dragons, it is optimal to take the $$$k$$$ largest amounts of gold, and you will lose $$$k * (k + 1) / 2$$$ on repairs. Now you just have to find the maximum over all $$$k$$$.

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

      Thanks a lot!

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

      It should be also mentioned that

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

I'll describe just the hardest problems. Others are too easy and everyone should have solved them. Anyway, if you have questions, ask them and someone will answer (hope not me).

The hardest problems

Oh, and this is the video of unfreezing and the editorial in Russian by Slamur: https://www.twitch.tv/videos/578322224

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

    Hi,can u explain this line " Why from n, not from 1? We do that, so that there always be only one next vertex when we will go from 1 to n in the next part of solution". and provide the source code to understand it better and some similar problem or topic. Thanks.

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

      I updated it, and this is the solution: https://pastebin.com/mzSvFaVp

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

        Thanks for providing solution, can u explain this "**Why from n, not from 1? We do that, so that there always be only one next vertex when we will go from 1 to n in the next part of solution**"

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

            In this example vertex (4,3) was put in same layer but vertex (1,2) put in same layer or not as this property{ the i-th layer contains all vertices y, such that for all vertices x from the layer (i-1) the equality d[x] == d[y] + 1 holds.} condition is not satisfied. so can u tell how layers are formed in this example. Thanks.

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

              d[1] = 2 (path 1-3-5), d[2] = 2 (path 2-4-5), so the edge 1-2 is not processed at all — it doesn't lie on any shortest path.

              And three layers are just {1}, {3} and {5}.

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

    "How to deal with TL? There are three parts of solution which give log^2: coordinates compression, events sorting and Fenwick tree. We will get rid of the first two, leaving only log^2 from Fenwick"

    What is the point of making constant optimizations ? The difficulty of the problem is not how wtf it would fit in 2 seconds, instead of write some decent $$$O(n $$$ $$$log (n)$$$ $$$log (4*10^8))$$$

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

      Because they give x7-x8 boost all together. My first solution worked a bit more than 4 seconds, and the last solution with all these improvements — 0.5-0.55 seconds. This is a huge speedup, deserving to be kept.

      You will still get accepted without doing all of them. One of those two optimizations is enough. Some participants wrote another (better) approach to process events, it doesn't require additional log and passes too.

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

        Just my opinion: I think that the main purpose of the time limit in a problem is to differentiate a $$$log^3$$$ from $$$log^2$$$ or $$$log$$$ from $$$log^2$$$ etc... not force the contestant to do constant optimizations...

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

          If I kept my first solution, with TL = 2 * author TL = 8 seconds, who knows what trash could have passed. It would be too much.

          + I find these optimizations very beautiful.

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

            ok, put 3 or 4 seconds not 2

            I have another completely different beautiful solution with same complexity, but I need two fenwick instead of one and that's why I got TLE, so after many many many optimizations finally I got AC with the monster that my solution became 75647531

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

        it doesn't require additional log

        Is that overall $$$O(n\log)$$$? I couldn't find a solution with such complexity on CF, can you explain it?

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

          No, in those solutions the preparation of events and iteration over them takes NlogN, but Fenwick and lower_bounds in compression still take Nlog^2. Example: 75556991. This is the fast one, there are others with typical running time 1000-1500 ms.

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

How to solve problem J?

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

    This is one of many possible solutions (Found it by brute force)

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

How to do K? I got WA on test 18.

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

      Interesting result. I kept on trying to solve 4 cases where each case had different number of distinct elements.

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

      why we sort the heights.

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

        Why not? It doesn't affect anything (jury could give us the sorted test, and the answer would be the same), and it gives the opportunity to make more assumptions.

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

can someone explain B ? binary search was giving me a wrong answer on test 29

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

    This test case may help

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

      how to solve I.

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

      yeah it worked that was a tough observation thanks!!

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

        Don't know what is your observation, but the solution is simple and well-known:

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

          yes

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

          Saying that it's well-known makes me kinda upset :(

          Can you explain what do you mean cause i didn't get it?

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

Can someone explain Problem-H Tree Painting ?? Thanks in Advance... And also can anyone post the link of editorials??

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

Can someone explain Problem-H Tree Painting ?? Thanks in Advance... And also can anyone post the link of editorials??

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

    First of all, it is not a rated round, and we don't have to provide editorial. It requires some time, you know. There is a video editorial we recorded just after contest, but for obvious reasons it is not in English. I think people can help each other in comments without any editorial.

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

Getting wrong ans on testcase 70 in problem G, any hints??

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

    You exceed query limit.

    Hint

    See more in my comment above.

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

Can somebody explain why this solution to problem B gives WA Submission

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

    A couple of things I can see is that:

    1. In main(), you have two for loops using the same variable i, so that would lead to overshadowing (but that won't cause a problem unless you use the outer variable in the inner loop).

    2. On line 62, it says a[i — 1] where i may be 0.

    3. On line 62, shouldn't you be checking if a[i] >= 0 instead of > (and same on line 69 — or you can simply remove line 69, as it changes nothing)?

    The algorithm I used is:

    My Algorithm

    Here is my submission: 75994294

    My submission was accepted — open at your own risk ;)

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

Could somebody explain how to solve problem D without Memory Limit Exceeded? My code reached test 32 but MLE was the problem (used Dijkstra's shortest path).

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

    Because strings in your Node struct can be O(N) length, so they eat O(N^2) memory in total.

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

      Yes, I thought so. Thank you. So then I would need to split it into two parts — finding the distance and then finding the lexicographically smallest path of that distance.

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

Does anyone have the tutorial for problem D with a c++ solution? I tried dijkstra but exceeded the memorty limit.

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

About the problem G — Nuts and Bolts — I saw in the comments that the problem + solution is described on a book, but I didn't find anything there about the motivation behind the $$$5 \log_{2}n$$$ operations. Why $$$5$$$ and not $$$3$$$ or $$$7$$$?

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

Do you guys prepare these problems yourselves or are they previous CodeForces Problems, dalex?

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

WA on test 8 in D any help?

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

I