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

Автор Vladosiya, история, 7 месяцев назад, По-русски

1881A - Не пытайтесь посчитать

Идея: Vladosiya

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

1881B - Три паутинки

Идея: Gornak40

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

1881C - Идеальный квадрат

Идея: myav, MikeMirzayanov, Vladosiya

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

1881D - Уравняй делением

Идея: myav

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

1881E - Блоковая последовательность

Идея: MikeMirzayanov

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

1881F - Минимальное максимальное расстояние

Идея: senjougaharin

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

1881G - Аня и таинственная строка

Идея: Gornak40

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

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

I just have a question: Why is the algorithm for F correct? What's the intuition behind it?

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

    Its like diameter of the tree and you want to get a point in the middle of it you can say as a centroid

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

      Yes, I know, but we essentially don't care about which nodes are marked and which ones are not.

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

        Assume the tree is rooted at a marked node. If you are at the deepest marked node on a branch and move further down that branch it will increase the distances to all marked nodes by 1 (meaning the value of that node will be greater than the marked node you came from). You can therefore remove any nodes past the deepest marked node on each branch. From this it follows that you have a tree where all the leaves are marked and at that point it's the standard algorithm for finding the largest distance from a leaf.

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

          can't we do it with rerooting?

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

            I actually did it with rerooting, with lazy segment tree. You can check out my submission 227869909 .

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

              There is no need for a lazy segment tree to do the rerooting.

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

              My rerooting with prefix and suffix sum. It is really a bit too more complicated, so I missed the first AK in div 3 (got AC after the contest 12min later, because of a little afraid of TLE by NodeJS). https://codeforces.com/contest/1881/submission/227927645

              The first DFS will calculate 3 kinds of values,

              • dp[u], the max length from u to a marked node under u's subtree

              • prefix[u][j], the max length from u to a marked node under u's [0,j] children's subtree

              • suffix[u][j], the max length from u to a marked node under u's [j,] children's subtree

              The second DFS is rerooting. For each u, its answer can be calculated by two parts,

              • dp[u], to nodes under u's subtree

              • out, to nodes not under u's subtree

              When rerooting from u to v, out is updated by 3 parts. All of them should increase 1 if necessary.

              • u's out

              • u itself

              • max(prefix[u][j-1], suffix[u][j+1]), with v is u's jth child

              Hope above can help you improve understanding of rerooting, even this problem is not the best application to be solved.

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

              What is the time complexity of below code for problem D written by me..I'm little bit confused about the TC of my code..

              include <bits/stdc++.h>

              using namespace std;

              define fastio() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)

              //#To find min divisor of N int min_divisor(int n){
              for(int i=2; i<=round(sqrt(n)); i++){ if(n%i==0) return i; } return n; }

              int main(){ fastio();

              int t;
              cin>>t;
              
              while(t--){
              
                  int n; 
                  cin>>n;
              
                  unordered_map<int,int> m;
                  for(int i=0; i<n; i++){     
                      int x;
                      cin>>x;
                      int min_div = min_divisor(x);
                      while(min_div!=x){              // what is the TC of this while 
                          m[min_div]++;               // is it simply O(logn) or O(logn*sqrt(n))
                          x /= min_div;               // or something else please tell me!!
                          min_div = min_divisor(x);
                      }if(min_div!=1) m[min_div]++;
                  }
              
                  bool flag = true;
                  for(auto &pr : m){
                      if(pr.second%n!=0) flag = false;
                  }
                  cout<<(flag?"YES\n":"NO\n");
              }

              }

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

    F can also be done in a similar fashion to Tree Distances

    Submission for Tree Distances

    Solution for CF: 227871270

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

      Exactly! Problem F can be considered as the special case of this one. 227869702 Here's mine with a slightly different approach.

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

    I mean this finding longest chain is quite common(at least i saw some of them before in div 3) Also I first found out the longest chain trick here(hard problem): https://oj.uz/problem/view/CEOI21_newspapers

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

"the author is lazy"

Pretty obvious from the way this editorial is written

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

For problem 1881F - Minimum Maximum Distance , can someone please tell the proof why it is always true to consider the longest distance between the labelled vertex and then divide it by 2 then take ceil of it.

After considering some examples it becomes somehow convincing but not very intutive about why that condition will always be true.

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

    Define $$$dist(i,j)$$$ as the distance between node $$$i$$$ and node $$$j$$$.

    Assume that there are $$$3$$$ labelled vertices $$$a,b,c$$$ and $$$(a,b)$$$ is the pair that creates longest distance from two labelled vertices. To find the node position that makes the minimum value of maximum distance to either $$$a$$$ or $$$b$$$, ofc we choose the node (call this node $$$d$$$) that resides in the middle of the path from $$$a$$$ to $$$b$$$ (since if without loss of generality we assume $$$dist(d,a) \leq dist(d,b)$$$, then $$$dist(d,b) = \bigg\lceil\frac{dist(a,b)}{2}\bigg\rceil$$$ is the maximum from both and this is the min value of $$$dist(d,b)$$$).

    Now, suppose $$$dist(d,c) > \max(dist(d,a),dist(d,b))$$$. Then, the longest distance from two labelled vertices must be the pair $$$(c,a)$$$ or $$$(c,b)$$$ (since $$$dist(d,c)+dist(d,b) > dist(d,a)+dist(d,b)$$$ and $$$dist(d,c)+dist(d,a) > dist(d,b)+dist(d,a)$$$) which results in contradiction.

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

C was the coolest one and it's not even close

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

    bruh I felt that G was much more interesting than all the problems(despite me tryping 11 attempts to AC G)

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

In problem F how can we be sure that ceil(n/2) is the only minimum ans compared to other nodes ?

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

In problem F how can we be sure that ceil(n/2) is the minimum answer compared to other nodes? Can someone please express their ideas on this?

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

Starters were bad(ABC) but the main course was good(DEF) but i am not able to understand the bill(editorial)

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

    tru, i dont really enjoy ABC this round. DE was kinda meh for me. FG was quite interesting to play around with

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

      can you explain to me why in E we are updating dp[i] as

      dp[i]=min(dp[i+1]+1,dp[i+a[i]+1]) and not as

      dp[i]=min(dp[i+1]+1,dp[i+a[i]+1+j]+j) for all j st i+a[i]+1+j<n indexing from 0.

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

        Depends on how you define your DP. My design was that dp[i] = minimum removals I can have after considering all the values from [i, n — 1].

        Case 1: We don't take the current index.

        That means that we will need to remove this index. So, dp[i] = min(dp[i], dp[i + 1] + 1).

        Case 2: Take the current block.

        That means that we will need to remove all the values from [i, i + a[i] + 1]. So, dp[i] = min(dp[i], dp[i + a[i] + 1]). Need to make sure it is not out of bound. You can only end up at i + a[i] + 1, nowhere else.

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

          I am saying that when you take the current block, it means you will take a[i] number of elements with you and then consider the next block. So I am saying that we pop some more values before taking the a[i] values and it can land us an even better solution. Thats y i am checking for all j possible

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

            From the definition of my DP state, we know that dp[i] is the minimum removals after considering [i, n — 1] so that means that even if you check all j's, it has been it has been considered in dp[i+a[i]+1] already

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

Task D

If we assumed 1s can calculate 10^8 times, but in the worst condition(all a are equal to 999983), it will judge near 2000(t)*10^4(n)*10^3 times. Would it TLE?

I am a novice and thank you for your generous advice and point out my mistakes.

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

https://ideone.com/lyUPEZ

problem F c++ BFS code: why RTE on test 3 ???

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

    Ok let me show some potential improvements of your code:

    Why you are wrong: You missed out the corner case (n=1) where deg[1]=0 meaning your "start" is undefined and therefore shows runtime error. Meanwhile, the solution is wrong(after I tested it with the fixed code).

    Data Structures used: You dont need to push the k values into a set instead use a boolean vector or smt. set requires O(nlogn) which means you will waste precious time if you are using set.

    Your code checks if the root is in the set and the adjacent elements as well, you can generalise it by putting it after int node=q.front(); q.pop(); if(bla bla bla) mdis.push_back(...). You can save some lines of code.

    You can try learning how to write functions such as function<void(int)> bfs=[&](int root){ code here}; this allows you to write the function inside your main fucntion where you dont need to pass all the arrays and stuff. You can access it inside the function. This should save you some implementation time as well.

    Your code is not very clean (for a guy like me), therefore hard to read. I saw some parts of the code that has strange spacing. I used to be a template monster with around 400 lines of templates, but I find it hard to debug if I write a code with lots of shortforms(for some reason). I recommend spending sometime either looking at other people's code and learning a neater way of writing it. I'm not pinelizing you, just giving some personal suggestions

    Neater and fixed code(although it is wrong): Sorry that I deleted the front part of your code.

    code is here: https://ideone.com/fN9WEY

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

Its a request for the author that do consider this point too that editorial is also referred by the beginners so they should make this editorial keeping in mind that beginners should also understand the intuition behind, making this platform truly helpful for the beginners as well!

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

I lost the top 150 due to hacking task D :(

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

Simple and insightful Video Editorials for A-E.

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

Why is my code for incorrect? I feel like it closely resembles the intended idea. It's prob D. Please help me My code

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

For F, It's always better to re-construct the tree like this.

Tree

It's related to tree diameter (I guess there's no formal proof but this blog will help Blog)

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

Can anyone please explain how does D solution works? Can't able understand how counting frequency of prime divisors gives our answer.

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

    Let's use two ideas:

    1) Every number can be represented as a product of prime numbers (= prime divisors). This is known as factorization.

    2) If two numbers are equal, they have the same set of prime divisors.

    So, the operation in the problem allows you to "take" one prime divisor from a[i] and "give" it to a[j].

    If, after doing this operation several times, we can rearrange the divisors so that every number in the array has the same set of divisors, then the answer is YES.

    To check that this is possible, we can simply count the number of occurrences of each divisor in the products.

    For example, consider test case 4:

    4

    30 50 27 20

    30 = 2 * 3 * 5

    50 = 2 * 5 * 5

    27 = 3 * 3 * 3

    20 = 2 * 2 * 5

    We have four occurrences of "5", four occurrences of "3" and four occurrences of "2". By doing the operation several times, we can turn each number into 2*3*5.

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

Only AC 1 problem... f**k me

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

If someone prefers video explanations or interested in knowing how to think in a live contest or reach to a particular solution.
Here is my live Screencast of solving problems [A -> E] (with detailed commentary in Hindi language).

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

Can G solved with sqrt-decomposition?, I'm getting WA2 Code

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

    I think it shoud be fine, WA means your code has some errors not TLE. But im pretty sure if your code has a large constant factor with sqrt-decomposition, your code might TLE

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

      Yup I know, I just wanted tye TLE verdict not the WA one to make sure that my idea is correct.

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

        Erm i also got many wa2(you can see from my submissions) I had many WA2 because I even pushed l into my valid answers when s[l-2]==s[l] but actually its invalid. If l is in the set meaning s[l]==s[l+2]. So check if your program has valid answers correctly. Also similarly for r with r+1 and r+2. r-1 with r+1.

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

the editorial is short and to the point!!

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

.

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

Problem F solutions are based on the tree diameter, It takes some greedy proofs but in the end you can convert the problem to a direct tree diameter problem. Here's a blog

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

What does question C mean? please help me

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

    erm C is actually straightforward. Turning 90 degrees clockwise is not hard to understand. One operation actually just mean that you turn one cell's values to the next alphabet (a->b).

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

      I know What you mean. But I don't see example 4.Why 5?

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

        so the test case is

        baaa abba baba baab

        now you can change a on the (1,4) cell to b

        baab abba baba baab

        now for the b on the (3,1) cell we will have to change the (1,2) , (2,4) and (4,3) cells to b

        bbab abbb baba babb

        lastly change the a at the (3,2) to b

        bbab abbb bbba babb

        so in total 5 operations

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

operation codeforces

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

Any one Feels that this contest was not for Div.3 ?

It seems to be Harder :(

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

One more opportunity to be filled with shame.

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

How do I solve 1881G - Anya and the Mysterious String with Segment tree using Lazy propogation? This is what I've done 227967016, I haven't used Lazy propogation and it's TLE. Thank you in advance.

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

    I guess its pretty obvious but let me just repeat the obervations:

    1. You only need to keep track of palindromes of size 2 and 3 only. pairs exist like this: (i,i+2), (i,i+1). Now since we do +x to every element in a range, we need to do range add(I used fenwick tree but lazy segment tree is also fine).

    2. Hence we can store possible elements that has pairs (i,i+1), (i,i+2). Note : We store i not i+1, or i+2.

    3. We only need to update (l-1,l) (l-1,l+1), (l-2,l), (r-1,r+1), (r,r+1) and (r,r+2) since the elements in range [l,r] is not changed.

    4. Store the indexes in a set, binary search to find if right end<=r

    Now you have finished the problem~~~

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

Why this code doesn't work for problem D?

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

Could someone explain me the E? How to think the dp which from right to left

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

    Let us say we have block: 2 3 4 5 2 1 1

    We can see that if we choose a[0], we continue with array 5 2 1 1

    Meaning, its possible to make it into smaller subtasks: use dynammic programming.

    We can see that if we want the minimum value for dp[0], we need to find dp[0+a[0]+1]=dp[3]

    But we know, we cannot choose a block of 5. Hence, dp[3]=dp[4]+1.

    Then we can see that either dp[i]=min(dp[i+1]+1,dp[i+a[i]+1])

    Does that make sense? Ill explain further if that is not clear enough

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

      i have a small question i used to solve dp by thinking bottom up and extending the problem (for example the subset sum problem [(Previous SUM)(Extended Number)] and now i can solve it by checking the previous state) however in this problem i failed to find a bottom up solution :(

      you should start with the whole problem then break it down (Top Down Approach)

      the question: are there certain problems which can be solved by only one of the 2 approaches?

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

        I actually understand dp as a breakingdown of subtasks, where you have the dp states as the stuff you need to record down for that each subtask.

        Tbh, I actually dont really think in the form of top down or bottom up? I would just think how the subtask can come from. The number of states of the dp would be determined by yourself, so its all good as long as you define it right.

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

I feel it was really a nice contest for anyone starting out on cp in the sense that it offers a good mix of adhoc and dsa

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

Имеется вопрос. Как я понимаю, на этом раунде задачи сразу проверяются на всех тестах. Тогда почему через день после раунда вердикт задачи B с "Полного решения" поменялся на "Неверный ответ на тесте 18"? Типа добавили новые тесты на некоторые задачи?

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

f can be solved using dp Let define d(v) as the max distance from vertex v to a labeled vertex in its subtree and define g(v) as the max distance from vertex v to a labeled vertex which is not in the subtree of v then d(v)=max(d(child of v)+1), g(v)=max(g(parent of v)+1,d(sibling of v) + 2) then f(v)=max(d(v),g(v))

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

F is similar to

The only change is to fix the end points of the diameter as RED nodes.

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

Help please, why my solution has TL?(problem D) 228167450

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

I did rerooting for F, would've gotten top 100 or something but I had to have a typo that I didn't see

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

I have a question: why is such brutal decomposition with every integer working with Problem D It was my idea in the first place during the contest but I gave up cause I thought it would be to slow. So I took a binary search approach My code and resulted in a TLE.

Why is tutorial's code fast enough or why is my code too slow?(I learned after a better approach of precomuputing the smallest prime decomposition of every number But still my original code confuses me.)

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

C++ Solution for A 227837666

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

C++ solution for B 227857937

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

C++ solution for C 227893269

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

C++ solution for D 228002421

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

C++ solution for E 228148743

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

C++ solution for F 228240931

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

In F, "Let's run a breadth-first traversal from any labeled vertex v1 and find the farthest other labeled vertex v2 from it.".

Why cant we take a "non marked" vertex v1 and find farthest marked v2 ?

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

    Even if we take non marked vertex also it's working. Not sure why the author intended to do like this ?

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

Is there a more efficient way to solve A??

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

I have two nicer(?) solutions than the official ones.

B: Suppose everything has length $$$l$$$ in the end. Then $$$l \mid A$$$, $$$l \mid B$$$, $$$l \mid C$$$ (proof: run the splitting apart in reverse). This is also sufficient, and uses $$$\frac{A}{l} + \frac{B}{l} + \frac{C}{l} - 3$$$ operations. The number of operations is minimised when $$$l$$$ is maximum, so $$$l := \gcd(A, B, C)$$$; to solve the problem just check if the minimum is at most 3. 228383697

(I saw a lot of people at the top of unofficial standings iterating over $$$(A + B + C) / l$$$ and testing each of them using this condition; it's quite strange to me that they didn't use GCD instead...)

G: There is no need for Fenwick trees or segment trees, you can check palindromes using just the difference array (and maintain bad positions using std::set as in the tutorial). 228383431

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

Can someone Please help me with the problem F . My code 228434471 is giving wrong answer at Test 4.

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

Problem G with sets and vectors is also possible submission

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

Another solution for E:

Let us consider each index i, and check if i+a[i]<=n. If so, then we could generate an interval [i,i+a[i]] and do that for all i from 1 to n. Now, we have a list of intervals and we want to find the maximum range-sum for non-overlapping intervals. This could be solved using dynamic programming with the following algorithm (I took it from a website and here is the link (https://itecnote.com/tecnote/maximum-sum-of-the-range-non-overlapping-intervals-in-a-list-of-intervals/):

Sort the intervals in order of their end timings. sum[0] = 0. For interval i from 1 to n in sorted array: j = interval in 1 to i-1 whose endtime is less than beginning time of interval i. If j exist, then sum[i] = max(sum[j]+duration[i],sum[i-1]). else sum[i] = max(duration[i],sum[i-1]). j can be found using binary search, i.e. in log n time. Hence algorithm takes O(n log n) time. The submission: https://codeforces.com/contest/1881/submission/228522440

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

Nice Contest, Thanks for the editorial.

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

Can someone please explain the intuition behind problem F editorial? I knew it's right but I don't think next time I saw a similar problem I can just figure it it's about the tree diameter.

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

Can anybody can tell me whether my solution in F can use when it have the edge-weight?Can it be called DP?228766385

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

Is it possible to solve F with centroid decomposition? I had TLe attempts

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

Can someone explain what does this mean ~ Notice that palindromes do not appear or disappear inside a segment, but they can appear or disappear at its boundaries

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

I did the same thing for A( 1881A—Don't Try to Count), but I got hacked.

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

Problem F: for anyone wondering about the intuition behind the solution, here's a short rundown of the logic, based on the dfs algorithm for finding the diameter of a tree.

Assuming k>=2 (otherwise the solution is trivial):

-> Assume A and B to be the two marked nodes that are the furthest away from one another in the tree. The first observation we need to make is that the maximum path from any and all nodes in the tree to a marked node will always lead to A or B, i.e. either A or B (or both) will be the furthest marked nodes from any node in the tree. This can be visualized by rooting the tree on an arbitrary node on the path from A to B.

-> Now we will consider all nodes at once and using the assumption that each node's maximum distance path will lead to A or B, whichever is furthermost from said node, we can observe that the minimum distance maximum path cannot start from a node outside the path from A to B, because it would be larger than that of a node on that path.

-> This confines the possible candidates for the node(s) which give the minimum maximum distance on the path from A to B. If we conceptually flatten this path to a line, we can see that the answer has to be given by the node(s) at its center, because they represent the minimum of the function max(distance to A, distance to B) on that line. Thus, the answer has to be (distance from A to B)/2, meaning the length of the maximum path from the node at the center of the path to either A or B (which are equidistant). In case the length is an odd number, then the center node will be slightly skewed towards A or B, increasing the length of the path by 1, hence the need to round the number d/2 up.

-> The problem is now reduced to finding the two furthermost marked nodes on the tree and halving their distance, which can be solved with a simple tweak of the standard tree diameter algorithm mentioned above.

My implementation: 232911915 Hope this helps!

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

can anyone explain me, in the second problem why did he minus 1 after dividing rest both numbers with minimum number??? I don't catch the idea behind that.

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

G can also be solved only with segment tree. In each node we keep track of the first two characters in the interval as well as the last two (or just one character if its a leaf). Then when we merge two intervals we just keep check if a palindrome is formed at the edges. Updates can also be handled very simply by just applying the shift operation to the characters we keep track of. AC with this idea: https://codeforces.com/contest/1881/submission/240931303

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

how is the time complexity O(2e5⋅n⋅m) of problem a? thanks in advance .

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

b/a−1+c/a−1≤3 question no B . what's the reason behind this logic? someone pls help me to understand

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

can you explain to me why in E we are updating dp[i] as

dp[i]=min(dp[i+1]+1,dp[i+a[i]+1]) and not as

dp[i]=min(dp[i+1]+1,dp[i+a[i]+1+j]+j) for all j st i+a[i]+1+j<n indexing from 0