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

Автор voidmax, 6 лет назад, По-русски

17 апреля в 17:05 по Москве начнётся Tinkoff Internship Warmup Round 2018 и Codeforces Round #475.

Хочу выразить благодарность Владиславу winger Исенбаеву, Александру AlexFetisov Фетисову, Ильдару 300iq Гайнуллину, Егору Egor.Lifar Лифарю, Филиппу grphil Грибову и Глебу Glebodin Лобанову за тестирование задач.

Особая благодарность Григорию vintage_Vlad_Makeev Резникову и Николаю KAN Калинину за помощь в подготовке раунда и Михаилу MikeMirzayanov Мирзаянову за великолепные системы Сodeforces и polygon.

Раунд будет рейтинговый для обоих дивизионов. Вам будет предложено 5 задач на 2 часа. Разбалловка будет объявлена позже.

Удачи в раунде! Успешных решений!

Регистрация откроется для всех, как только будет правильно настроена. Следите за обновлениями.

UPD Регистрация открыта.

Приветствие от спонсора контеста:

Мы рады приветствовать участников Tinkoff Internship Warmup Round 2018 и Codeforces Round #475. В этом году компания Tinkoff.ru проводит летние стажировки для разработчиков, специалистов в машинном обучении и аналитиков в Москве, Санкт-Петербург, Екатеринбурге, Новосибирске, Ижевске, Рязани и Иннополисе. Первый онлайн этап для разработчиков это аналогичный контест, он пройдет 14-18 мая. Регистрируйтесь на стажировку на fintech.tinkoff.ru и проведите лето в самом большом онлайн банке в мире.

UPD Разбалловка для обоих дивизионов: 500 — 1000 — 1500 — 2000 — 2500

UPD Поздравляем победителей!

Div 1:

Div 2:

UPD >>> Разбор <<<

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

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

Автокомментарий: текст был обновлен пользователем voidmax (предыдущая версия, новая версия, сравнить).

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

Wish high ratings everyone

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

    Please stop all these comments about Wish high rating and is it rated and short problem statements.

    Every one wishes that. So it is not important to write these comments. Keep comment section clear for more important things.

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

Автокомментарий: текст был обновлен пользователем voidmax (предыдущая версия, новая версия, сравнить).

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

Why isn't there an English version of the blog?

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

Is it rated?

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

I got worried when the registration was only privet :D

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

Вы, кажется, фамилию одного из проблемсеттеров неправильно написали :( Гайнулин -> Гайнуллин.

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

Is It Rated?

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

Ссылка на fintech битая :)

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

thanks, finally it's 5 problems

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

The points distribution will be updated later.

This sentence is wrong, correct one is :

The points distribution will not be updated before contest.

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

Why I can't register for the contest now???

»
6 лет назад, # |
  Проголосовать: нравится -28 Проголосовать: не нравится
Комментарий удален по причине нарушения правил Codeforces
»
6 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

What was Div2 B?

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

Any Idea of pretest 7 for Div2C?

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

Please!! What's the hack data for B?

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

Is it just me or B was much more difficult than usual?

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

Oh..the competition is over....it is too hard for me.....

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

 #easy

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

Too much maths for Div2

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

Any idea of pretest 9 in DIV2C and pretest 7 in DIV2D?

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

how to solve problem D in div2 ? so sad of wr7

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

    x2

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

    x3

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

    5 0 1 2 2 4

    My initial code failed this test and it was getting WA in test 7.

    I think that the answer is to remove the deepest node with even degree, because none of its children have even degree so they can't be removed unless this node is removed first.

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

      I think you can remove any such node that all the remaining trees would have odd sizes. This is easily done using BFS or a set(), since each removal only changes the "parity" of adjacent nodes.

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

oh..the contest is over...maybe it is too hard for me.....

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

In Div2 D isn't it always possible to destroy the tree by removing the leaf vertices and then proceeding upwards in this fashion?

The leaf nodes will always have a degree zero which is even right ?

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

How can this O(n) solution 37407108 for Div1A pass when I tried to hack it with test case n = 1000000000 ? Can someone explain? voidmax

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

    Ok, that solution has O(n) complexity, but hidden constant is very small. Codeforces has fast servers hence O(1e9) fits in TL.

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

Can anyone explain how can this O(n) solution 37407108 for Div2A pass when I tried to hack it with test case n = 10^9 ? voidmax

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

Regarding "Destroying a tree", it matters the order in which the vertices are selected. For example, consider this test case:

5
0 1 1 2 3

If you start from vertex 1, then it's impossible to destroy the tree, but if you start with vertex 2, then the order "2 4 3 1 5" is valid.

Unfortunately, I couldn't make it up to find out a strategy that always brings the correct result and maybe that's why I failed pretest 7.

Kudos to voidmax for the interesting problemset!

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

    Root the tree from a random vertex. It's always optimal to destroy a vertex with largest depth (and even degree of course).

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

      Can you explain why?

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

        This is probably not a proof, it is just my thinking during the contest

        Suppose that you have two vertex with even degree (one is parent of other).

        If you remove the parent, the child will be affected, you will need to remove some child to have even degree again... It's kinda hard to check this from parent to child (root to leaf).

        Try to go in the opposite way: from leaf to root.

        You have a leaf (obviously odd degree), how can you remove it? You need to remove it's parent... If the parent is odd, then you need to keep checking the parent until you reach a vertex with even degree. Now you remove it.

        Then you have just disconnected the tree, the new tree should be solvable, otherwise "NO"

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

        Hi Yash, did you figure out a proof. I really want to know how this works but I can't prove it. The comment linked by the author below also doesn't help :/

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

          PROBLEM D GREEDY PROOF

          OK I figured it out for anyone in the future who falls in trouble:

          1. Removal of the deepest even-degree node causes further removal of even number of nodes in its subtree (easy proof by induction)
          1. This means that odd-even=odd which means that the number of nodes remaining in the subtree is odd. Which means again, by initial lemma, that there exists atleast one node with even degree.
»
6 лет назад, # |
  Проголосовать: нравится +9 Проголосовать: не нравится

wake me up when systests start

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

What is pretest 15 in Div1 C?

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

Why this o(n) sollution passes system testing? 37405016

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

    Because C++ has optimizer. It easily optimizes this sort of for, so programm works in O(1).

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

Please, just run systests faster and let us go to sleep, we have rehershal tommorow :/

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

What is correct solution to B anyway? I know that:

  • If a tree has even number of vertices, the answer is 'NO'.
  • Otherwise, there is always at least a even-degree vertex. However, I don't know if it is true that there is always at least a even-degree vertex that seperate the tree into smaller component that has odd number of vertices (If it is true, just choose this vertices and solve the subproblem). I couldn't find a counterexample so I bet my luck in it, but failed miserably.
  • »
    »
    6 лет назад, # ^ |
    Rev. 3   Проголосовать: нравится +30 Проголосовать: не нравится

    There will definitely be a vertex with even degree breaking the tree into odd components. We can first remove all even sized subtrees of the root. Once all even sized subtrees have been visited, print current vertex and then visit odd sized subtrees. In this method, we are considering either odd sized trees with no parent edge, or even sized trees with a parent edge, and you can prove using induction that this works :

    void dfs(int s = 1, int p = 0){
    	for(int v : con[s]) if(v != p && subtree[v] %2 == 0) dfs(v, s);
    	printf("%d\n", s);
    	for(int v : con[s]) if(v != p && subtree[v] % 2 == 1) dfs(v, s);
    }
    
    • »
      »
      »
      4 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится
      "There will definitely be a vertex with even degree breaking the tree into odd components."
      

      That's what he asked to be proved.

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

    You can remove the vertices greedily by its heights: remove the ones with greater height first.

    If you are removing a vertex V, its subtree has no vertex X ≠ V with odd degree, otherwise it would be removed before V. The children of V will now have even degrees, since just one edge is removed from them, and you can apply the same idea to them, since their subtrees have no nodes with odd degree beside them.

    So, all components that were on V's subtree are good to go; you just need to prove that the upper component is good to go too. That's easy: since the number of edges in V's subtree is even, then the parity of removed edges of the upper component did not change, which implies that there is another even-degree vertex to be removed.

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

    Could you explain why answer is No when tree has even number of vertices?

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

      Even number of vertices have odd number edges .And you always delete some even number of edges

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

        What a simple idea it was. Deleting a vertex will separate trees, that thought confused me. thanks.

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

Could anyone please drop a couple of hints on Div2C? (Div1A)
How to approach this kind of problems?

Update:
Oh, I got it now.
Thank you, aangairbender.

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

    You can calculate (we will call it T) in O(k * log(k)) time complexity. It will be the sum of one period.

    Two consecutive periods are times different — we can call that value Z.

    The number of periods will be (n + 1) / k = Q.

    Therefore, the final answer should be: , or .

    All of these can be calculated with modulo addition/multiplication/inverse.

    Update: Just see the update of your comment. Nevermind, hope you can find something useful in mine ;)

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

      Thank you!
      I indeed find your comment useful.
      Specifically, it did not come to my mind during the contest that consecutive periods differ by (ak / bk) times.

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

    Let Sum[0, k) be the summation of first K terms of that series.

    Now you can observe that Sum[k, 2 * k) = (bk / ak) * Sum[0, k)

    Similarly, You can divide the whole series in (n + 1) / k terms which is a G.P with common ratio (bk / ak) and then use the formula for the sum of geometric progression (don't forget the case when common ratio of this G.P is 1).

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

Can anyone tell me if this solution for Div2.D is correct? I came upon it too late in the contest and didn't have time to implement it. So, here it goes:

Lets start at the leaves, it is obvious that their parent will have to be destroyed before them.

Now let's go 1 level up on the tree, if a parent of a leaf has even degree, then for sure its parent will have to be after before it, otherwise it wouldn't be possible to destroy it.

If it has an odd degree, then it will have to be destroyed before it. Now, lets substract the number of sons that will have to be clicked before their parent from the parent degree and continue doing the same procedure, going up the tree.

Lets make a directed graph, that has edges (u,v) for every u and v such that they are adjacent in the tree and u has to be clicked before v.

Do a topological sort on this graph and start clicking vertices in order, if at some step we have to click a vertex with odd degree, there is no solution. Otherwise, simply clicking in order will produce a solution.

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

Actually I will kill myself. I used f***ing std:map< string > and I didn't realize it is |Slog.

P.S. I read comment it is always optimal to destroy vertex with the largest depth, why it is not good to destroy vertex with largest id ?

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

    Because ids are arbitrary. You can relabel the nodes in any way that you want. (as long as you output them with their original labels)

    Also don't kill yourself.

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

I am probably the only person who tried to solve Problem B using Dynamic Programming. I am sooooo stupid.

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

"Oh, they changed the mod from 1e9+7, that must mean it's not prime."

Why would you do this to us

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

When you get wrong answer on E after system testing...

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

help please with this submission of DIV 2 C: http://codeforces.com/contest/964/submission/37413366 upd: solved, thanks voidmax

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

Can anyone explain, why it is always optimal to remove nodes from deeper level in div2 D?

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

1) Evil 2) Very Evil 3) Not putting any pretest cases where C-B > 1 for B :3

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

Can someone help me?My code of div1.A is similar to others accepted submissions but why I got Wrong Answer on test9?

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

I normally have something to complain about the rounds (even though I never comment) but this round's problems were great.

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

Контест говно

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

Now failed systest on A too... Why not allow solution...

It seemed that I still have a lot of thing to do if I want a slot in ACM-ICPC WF

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

    Revision history of the comment is me irl

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

    If I had to guess, I'd say it's not a problem of time complexity, but of correctness.

    In your submission, you write int t =k*n/2, but the multiplication can exceed the limits of the int type, causing undefined behavior. What I'm guessing is that at some point this t becomes negative and since you passed it as an exponent to your power function, it will cause an infinite loop.

    Just a hunch though, I'm not at my laptop right now so I can't test :)

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

      t will never exceed n in the problem statement.

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

        Why? Which part of the problem statement leads you to believe that?

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

          I called the function in this manner:

          Calc(..., ..., k, (N+1)/k);
          

          So t will never exceed N/2 (let N be the 'n' in the problem statement so it won't be ambigious).

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

          I got accepted after improving the complexity to , and I didn't change the Calc function in my code.

          37415485

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

            You can calculate first block in complexity O(K + log(A + B). First calculating , so you can calculate all degrees up to .

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

What's wrong with my solution ofr div2 C? http://codeforces.com/contest/964/submission/37415514

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

Editorial?

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

The feeling of becoming Expert.

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

I think the time limit for Div1 A/ Div2 C should have been 2 seconds considering order of 10^6 modulo operations.

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

But is that true, that with given constraints (k <  = 105)(b / a)k = 1 implies (b / a) = 1?

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

Jesus! I can't believe my bogus solutions for B and D passed System Tests !!!!!!

My solution for B: Maintain a set with all nodes with even degree ordered by depth first (distance to root). At each step, remove the deepest node (farthest from the root) and update degrees accordingly, removing or adding to the set as necessary.

My solution for D: Perform Suffix Array on S. Then for each query (t, k), all occurences of t in S will form a contiguous segment in the Suffix Array. Let the suffix array be SA, and suppose that the subarray for a given query in it is (l, r), then we need to find a set X of k indices i1, i2, ..., ik from the range (l, r) such that max(SA[i]) - min(SA[i]) is minimized (). I did that by pushing all SA[i] with l ≤ i ≤ r to a vector, then sorting the vector and checking all values of vi - vi - k + 1 for all i ≥ {k - 1}. I was certain this approach would get TLE in a very early test case. I can't believe such a thing passed systests....... but I'm really happy it did! :)

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

    Your solution for D works in . Let's consider all strings of the same length. The total number of their occurrences in s is O(n), because at each position there can be at most one string. The number of defferent lengths is . So the number of all occurences is . You can also get rid of additional if you use Aho-Corasick instead of suffix array.

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

    i can prove your solution for B and it's true :))

    so tests are okay ...

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

      Yeah, I have no doubt tests are okay. It's just that I didn't prove it myself, I just thought "I guess this approach will work" and decided to blindly submit.

      The same for D, I didn't put too much thought into how many different lengths and matches could occur and didnt' do the math. I just coded the first thing that came to my head and submitted.

      That's why I didn't expect either of them to pass. Seeing my rating increase and ranking 50+ was a very pleasant surprise :)

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

Когда Роскомнадзор заблокирует CF, ведь его спонсор — телеграм?

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

My solution for B div1:

Always process the child nodes first before their parent (like a topological sorting where the directed edges go from the nodes to their parent). Initially start with the leaf nodes in the queue of the nodes to be processed. When processing a node, if its degree is even, delete the whole subtree rooted at it, and decrease the degree of its parent by 1. And after processing the node, look at its parent, if this parent has its children all processed then push this parent to the queue. At the end, you succeed if you have deleted the whole tree.

This idea is based on the fact that the information you start with is that the leaf nodes can't be removed unless their parents are removed. And if you processed the whole subtree under some parent and this parent still can't be removed you have to remove its parent, and so on. If you reached the root and couldn't remove it, so it is impossible to remove all nodes.

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

I see many people have provided greedy solutions for Div1B/Div2D. Here's my DP on tree solution (which ACed) for those interested:

First, observe that for any vertex u, having parent v, you can destroy the subtree of u either entirely before destroying vertex v or entirely after destroying vertex v. So, let's classify our vertices into two types: 'before' vertex — a vertex whose subtree is destroyed before destroying it's parent and 'after' vertex — a vertex whose subtree is destroyed after destroying it's parent.

Now, identifying vertices is easy. First, note that all leaves are 'after' vertices. They can only be deleted after their parent is deleted. Now, observe that a vertex is a 'after' vertex if and only if it has even number of children who are 'after' vertices, otherwise it is a 'before' vertex.

So, all vertices can be classified into 'after' and 'before' with a single DFS. The answer to our question is YES if the root is an 'after' vertex otherwise it is NO. Printing the solution is also easy, for printing the solution of the subtree of vertex u, print the solutions of all it's children who are 'before' vertices, then print u, then print the solutions of all 'after' vertices.

Here's my code: Destruction of a Tree

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

How to solve div1 E?

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

Still waiting for the editorial...

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

On div 1 Problem D test 22. The n is 80445 by assert, and the kind of lengths of mi is at least 325 by assert too. So Sum of length of all strings in input is at least 133420. That's illegal to the tips of the subject.

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

    There really is a problem but I don't think that would be. The problem is that the problem mentioned "Sum of length of all strings in input doesn't exceed 10^5", the total length of query is less than or equal to 10^5, but including the string s, the total length is greater than 10^5. But I don't think it caused any trouble.

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

WHY got TLE in Div1 D using a Aho-Corasick automaton to brute force maintain the occurrences of each query strings?

I thought the time complexity is O(n sqrt(n))

my code here:37415123

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

So when can we see the tutorial of the contest? I really need it. thx!

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

Thanks for the round voidmax, great problems! (except div1 D)

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

Since there's no editorial, here are some solutions:

  • B: No clever tricks, just tree DP — is it possible to delete the subtree of v if the parent of v is deleted before v / after v? If we determine which sons of v should be deleted before v for both of these cases, the order of deleted vertices can be computed recursively (to delete the subtree of v, delete subtrees of sons deleted before v, delete v, delete subtrees of remaining sons). For the tree DP, if v has a son that can't be deleted in either case, the answer is no for both; if it has a son that can be deleted in both cases, the answer is yes for both, and otherwise, we know exactly which sons should be deleted before/after v.

  • C: If the answer is non-zero, the problem can be formulated this way: we have a complete edge-weighted bipartite graph (vertices are widths and heights of rectangles, edges are rectangles, weights are ci); count the number of ways to assign integer weights to the vertices in such a way that the weight of each edge is the product of weights of its endpoints. This can be solved independently for each prime factor — we're adding exponents instead of multiplying integers, everything is determined uniquely if we fix one exponent, and since these exponents are small, we can try all possibilities for one of them and check by bruteforce if it actually leads to a valid assignment. We only need to deal with prime factors of w.l.o.g. c1; afterwards, we're left with a graph that has c1 = 1, and need to check if the only possible assignment in this graph is valid. Time complexity: .

  • D: If we know all positions where a query string occurs in s, the answer for this query can be easily computed in linear time with no additional overhead. Actually, there are sufficiently few of these positions, so we can find them all. For a query string with length greater than sqrt (let's say 100), we can find them by KMP with overhead O(|s|); there are only sqrt of these strings. All query strings with length at most sqrt can be stuffed into a trie. Now, for each suffix of s, we can find a path in the trie corresponding to this suffix (with length at most sqrt, since that's the depth of the trie), and all query strings that end in vertices on this path occur on the position corresponding to this suffix. Time complexity: . You can get MLE or TLE, watch out for your trie implementation, try to put smaller strings in it or use a hashmap instead.

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

    Problem B has a greedy approach too -> here

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

    Solving D with only Aho-Corasick is also possible. Just put all query strings in the trie and compute the suffix links. Then iterate over the text characterwise and record all occurences.

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

      Aho-Corasick is solid overkill compared to KMP and tries. Yes, this is a deterministic memory-efficient solution, but I like to avoid Aho-Corasick whenever possible.

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

        You seem to not understand Aho-Corasick if you think that KMP and trie is simpler. Because Aho-Corasick is literally KMP and trie. It even can be written as combination of those.

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

          Ok, wise guy, answer this: in what order do you compute backlinks and where in KMP or trie do you need to think about it?

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

            In order of length increasing, same for kmp.

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

              In KMP, it's also in DFS order, or in the order in which vertices were added. So you didn't answer the second part of my question: where in KMP do you need to think about which order (out of at least 3 possibilities) it should be?

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

                You don't need to think of it in both Kmp and Aho-Corasick if you have proper images of how it works in your head. Both algo proven by induction over length, so you use order of lengthes in your implementation. That's just ridiculuous that you think that it is hard to choose between dfs and bfs in such a case.

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

Can any one please help me about my solution of Problem B I use a O(n) algorithm but I get TLE.. http://codeforces.com/contest/963/submission/37431208

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

Скажите пожалуйста, будет ли разбор?

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

    Разбор будет скоро, я перевожу его на английский

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

Why is my solution for Div.2 C computing 1 as the answer for TC 7? LINK

Thank you in advance.

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

    While addition, subtraction and multiplication are straightforward in modular arithmetic

    ( (a op b) % mod = ((a % mod) op (b % mod)) % mod, where op is one of +,-,* )

    the same cannot be said about division:

    (a / b) % mod != ((a % mod) / (b % mod)) % mod. For instance, take (8/2) % 5.

    To do division in modular arithmetic, you multiply the numerator with the modular inverse of the denominator. A modular inverse for number a under the modulo n is such a number b that . This number b exists if and only if gcd(a, n) = 1. By Euler's theorem, we can conclude that b = aφ (n) - 1. You can read more about it online:

    Wikipedia

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

      1e9 + 9 is the prime number so you can use Fermat's little theorem.

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

        That is correct and is often what you use for solving tasks. I was just trying to offer a more general answer.

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

      a·b = 1

      b = ap - 2

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

        Out of curiosity, how will the following statement result in an overflow:

        (a / b) % m

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

          There's no overflow. The fact that division doesn't work in modular arithmetic doesn't have anything to do with a programming limitation such as integer variables having max values and overflowing. It just doesn't work mathematically.

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

hey, if someone could explain please why is the total weight of split of 8 equal 5? At 964A ... I mean, i found 4 of its splits but i can't find the fifth ... Thank you!