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

Автор cannor147, 5 лет назад, По-английски
Tutorial is loading...

Authors: MikeMirzayanov and geranazavr555

Authors' solution
Tutorial is loading...

Author: MikeMirzayanov

Authors' solution
Tutorial is loading...

Authors: MikeMirzayanov, cannor147 and geranazavr555

Authors' solution
Tutorial is loading...

Authors: MikeMirzayanov, cannor147 and geranazavr555

Authors' solution
Tutorial is loading...

Author: MikeMirzayanov

Authors' solution
Tutorial is loading...

Authors: MikeMirzayanov, cannor147 and geranazavr555

Authors' solution
Tutorial is loading...

Authors: MikeMirzayanov, cannor147 and geranazavr555

Authors' solution
Tutorial is loading...

Authors: MikeMirzayanov, cannor147 and geranazavr555

Authors' solution
Tutorial is loading...

Authors: MikeMirzayanov, cannor147 and geranazavr555

Authors' solution
Разбор задач Codeforces Round 568 (Div. 2)
  • Проголосовать: нравится
  • +53
  • Проголосовать: не нравится

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

very good contest!

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

How to solve C2 if 't' constraint would have been t<=10^5 (without segment tree and treap) ?

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

    Use two Priority Queues, in one keep those that pass and in the other those that fail. Before printing the result, you have to fail as students as needed to sum less than M. Then, while the greatest from the pq that passes is greater than the smallest of the pq that fails, swap them. Finally, while you can pass the smallest from the pq that fail for free, do it.

    My submission during contest: 55775417

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

      So you're pushing/popping same element multiple times. How are you sure this will work in the given time constraint? Can you please explain a bit more?

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

      I have used a similar method but couldn't get the answer ...

      What I am is doing deleting removing the greatest from the pq till the sum is less than M and then adding the smallest from the pq that fails until the sum is than M ...

      Can someone help me know why won't this method work?

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

      I solved this with a similar approach here: 55809687, but I believe this solution also depends on the low t constraint. The amount of elements that can be popped from the priority queue at the end depends on the possible difference in answers between two subsequent indices. With the current constraints, the possible difference between t values of two indices is 99, and since each t value must be at least 1, the difference in answer can be at most 99. If you were to have t go up to m, you could construct a case where you alternate t values between 1 and m. For the cases where t is 1, you only need to remove the t values that are equal to m, and thus the answer is current index / 2. For the cases where t is equal to m, you need to remove all previous values and thus the answer is the current index. Here, the amount of elements popped and pushed is O(n^2) and will not pass.

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

      In your code you have written saco.top(); inside the while loop. What is the value of saco.top() when i=0 and you haven't put anything inside it. Can you help explain the code ?

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

        when i=0 then u r correct that there will be nothing in pq but u will never go inside that while as first element will always be less than M. also this is mentioned in problem statement ** It's guaranteed that all values of ti are not greater than M. **

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

    I used two BIT arrays to find the answer, 55812830
    $$$su$$$ stores the prefix sum,
    $$$seen$$$ stores the sorted idx,

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

    https://codeforces.net/contest/1185/submission/55759936

    Top programmers usually have the best solutions. He basically puts the students in a multiset (multiset automatically sorts things in O(logN)) and if the sum is bigger than M, he subtracts the biggest students in the multiset and prints the answer. Just doing this would give TLE so he also deletes students from his multiset if the sum is above M. For example, take this case:

    5 100
    80 40 40 40 60
    

    first sum is 80, so no need to fail any students, output is 0.

    second sum is 120, so we need to fail one student, output is 1. Since the sum is now bigger than M, and it will always be bigger than M from now forward, its in our best interest to elements from the multiset until the sum is smaller than M.

    This solution would I think work regardless of the constraint of $$$t$$$

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

      No, I don't think this solution works for large $$$t$$$.
      e.g. N = 20000, t = 10000, M = 10000
      and the array are
      1...(repeat 10000 times) 10000... (repeat 10000 times)

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

        Maybe maintain an array that stores the sum after each $$$i$$$,and then when sum > M, we use binary search to find the first sum in the array that would get the current sum below M, maybe do $$$int index = lower__bound(sum_array.begin(),sum_array.end(),current_student)-sum_array.begin()$$$ ? Because sum-current_student is less than M. And then whatever index we get, we add it to every other result. This seems like a TLE as well tbh, but I'm too lazy to figure out a better solution.

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

          Can you please explain why this approach gives TLE isn't the complexity n(lgn+ n)

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

    I have used two Fenwick Trees + Binary Search. It will work for t <= 2e7. Code: 55863688

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

nice contest!!

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

Hey can someone help me in F Two Pizzas:

In the editorial it has been written: "Then, we should go through all possible masks, that could be reached by two different pizzas.

For each such mask we should keep two pizzas with the smallest total cost, which gives us that mask (i. e. their bitwise-or is equal to our current mask)."

My question is how to choose two pizzas of min-cost that generate a particular mask without going back to brute-force which would, of course, be a TLE.

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

Though G1 was a bit easier than F, it's still a really good contest for div 2. The score distribution is a bit weird since i saw someone who solved 8 problems have a higher rank than someone who solved all.

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

I solved G2 by using a $$$O(n^3T^2)$$$ solution. I think it's incorrect but I can't hack it.

Can someone help me hack it?

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

can somebody tell me why my code is incorrect? https://codeforces.net/contest/1185/submission/55763542 it is easy to read

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

For problem D cant we maintain a difference array after sorting the initial array of pairs . now we traverse the difference array and maintain a count of number of different elements in the difference array .

if there is only one element say 1,1,1,1... then we can output first or last index since it is in ap already , if the difference array is something like 2 2 1 1 then we output the first occurrence of the changed difference that is index 3 in the above array if the difference array is something like 1 2 3 .... then -1.

is this approach correct ?

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

    Your second case will fail on test 1 2 4 6 8 Difference array will be 1 2 2 2 and your output will be 2 instead of 1.

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

      Could u also explain how u solved Nick an array(CF round 569 Problem B)

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

        yes that was pretty simple one if you convert all elements to non negative integer that is either zero or positives. Now you just need to sort the array and then make elements negative pairwise so that you can get maximum product at the end. If your array length is odd then you don't need to add any condition you just need to leave the last element as it will handle itself the maximum product. For example if your array is -2 -4 -1 0 0 1 2 3 then after converting them to non negatives it becomes 1 3 0 0 0 1 2 3 now after sorting and making the elements pairwise negative you will get 0 0 0 1 1 2 3 3 --> -1 -1 -1 -2 -2 -3 -4 -4 now you can restore your array order by sorting it with index for that you can store it in pair.

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

          Thank u so much for sharing this approach. My approach was count number of positive and negative elements in array and if both positive and negative elements are even or odd make all elements positive elements negative. Else make all positive elements negative except the last one but it is giving me a wrong answer. Can u explain y my logic is wrong?

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

            Consider the following example array[]={-2 -1 2 1} according to your approach neg_count==2 and pos_count==2 here both are even hence you will perform the operation on all elements and your new array will be [3 0 -3 -2] which leads to zero product which is incorrect.

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

    Check my submission history :|

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

in solution of problem D, i don't really understand why we need to find the maximum difference between two elements in sequence maxd = max(maxd, a[i + 1].first — a[i].first) and how we to to know if we do that, it will correct ?

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

    Please, try one else. One of authors added another solution, which wasn't coincidental with editorial. I hope, it will help you.

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

Could someone elaborate more on the $$$3^9$$$ bruteforce to get the number of satisfied people for each mask?

Or as in this submission: 55810335, Why is making the outer loop as the loop over the bits, and the inner loop as the loop over the masks stops double counting. I don't seem to get what it is trying to achieve with order.

Here's the for loop, $$$B$$$ is a const int which is equal to $$$9$$$ and $$$cntHappy$$$ has the number of satisfied people for each mask and at first contains the count of the input masks.

    for (int j = 0; j < B; ++j)
    {
        for (int msk = 0; msk < (1<<B); ++msk)
        {
            if ((1<<j)&msk)
                continue;
            cntHappy[msk|(1<<j)] += cntHappy[msk];
        }
    }

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

    Can Anyone Please Explain how to solve C2 problem in given time constraints. I am not able to understand the solution.

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

      Use greedy approach,let's say u have available A marks out of M (u need to pass a student that have index i so A=M-marks[i] ).u want to fill Max amount of students in A so u check count of student having marks 1 to 100 (which, u are maintaining count). Now greedily fill A, so u will get maximum number of passing students.

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

Can anyone please explain this particular line of code of problem c2 posted by author and please also explain the reason behind this line.

k += (d + j — 1) / j;

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

    I will try to explain it. So, according to the editorial, this line will be run if we have situation, when $$$s_i + t_i - count_k \cdot k \le M$$$. And in this situation just $$$a_i + count_k$$$ may be not mimimal answer (but we want to output the minimal answer).

    So we need to free some $$$s_i$$$ minutes. We know that $$$k$$$ students' durations equal $$$count_k$$$. And for the minimal answer we need to add only $$$\lceil \frac{s_i}{k} \rceil$$$ to $$$a_i$$$. Let me rewrite this line in editorial's naming:

    $$$a_i += (s_i + k - 1) / k$$$

    Note that in programming `(A + B — 1) / B' is equivalent to $$$\lceil \frac{A}{B} \rceil$$$

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

Problem E

Getting error on test case 5 :

wrong answer actual picture doesn't equal to expected [test case 35]

Can anyone help me with that?

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

Can anyone explain the two BIT approach in C2?

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

I can't understand G2 editorial ... any help?

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

I can't understand the author's solution code of problem B(Email from Polycarp). Can anyone help me? TIA

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

    i think i am late but still... split function's work is to convert a string for e.g. hhelllo to h 2, e 1, l 3, o 1 now if u obtain this equivalent for both strings you can easily check if at each index, the alphabet is same and count for string t >= count of string s for that alphabet

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

D's test cases are weak..

some sols are failing at-

6

1 2 5 8 11 13

ANS= -1