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

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

1618A - Поликарп и суммы подпоследовательностей

Идея: Brovko, подготовка: Brovko

Разбор
Решение (Brovko)

1618B - Потерянная биграмма

Идея: BledDest, подготовка: awoo

Разбор
Решение (awoo)

1618C - Покраска массива

Идея: BledDest, подготовка: BledDest

Разбор
Решение (BledDest)

1618D - Массив и операции

Идея: BledDest, подготовка: BledDest

Разбор
Решение (BledDest)

1618E - Турне певцов

Идея: shnirelman, подготовка: shnirelman

Разбор
Решение (shnirelman)

1618F - Развороты

Идея: Lankin, подготовка: Lankin

Разбор
Решение (awoo)
Решение (BledDest)

1618G - Торговая задача

Идея: BledDest, подготовка: BledDest

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

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

At the beginning of the year i became expert, hopefully at the end of the year(tomorrow) i will become expert again. Nice problemset. Thanks for fast editorial.

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

Not sure if anyone else has made this connection yet, but Problem $$$A$$$ looks very similar to Bronze Problem 1 from the 2020 December USACO competition: http://www.usaco.org/index.php?page=viewproblem2&cpid=1059

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

Русскоязычный разбор поправлен (прошу прощения, что до этого он не подгружался).

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

I solved D using Knapsack DP , I found out that last 2*k elements would be paired . So while pairing them I should try to keep elements with same value in a set , as splitting them will contribute 1 to answer , and not splitting will contribute 0 . I implementated it using Bitset Link
Edit : It got hacked :((

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

Would anyone be kind enough to explain to me why these 2 submissions don't have the same result for problem e(https://mirror.codeforces.com/contest/1618/submission/139338958 https://mirror.codeforces.com/contest/1618/submission/139339631)? In the first submission I did a calculation using long long's in a cout statement, and in the second submission I swapped that with a calculation using a temp variable first then printing that variable. Is this something that I should be careful about and why does this happen? Thanks!

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

Why is the pairing in 1618D - Array and Operations optimal? It seems obvious but I can't find a proof for it.

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

    We can look this as an inequality. Let's suppose a >= b >= c >= d >= e >= f >= g >= h. And k=3. (it's a simplified version, but it can be generalized to any kind of array).

    First, we can see that the optimal solution gives \floor {d/a} + \floor {e/b} + \floor {f/c} + g + h.

    What will the answer become if we swap elements e and g ?

    It gives : \floor {d/a} + \floor {g/b} + \floor {f/c} + e + h.

    To prove that the latter is less than the former, we could prove that the difference between the former and the latter (former-latter) is <= 0.

    That brings us to prove that \floor {d/a} + \floor {e/b} + \floor {f/c} + g + h. - \floor {d/a} + \floor {g/b} + \floor {f/c} + e + h. <= 0. In other words \floor{e/b} + g — \floor{g/b} — e <= 0. Which is equivalent to (\floor{e/b} — \floor{g/b}) + (g-e) <= 0. The case e=g is trivial, suppose e > g. Than (\floor{e/b} — \floor{g/b}) <= 1 and (g-e) <= -1. Summing up these two inequalities, we obtain (\floor{e/b} — \floor{g/b}) + (g-e) <= 0, as desired.

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

Can someone helps me? In 2nd problem why my code fails the test cases https://mirror.codeforces.com/contest/1618/submission/139289954

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

I tried D with DP I was getting WA for testcase 2. I am not getting where I am going wrong,

Please check my submission and please tell where I am going wrong

Submission Link : My Submission Code

Thanks in advance for helping

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

Hi, I think I might confuse something. But in the F problem ( Reverse) how can you turn 23 (10111) to 59 (111011) ?

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

I had solved problem C by taking the LCM of both GCDs and then checking if the array is divisible by the LCM for both the cases and printing the respective GCD, but the code didn't pass the test. Below is the link https://mirror.codeforces.com/contest/1618/submission/139321336 I did the same thing but this time I used GCD which passed all the tests. Below is the link — https://mirror.codeforces.com/contest/1618/submission/139323889 Can someone explain what is the difference between both the codes and why the LCM one didn't pass the test?

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

can anyone please explain the intuition behind problem C?

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

    With practice, you will see that for these kinds it's better to evaluate all the possibilities to arrive at a conclusion. Adjacent elements needs to be colored differently...So the only two possibilities here are (even index elements colored blue and odd index elements colored red) and vice versa. Evaluate whether any of these can happen. To do so, see how can you find out a number that will divide all the numbers present at alternate indexes--->so you need to find the gcd of those numbers and then check whether the numbers at other indexes are divisible by that ...Could I make it clear ?

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

      Bt how can you prove that it will be the greatest common divisor but not other any divisor?

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

        Because, see, if the other numbers are not divisible by GCD , then GCD is the answer. If GCD divides at least one of the numbers that is supposed not to be divisible by the GCD ,then all the factors of GCD will also divide that number. Let GCD=x, the number that it divides is y which is supposed not to be divisible by x . Now let z be a factor of x. if x divides y, then z also divides y. if any other number is there other than GCD that divides all the numbers that it is supposed to divide, then this divisor will always be a factor of GCD. So it will face the same obstacle as the GCD faces .

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

Can anyone explain what is "string(1, char('0' + i))" this line doing ??? Thanks!! This is in editorial of F.

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

can anyone help me figure out why this program for Problem F terminates ? It passes all the test cases:

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

Stupid question about Problem C:

I'm trying to understand this line of code:

--> good[i % 2] = good[i % 2] && (a[i] % g[(i % 2) ^ 1] > 0);

Specifically this part:

--> && (a[i] % g[(i % 2) ^ 1] > 0);

What's the purpose of the XOR here?

Same question about this line:

--> ans = max(ans, g[i ^ 1]);

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

good contest but it need to strong pretest cases in problem d and f finally i realy sorry for every one get wrong answer in d test 25 i put it in hacks , i tried to cover corner case not to hack some one

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

If possible, add graphs tag to problem F.

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

In problem G can someone clarify how to use DSU to reach the solution. I understand the creation of graph but am unclear on how to use DSU.

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

    I didn't use graph or DSU. It's just interval merging.

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

      Can you please explain basic idea of your solution, I mean just a walkover. Thanks in advance.

      P.S: I could see your code but I don't want to as I want to code it on my own after knowing the basic idea you have implemented in your solution.

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

        First combine array A and B as a new array v, then sort it. what you need to calculate is the sum of maximal x values of each interval [i, j] where v[l] + k <= v[l + 1] (i <= l < j). So, initially you have n intervals, [1,1], [2,2], ... , [n, n] where n = v.size(). For each given k in increasing order, find out all i satisfying v[i] + k <= v[i + 1] (from a pre-sorted array). Merge the interval end at i and the interval start at i + 1. I used two arrays left and right to store intervals. use prefix sum array to calculate the number of elements coming from array A between [i, j] in O(1), then use another prefix sum array to calculate the sum of maximal x values of [i, j] in O(1). You can check my last AC code.

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

https://mirror.codeforces.com/contest/1618/submission/139274778 this my code of E question and I just got msg that my code is significantly match with this code https://mirror.codeforces.com/contest/1618/submission/139261121. please can anyone look into this because both codes are not same and I haven't done any unfair mean, you can also look into my profile.

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

Hey Everyone
Can anybody tell me how 'testcase: 1 576460752303423487' for problem F gives YES
According to me if x = 1.
You can change it to only 111...(any no of times)
but in this testcase, you can change it to 10000..(58 times). But How?

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

1) In problem G, what is the proof that the rebalancing step in the unite function (i.e. while (*bst[a].begin() < *wst[a].rbegin())) won't take too long in total?

2) In problem D, how to prove that the answer is:

$$$(\sum_{i = 2k}^{n}a_i) - max(0, f - k)$$$

after sorting the array in non-increasing order? (I got AC with it and it seemed very intuitive)

$$$f$$$ is the frequency of the most repeated element in $$$a[1..2k]$$$.

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

    the first one only runs n — 1 times, as there is only n — 1 segment and each one will be accessed only once.

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

    Regarding your second question, I had the same observation. This is my informal logic. We know that we are going to remove the first 2k elements when the array is sorted in non-increasing order. For each pair we remove, as long as the two elements are different, we can guarantee that they won't add anything to the score. Therefore, we are only concerned with pairs with two identical elements. We want to minimize those pairs in order to minimize the score. After some analysis, we can see that only the most repeated element in a[1...2k] matters. Consider the expression 2k — max_dupes, where max_dupes is the frequency of the most repeated element x in a[1...2k]. 2k — max_dupes represents the number of elements that are different from x, therefore, 2k — max_dupes operations will add nothing to the score. The remaining number of operations, which are unavoidable, will each add 1 to the score (bc numerator = denominator), which results in the expression k — (2k — max_dupes) = max_dupes — k. This equals the extra score added to the remaining sum of a[2k+1...n]. If max_dupes — k is <= 0, we know that there are no unavoidable pairs with two identical elements therefore we add max(0, max_dupes — k).

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

Can someone help me? In problem F, I do not know why my code fails. Thanks a lot.

https://mirror.codeforces.com/contest/1618/submission/139439943

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

There's an even simpler solution for D. First of all, you greedly add the first n — 2k numbers (after sorting of course), then, for the rest of the numbers, you check how many times each number appears. If there's a number that appears more than k times, then you know that there's no avoiding in adding one to the answer; you simply add the amount it appears — k to the answer.

139271250

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

Can anyone tell me what is the time complexity of the second solution of problem F?

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

For E, could you use FFT? I see a system of linear equations, and the resulting matrix is circulant. Hence, you could use a FFT and solve it in nlogn time. It's slower than the accepted solution, however. Still would be interesting to do.

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

Instead of pairing up the last 2k numbers like described in the tutorial for problem D, is it possible to just run the following O(n^2) algorithm: For each i in the range [n — 2k + 1, n — 1] we will look for the smallest index j such that arr[i] < arr[j] and then set arr[i] and arr[j] to -1 so that they aren't used anymore. And if we can't find any index j that works, just look for the smallest index j such that arr[i] = arr[j]. Then you just increase answer by 1 and once again set arr[i] and arr[j] to be -1. Finally, add the first n — 2k numbers to the answer as described in the tutorial.

My submission implements this algorithm and didn't pass, so I am wondering if there are any edge cases that break my O(n^2) algorithm. Here is my submission, just in case it is needed.

143369978

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

Here is a very interesting way to do E through solving a system of equations. Firstly, it is very easy to transcribe the problem into a system of equations. For example, when $$$n=3$$$, we have:

$$$1a_1 + 3a_2 + 2a_3 = b_1$$$

$$$2a_2 + 1a_2 + 3a_3 = b_2$$$

$$$3a_1 + 2a_2 + 1a_3 = b_3$$$

I chose to solve the systems using the inverse matrix method. In this method the goal is to calculate the inverse matrix of the system and multiply it by the constant vector ($$$b$$$) to get the solution vector.

Of course, calculating the inverse of our matrix is too computationally expensive, but due to the patterns exhibited on our matrix, the inverse matrix will also show some patterns.

After some experimentation with web tools to calculate some inverse matrices, I came to the conclusion that the inverse matrix for matrices derived from this problem:

  • Are composed of one single row that is cyclically shifted to the right to form subsequent rows
  • Have only 3 unique cell values, all 3 of which can be represented as fractions with equal denominators
  • In the first row, the middle $$$n-2$$$ cells have a numerator of $$$1$$$
  • The first element of the first row has a negative numerator
  • The last element of the first row has a positive numerator.

Furthermore, each of the 3 unique cell values exhibit a pattern of their own as $$$n$$$ varies:

  • The common denominator is the $$$n$$$-th pentagonal pyramidal number.
  • The negative numerator follows the sequence $$$0, -2, -5, -9, ...$$$
  • The positive numerator follows the sequence $$$2, 4, 7, 11, ...$$$

We now have enough knowledge to generate the inverse matrix of our system of equations very quickly. By taking advantage of the pattern in each row (noted previously), we can calculate the product of our inverse matrix with the constant vector in $$$O(n)$$$ time through a sliding window method.

Here is the final solution: https://mirror.codeforces.com/contest/1618/submission/208803182

While this solution is interesting, it's biggest crutch is that my observations for the inverse matrix would have to be correct for all $$$n$$$. I have very little experience in this area so all I could do is hope for the best. I would love to hear some rationales from some people who are more experienced in this area!

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

Can We Solve Problem D Using Dynamic Programming?

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

Greetings, I tried to write a solution for D Array and Operations using basic algebra operations and pigeon hole principle
https://mirror.codeforces.com/blog/entry/138883

any constructive feedback is much appreciated!