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

Автор doreshnikov, история, 2 года назад, перевод, По-русски

Всем привет!

Снова рады пригласить Вас принять участие в Codeforces Round 753 (Div. 3) – раунд для третьего дивизиона, который состоится во 02.11.2021 17:35 (Московское время). Раунд (снова) был составлен совместными усилиями меня и MikeMirzayanov. Задачи, разумеется, новые, но мы, как и раньше, надеемся, что Вам они понравятся :)

Большое спасибо MikeMirzayanov за прекрасные идеи задач и за помощь с написанием хороших условий и тестов. У меня пока все еще уходит довольно много времени на некоторые аспекты подготовки задач, так что для меня эта помощь достаточно заметна. (UPD: в итоге эта помощь оказалась еще больше, так что спасибо огромное еще раз).

Помимо этого отдельная благодарность RisingWizard, Capta1n_Shy, Mazaalai и GustavoMG, nizamoff, 2020akadaver, ashmelev, p0kemanbr и Kofta за тестирование раунда, а также, как обычно, Gassa за полезные замечания по тестам и решениям! Ну и наконец, спасибо всем, кто примет участие в раунде! Раунд будет содержать 8 задач и расчитан по сложности на участников с рейтингами до 1600, однако все желающие с рейтингом 1600 и выше могут зарегистрироваться на раунд вне конкурса.

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

Вам будет предложено 8 задач и 2 часа на их решение. Штраф за неверную попытку в этом раунде (и последующих Div. 3 раундах) будет равняться 10 минутам. Обратите внимание, что количество задач увеличилось по сравнению с изначально анонсированным!

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

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

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

Всем хорошего настроения и удачи!

UPD: Выложен разбор задач!

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

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

I hope to become Expert in this round. Please, wish me luck :)

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

Look forward to great problems in this round! And I find that there is no testers in this round.

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

i hope to add 50 points

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

Note the unusual time of the round.

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

My first unrated round and this means a lot to me. It feels a lot better than I thought. I put a lot of effort into this in last 3 months and now this feeling is different kind of motivation to improve further. Codeforces has been sort of home to me. A big thank you to the best place on internet.

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

Hope to cross 1400.

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

    Sir, i have one doubt.

    Is it difficult to increase one's rating in div3 round after one has become pupil?

    Because in last div3 round, I solved 4 problems and gained only +3 .

    Moreover the predictor was indicating -10.

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

Is it unrated?

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

My first unrated round!

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

Hope to solve 5 problems.

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

Wish I could also comment My first unrated round. LOL!

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

I hope to return to monke in this round.

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

It's gonna be my first unrated div3 contest

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

Perfect. A round on my birthday where i can't lower my rating :D

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

Hope to become pupil in this Round, wish me luck :)

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

As a tester, I want contribution. :)

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

We tried to make tests strong enough but it doesn't at all guarantee that open hacks phase will be pointless.

Thank you for your honesty.

»
2 года назад, # |
  Проголосовать: нравится +16 Проголосовать: не нравится
As a first time tester, I must say
»
2 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Hopefully I will become Specialist after this contest.

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

As a tester, i feel problems are very interesting.

Hope you get more rating in this contest.

Have a nice day :).

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

I'm +3 away from being green, wish me a good luck guys.

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

At this point, it's really become necessary to remind this:

note the usual start time

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

is expected to have a decent level of difficulty for participants with ratings up to 1600.

Such a nice word decent.

As I have to say, I'm always hoping for solving those decent problems in div.3 in contest. But almost always, it turns out that those problems are too hard for me or even someone else with higher rating than 1600 to pass QWQ.

Wish me solve some of these decent problems in the upcoming div.3 round today.

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

Hoping to recover points which i had lost on the previous round :)

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

i guess that div3 is a great choice for the first round ever

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

50 points away from expert, wish me good luck !

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

Expert to be ♥

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

i have a feeling that my solution for D is wrong and gets ac

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

GG crappy memory limit like FHC

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

can't wait for the editorial, G is a new thing for me

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

Infinite loop / massive stack memory usage case for MLE on test case 4 of F? Is there no way to get AC without building the solution iteratively?

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

    Just stack memory usage. I had to stop using vector of vectors and use normal functions instead of std::function to get AC.

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

    Accurate enough DFS implementations were accepted, most of the testers' solutions used DFS and got AC :)

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

      Anything that stands out to you as problematic in this solution? 134105154

      Three cases are general non-calculated, cycle found and value already known.

      I can't really think of much that's removable except removing $$$on_cycle$$$ and using a reference to a common int for cycle start node or something like that.

      Anyway is there a reason for the constraints to be so high in this problem? I can't think of any incorrect solution that needs to be cut off that won't also fail for $$$n \times m \leq 3 \times 10^5$$$

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

        As I see it:

        1. gridx and gridy arrays are unnecessary, there's no point in storing them explicitly
        2. solve() can be slightly optimized by making curval global (and x and y also, but it will make code a bit less readable). Also local variables can be inlined

        I understand that these kinds of optimizations are not what you expect from Div.3 but the main expected solution doesn't use dfs at all, so it's not like we wanted to fail dfs explicitly, we just didnt' tune ML for any dfs to pass.

        UPD1: (sorry, previous UPD wasn't true, fixed)

        UPD: We just re-checked your solution in Polygon with double ML after making some modifications and it passed, so I guess we should've made the ML larger. Sorry about that :(

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

          My solution failed because of that too. I considered that to be a problem. But I didn’t believe that it was a true reason to get ML. After the contest I wrote solution without dfs and it passed

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

          Just wondering, in polygon, does increasing the ML also increase the stack limit (the option given to gcc -Wl,--stack=268435456)?

          I am debugging in gym and it doesn't seem like setting a higher memory limit changes the stack size. You still get a RTE/stackoverflow when you use above 250ish mb which is making this really annoying to debug.

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

I am completely apalled that you need to do a constant optimization in MEMORY on a official cf round. There are currently 15 PAGES of MLE solutions on F. Even using std::function at all gives MLE. Actually disgusting.

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

Was it really that necessary to make the limits tight for problem F, so that scc with recursion would TLE/MLE ??? Was it ???

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

How to solve D?

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

    My idea was greedy : first take the blue marked numbers and red marked numbers in the ascending order and keep a variable can = 1 Iterate through blue numbers : if (blue_number>=can) then can++ else we cannot convert this number to any other number in the permutation ans = NO;
    similarly for red numbers if ( red_number <=can) for each red_number if this too fails then ans = NO

    in all the other cases ans = YES

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

is G greedy?

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

    Yep

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

    Yup, identify maximum prefix increase of a — b possible for first $$$i$$$ nodes. Then as we go backwards make operations so the difference is below the max prefix possible and as close below it as we can get (so it lies above the min prefix possible).

    I think the intuition is clear, but I do hand wave away some details so maybe there is a small edge case I'm missing and I'll get hacked.

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

    A simple-ish way to think about G is as follows:

    Given values of a[i] and b[i], there is a minimum amount of each that the tester must eat (sometimes 0). Iterate once through and assign this minimum amount. This leaves a remaining 'variable amount' for each dish, and a starting difference. Iterate through again and assign this variable amount in such a way as to bring the difference back as close to 0 as possible.

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

      It feels so good when someone has done the exact same thing that you did and got AC .. Glad I could think this in time..

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

Am I the only one for whom was the 2 hours too tight for this contest?

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

such a bad div 3 round I have ever given. Authors div 3 is for newbies, so kindly make the problems for newbies and not for pros.

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

Someone please explain problem G, i don't understand :( example: test case inp 3 6 1 8 1 9 30 10 out 7 1 5 1 5 6 0 why the first line = 7 @@

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

Really annoying G for its unclear statement. The taster needs to maximize the balance of dishes WHICH IS LEFT AFTER EATING BY HIM, not eaten by him. It drops me from rk 40~ to 170 :(

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

    doesnt the first testcase show what they meant?

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

      I didn't saw it until I finish my program. I think the statement is clear enough, but it doesn't.

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

    You don't need tarjan x)

    The graph is a functional graph so it's enough to just iterate while you don't cycle and keep track of the nodes you're visiting in a vector. Then, if you visit a node X you visited in the same run, there is a cycle starting at node X and you can recover the cycle with your vector

    See my code here for more details: [submission:https://codeforces.com/contest/1607/submission/134137875]

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

the MLE of F is awful

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

I believe, F should belong to an educational round, not to a div3 round. Like I am not against teaching people how to write dfs using stack (though I believe that the authors who design such problems are quite... strange), but asking a beginner to do this optimization? For me it looks like the best way to discourage them from doing cp.

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

    It's true that DFS is one of the first things that come to mind when one sees this problem, but it's not the only thing that could be used...

    The ML wasn't set up to explicitly fail all DFS solutions (and I mean it), we just expected a solution without DFS as we know it so we didn't tune the ML for any DFS to pass.

    Since if you think about the board as a graph, each vertex has only one outcoming edge and you can walk through the graph with a single loop without even knowing that such thing as DFS exists. And that's what actually written in main solution.

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

      Actually there are some DFS solutions be able to be optimized enough to pass. Yet they are very rare compared to those get MLE.

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

      Well, that's great that you have a solution that does not need any additional optimization. But it seems you don't get the point, the thing is that failing recursive solutions (with correct time and space complexities) is not nice. Did you not think of dfs while setting up this problem? That's really strange, because that's the first thing that comes to mind.

      I believe that in beginners contest (in any contest, actually, but for beginners it's even more important) the authors should try to cut off solutions with bad complexity and allow solutions with good complexity to pass comfortably and I also belive that this does not hold for this problem.

      UPD. So you say that none of the testers solutions were close to ML, while having recursive dfs inside? Seems unbelievable. Or you mean that they were able to squeeze dfs into time limit? This is possible, of course, but really, you wanted 1600- rated people to optimize dfs?

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

        Maybe the authors wanted to SendThemToHell

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

        I understood your point, yes. The fact that in the end this task was challenging not because of it's algorithmic difficulty but because of the memory limit is kinda frustrating, this was not how it was intended.

        Well, I can't argue with the fact that this Div. 3 is not as well-adjusted as the previous one, sorry for that. We'll try to make the next one more pleasant to solve.

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

          I solved 7 problems in 1 hour. And couldn’t optimize dfs to pass in the remaining hour of the contest :(

          everything else is super. Thanks for the great contest :) спасибо за интересные задачи

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

        Yes most of the recursive solutions fail just because of MLE. But my main point is that there are so rare dfs solutions with heavy optimization to be able to pass, I did not mean that DFS is enough to past.

        I think that the author make a miscalculation to use 256Mb instead of 512Mb and kill around atleast half of the solutions.

        Yet some of my CM friend still find it very confusing to optimize further, some even spend an hour without being able to solve it.

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

      But is there a solution that even needs to be cut off? If not why set the constraints so high? Additionally you mentioned earlier that some testers had dfs solutions, were none of them close to the memory limit?

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

    the graph is a functional graph so you can just use a loop 134137875 (although I used a DFS during the round and got few problems)

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

      Is there a prerequisite technique on how to find the longest path in a functional graph? I dont get your solution, what do the while loops do?

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

        First, why do I have that much downvotes :') ?!!

        I'll try to explain my solution step by step. First notice that in the graph, each node has at most one child. So basically, any connected component has at most ONE CYCLE.

        Indeed, let's assume you're currently constructing the connected component starting from node $$$1$$$. When we're at node $$$i$$$ we have two choices: we can either add an edge to node $$$i + 1$$$ (so the graph looks like a path and we don't have any cycle) or we can add an edge to some node $$$j$$$ such that $$$j < i$$$ and we'll create a cycle. Notice that after a cycle has been created, we can't add any more edge.

        Now let's say we found the cycles. For a given cycle, the length of the longest path is the same for each node of the cycle (it's the size of the cycle).

        So now we know that a functional graph looks like

        ......x

        ......|

        ......|
        ......v

        x->x->x->CYCLE

        (the . are used to align the edges. I'm sorry I couldn't do something clean. I'll try to send a drawing asap)

        Imagine it as we link some sort of directed tree (where all the edges are directed toward the root) to a cycle.

        About my code:

        What you can do is store for each node:

        1) if it has been visited

        2) if we are visiting the node (this means the node is part of the path we are exploring right now)

        3) the longest path starting from this node

        In my code $$$ans[i][j] == 0$$$ if the node hasn't been visited, $$$ans[i][j] == -1$$$ is we're visiting the node, else it's the longest path starting from this node.

        Now let's iterate over each node $$$u$$$. If the node hasn't been visited, let's start a walk in the graph (basically we explore the unique path starting from node $$$u$$$). We'll keep track of a vector of all the nodes in the path ($$$curCycle$$$ in my code) and we'll also remember the length of the path ($$$cnt$$$ in my code)

        This is what I do in the first while loop.

        Let's say the child of our current node is $$$v$$$. If it's the first time we see it then we move to $$$v$$$ and keep exploring (don't forget to update $$$curCycle$$$ and $$$cnt$$$). If we already computed an answer for node $$$v$$$, we simply increment $$$cnt$$$ by this answer and break. Now, if $$$v$$$ is already part of our path (in my code it's $$$ans[i][j] == -1$$$), it means we cycled. So we're going to look for the last occurence of $$$v$$$ in our array $$$curCycle$$$. All the nodes after this occurence are part of the cycle and their answer should be updated accordingly. Notice that as we cycled, we can't expand our path anymore.

        Now we also need to update the answers of all the nodes in the path (nodes which are outside of the cycle). So we basically start again to walk from node $$$u$$$ and we set it's answer to $$$cnt$$$. Then when we move to the child of the current node, $$$cnt$$$ should decrease because the length of the path is reduced by $$$1$$$.

        The time complexity is $$$O(N)$$$ where $$$N$$$ is the number of nodes (here $$$N = nm$$$). Indeed, we visit each node exactly once because after a node has been visited, it's answer is remembered and we'll never explore again it's path.

        Essentially, finding cycles in a functional graph is the same as finding if there is a cycle in a directed graph (See CSES Round Trip)

        The only difference is that:

        1) As the graph is pretty simple we can use a while loop instead of a DFS

        2) We're actually finding ALL the cycles of the graph because each connected component has at most one cycle

        About the other part of the algorithm, imagine you "compress" the cycles into one big node with it's answer = the length of the cycle. We now have a DAG (and more specifically it's a kind of directed chain) so we can apply DP (here we have only one transition per node).

        The while loops are just a more convenient/efficient way to implement the algorithm.

        A few problems about functional graphs:

        Usaco silver, Swapity Swapity Swap

        Usaco silver, Dance Mooves

        Usaco gold, Exercise (well this one is a bit less related but it's an interesting problem)

        I hope my explanations were clear, if they weren't just ask me and I'll do my best to explain :)

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

Why the memory limit for F is so tight ? As a beginner I find it very hard to optimize memory further more (though there are better algorithm but I cant just think of it)

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

    The same for me. Seems recursive programming does not work. Have to do in a loop.

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

      Most of my friend using DFS are failed due to MLE (and there are CM too). Just one among them be able to pass using kosaraju instead of tarjan.

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

        wait, did you really compressed the graph using strongly connected components ?

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

        U wrote opposite maybe
        I believe he would have used tarzan as Kosaraju takes more memory . I too passed it in recursive way but I had to find cycles by simple DFS . And code is still on the edge for MLE .

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

        But isn't Kosaraju also dfs?

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

Someone please tell me why my code is not working in problem D.

134132886

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

    You forgot return statement in the flag == 1 condition :/

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

    You misunderstood the problem. The numbers can be completly out of range of 0..n, so the code does not work at all.

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

      No, they added specific conditions for 'B' and 'R'. Since 'B' can only be decreased by 1 and 'R' can only be increase by 1, it seems right to me.

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

        Consider in example all red numbers bigger than n. Obviously output must be No.

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

          Sorry I don't get your point. This is exactly what is done in their code + what I explained.

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

            No, the code does not check this.

            The var temp1 never gets incremented if values are out of range 1..n, so output is never No.

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

              Parts of the code

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

Can anyone help me understand why this is TLE on F? https://codeforces.com/contest/1607/submission/134130569

I'm pretty sure it's just linear time complexity DFS with the board size, but why TLE?

Is this because it's using recursive and cause stack overflow?

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

    I see you're using std::map and std::set in your code, both of them will make total time complexity of code as: $$$t \times n \times m \times \log(n \times m)$$$ which will surely give TLE over all test cases :(

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

      even if it's using map and set, the complexity is 4*10^6 log (4*10^6) which is less than 100 millions. Why would that TLE over all test cases?

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

Задачи очень интересные были) Спасибо!

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

How to solve B? :(

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

I really like it to solve so much problems as in div3 possible. But today there was also a big difficulty gap from E to F,G,H.

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

This input data is from Test Case #3 of problem D.

Test Case :

Hi doreshnikov, Could you please help me? I wanted to know what is the logic behind this test case. I have stress tested my solution on random 10000 inputs of array length 20 but my generator couldn't catch this.

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

    Not sure what's so exceptional about this test. If you sort all the numbers by (color, value), you get something like this

    As you can see, all blue numbers can be decreased to the corresponding number from permutation and all red numbers can be increased to get the number from permutation (the first number in the row is the expected number from permutation).

    It could be the fact that there is a Blue number that you don't have to apply operations to (2), but I was sure a similar case was in the example test...

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

WTF! Why do you put a blank line in the input?

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

    If there was no blank line it would be hard to know which testcase is which. The extra blanks don't affect input

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

    So it is easier to distinguish tests in a multitest when you read it

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

B was trash

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

    It was a pretty straightforward observation after dry running any testcase that we land at the starting position after every 4 jumps.

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

      oh is it so straightforward? Please teach me how to make observations.

      Observations suck!

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

        Observations are quite important in the world of competitive programming :) it's pretty valid advice from yasserkhan45: if you can't see the answer immediately, experiment with some test cases. As is pointed out, a single test case was enough to see what happens in general, and a small modification was required for an odd starting position.

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

          What to do if I still can't see through, happens with me most of the times, observational questions are the ones that take up most of my time in a contest, for most people they are straightforward but for me :(, any advice on how to improve?

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

            If observation doesn't work, sometimes it helps to write a solution that you know is slow and will not pass but is really easy to implement (in this case it's just to simulate the process).

            Either you'll find a way to optimize it later so it would get OK (not in this particular problem though) or you'll have a way to search for patterns in answer a bit faster. In IOI format it also may help you to get at least partial score.

            If nothing else, at least you'll have a solution you can stress-test your main solution with if something goes wrong with it.

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

            There's no catch-all answer here and I don't want to reel off any cliches but:

            • practice really does make an enormous difference here: the more questions you solve, the more your past experience can inspire the right ideas.

            • limits often provide a clue. The limits here were big, so it was clear there must be some sort of pattern that did not require us to iterate over all moves.

            • look for patterns. Here, if you choose a starting point of 0 and iterate for a few moves, you get [0, -1, 1, 4, 0, -5, 1, 8, 0, -9, 1, 12, 0, -13, 1, 16, ...]. It's clear that we keep getting back to 0, and that this happens every 4 moves — think about why. It's because every 4 moves, the first and last move go left, and the middle two moves go right. What's happening between those moves? Every other even move (n % 4 = 2) brings us back to 1 (it's easy to consider why this happens). If n % 4 = 1, we're subtracting n from 0. If n % 4 = 3, we're adding n to 1. So this gives us the complete set of cases [0, -n, 1, n+1] for the four possible values of n % 4. Then we add the starting position. If we start on an odd position, it turns out (by similar experimentation and consideration) that the complete set of cases is [0, n, -1, -(n+1)].

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

              you are right but my observation took a lot of time, I guess more practice will help, thanks for the advice :)

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

              It’s took almost 1 hour for me to solve B problem. After contest I asked my friends why B problem is so hard(After B I solve 2 more problems in less than 20 min), I was shocked that we can n%4. My solution is arithmetic progression, after we start in even number we move -1, +2, +3, -4, -5, +6, +7 etc. So I saw we have progression +2,6,10... and 3,7,11... -4,-8,-12... I just don’t know why this problem is B, because C is easier. In C you don’t need to notice anything, just write easy code. In B you have to write complicated arithmetic progression(which is obvious will pass 10^14 tests, after that I just didn’t think about another solution), or notice n%4 somehow.

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

                That’s why you shouldn’t spend much time on one problem. You only read B and didn’t read other problems. Try to read next problems too, because they may be easier for you. If you just skipped B, you would have taken higher place on the contest. For example I solved problems in this order A B C D E H G and F after the contest.

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

      I still think its dumb. If you try to work out an idea instead of looking at the sequence and guessing you waste a bunch of time and get nowhere. To this point i have no idea why my solution works (will probably work it out now that i said this).

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

134139660 please see my solution .I am getting tle . for no reason .

please do not ignore .

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

Question B and C someone please explain approach of these :))

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

    C, consider the array a[] to be sorted. So the first value is smallest, so gets removed first. Observe that all values allways change by the same amount, so the relative sorting allways stays the same. So the values are removed from left to right.

    When removeing a[0], a[1] becomes a[1]-a[0], a[2] becomes a[2]-a[0] and so on.

    When removing a[1], a[2] becomes a[2]-a[0]-(a[1]-a[0])=a[2]-a[1] Same for a[3] becomes ... =a[3]-a[1]

    When removing a[2], a[3] becomes a[3]-a[2]...

    So ans=max(a[0], max(a[i]-a[i-1]))

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

I got runtime error in test 10 problem H. Can someone fix for me

https://www.ideone.com/64cEbJ

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

I guess this is because the pointer in 64bit system is 8 bytes :(

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

I tried solving F. Robot on the Board 2 using dfs with dp on the matrix using directions as edges and cells as nodes.

My idea was to first find a single nodes for each simple cycle for which I used dfs1. Then I used dfs2 to set each nodes of every cycle to it's cycle length. Finally, I used dfs3 to get length of paths for the remaining nodes of the graph. I'm getting Memory limit exceeded due to some bug. Can anyone point out the issue here.

Here is my submission #134144883.

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

    When you have recursion(dfs) system reserves memory for that recursion. It is usually called stack memory. So your dfs uses additional O(N*M) memory. That’s why you got MLE, and me too. Try to solve this problem without recursion.

    Hint: all cells have only one outgoing edge

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

    My Solution got AC with DFS although it is also on the edge of MLE. You can have a look if u want .

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

Memory limit was too tight for problem F. I used dfs and got MLE with a memory usage of 283MB using C++17(64). However, I submitted it for C++17 and got AC, only 161MB.

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

I hope to become Expert today :) (unless any of my question is hacked :( ) Thanks for this wonderful round!

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

Thank you so much for interesting & worth studying problems :) I really enjoyed it. p.s. Any editorials yet?

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

when will system testing / hack rejudging start??

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

I hacked 10 users!

When will system test begin?

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

how to improve my logic

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

Can anyone tell how to get rid of MLE in test 4 in problem F. Link to my submission:- https://codeforces.com/contest/1607/submission/134177362

I used Kosaraju's algorithm and then did dp in the condensed graph.

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

    here's what I did:

    1. i was earlier using SCC to find cycles, but then I switched to using just DFS

    2. iterative DFS using stack, instead of recursive DFS

    my submission: 134172739

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

This was my first ever contest. I was not able to solve all the problems and wanted to know the solutions of it. PLease tell me where can I find the tutorials

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

This was my first round, and I solved 7 problems but i'm still unrated :( Is this round unrated for me?

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

how to do problem C minimum extraction

I did a brute force but got tle

My solution

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

    $$$1\leq n\leq 2\times 10^5$$$

    And your code is not less than O(n^2).That must come to TLE.

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

    You must calculate the TIME COMPLEXITY before submitting.

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

      Thank you very much for replying Actually I didn't submit this solution in contest in fact I couldn't solve this. Now when I am upsolving it this is the only solution I can come up with. I wanted to know the actual approach or solution that is why I asked and I also gave my approach I can come up with. I know that is O(n^2).

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

Will this contest be rated for me? this is my first ever codeforces contest ? Any information on this will be really helpfull. Thank you!

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

    It is rated for you

    Regardless of whether you are a trusted participant of the third division or not, if your rating is less than 1600, then the round will be rated for you.

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

is there anyone whose rating has been updated yet? I am still unrated, so I was wondering if I had to do something more in order to get a rating..

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

Editorial? doreshnikov

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

    Sorry, wasn't feeling well. I promised the previous time that editorial will come out sooner, but couldn't finish it faster this time :(

    ETA: half an hour probably, I hope...

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

All problems in this round is with multi testcase. Interesting.

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

Sorry, but when is the editorial available? Because last 2 problems I can't solve it T_T

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

What's the meaning of the memory limit of Problem F...

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

I think A-E are good problems in div3,but F is obviously harder than E,it leads to the speed of solving the first five problems is particularly important.But anyway, I think it is a good round!

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

n

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

The test data for Problem H is not strong enough. After taste, for the $$$i$$$-th dish, $$$a'_i$$$ should be in $$$[\max(0, a_i - m_i), a_i - \max(0, m_i - b_i)]$$$; In my first submission, I wrote it as $$$[\max(0, a_i - m_i), a_i]$$$. It's wrong because I ignored this type of situation: when $$$m_i > b_i$$$, taster must eat some of $$$a_i$$$. But it got Accepted.

Upd: It seems this bug surprisingly can't be hacked, none business of the strength of the test data, sry.

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

比赛结束了吗,难度咋样

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

    What'are you saying?Which language?Chinese or Japanese?Please use English(recommended) or Russian.

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

if you like codeforces.com? then put +

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

Hi