Vovuh's blog

By Vovuh, history, 19 months ago, In English,

961A - Tetris

Editorial
Solution (Vovuh)

961B - Lecture Sleep

Editorial
Solution (Vovuh)

961C - Chessboard

Editorial
Solution (Ajosteen)

961D - Pair Of Lines

Editorial
Solution (adedalic)

961E - Tufurama

Editorial
Solution (Ajosteen)

961F - k-substrings

Editorial
Alternative solution (jtnydv25)
Solution (adedalic, suffix array)
Solution (adedalic, hashes)

961G - Partitions

Editorial
Solution (adedalic)
 
 
 
 
  • Vote: I like it
  • +38
  • Vote: I do not like it

»
19 months ago, # |
Rev. 2   Vote: I like it +9 Vote: I do not like it

Damn, I used Order Statistics tree to solve Problem E after the contest, and now I find it can be done with BIT.

http://codeforces.com/contest/961/submission/36984273

»
19 months ago, # |
  Vote: I like it +1 Vote: I do not like it

nice problemset :)

Had solved E in 3 hours by using persistence segment tree. By seeing the editorial i think that i know nothing :)

Nice editorial!

  • »
    »
    18 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I solved E with persistence segment tree too, but it didn't took too much time because the only difference between normal segment tree and persistence segment tree is that you have to change the update process of later.

»
19 months ago, # |
  Vote: I like it +6 Vote: I do not like it

It's beautiful problemset, thx!

»
19 months ago, # |
  Vote: I like it +6 Vote: I do not like it

Geomety always seems to get me..

»
19 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Can someone give me more detailed explanation of question B?

  • »
    »
    18 months ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    First, in O(N) time, we can calculate "total", the current total number of theorems that Mishka will be able to write without the secret technique.

    Now we calculate the EXTRA number of theorems (apart from the ones for which Mishka needs no help) that Mishka will be able to write if the secret technique will get used at the first minute; this is O(K) of course. Call this number "cumu". Now in O(1) time, we can find out the number of theorems that Mishka can write down if the secret technique will get used at the second minute (just remove the number of theorems for the first minute (if applicable) and add the number of theorems for the (K+1)th minute (if applicable)). Keep "sliding" till you reach the end. Of course, maintain a maximum of what you have seen so far, which we call maxcumu.

    Finally, add "maxcumu" to "total". http://codeforces.com/contest/961/submission/36992860

»
19 months ago, # |
  Vote: I like it 0 Vote: I do not like it

I used just the priority queue and AVL for E and it just worked fine. In min priority queue I save pair of (ai,i). On reaching i+1 I pop all those ai from priority queue where aj<i+1 (j<=i) because they can't pair with further seasons. Now I need to find those indices which are in priority queue and are less than a(i+1) because if index is greater than a(i+1) it won't be able to pair with season(i+1). For doing this I use an AVL. Whenever I am popping from priority queue I delete the corresponding index from AVL. I then count all indices lesser than (ai+1) and it to my final answer. Then finally I insert the pair (a[i+1],i+1) to priority queue and index i+1 to AVL. (Both operations take LogN complexity). It was much easier to code and code for AVL is easily available on GFG. My Solution

  • »
    »
    19 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I have made the same, but with Fenwick tree (BIT), much more simple to code.

»
19 months ago, # |
  Vote: I like it +4 Vote: I do not like it

Nice F

»
19 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Amazing problemset. I solved E after the contest using merge sort tree, it was pretty intuitive, and good oportunity to learn to code merge sort tree (because i didnt implement it before, only knew idea). Anyone else solved it this way?

  • »
    »
    18 months ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    Yah ! I also sloved it using merge sort tree.

»
19 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Can anyone help me in understanding Problem E?

  • »
    »
    18 months ago, # ^ |
    Rev. 2   Vote: I like it +3 Vote: I do not like it

    Observe that for some season i we'll only get a collision with an episode of season j where j < i if aj >= i and ai >= j. So we just need to able to answer for a particular season i how many seasons with index j such that j < i have aj >= i and ai >= j. We can do this query for all i (using a merge-sort tree for example) and then report the answer.

»
18 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

For E, just use BIT to maintain sorted segments. Then use binary search (lower_bound in C++) to get the answer in each segment. I think it's the most simplest approach (or the best answer especially in a time highly limited competition).

Here is my code 36971807

Most of the shortest answers are done by this way.

  • »
    »
    18 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Could you elaborate on your method? Looks interesting

    • »
      »
      »
      18 months ago, # ^ |
      Rev. 2   Vote: I like it +3 Vote: I do not like it

      Well. In this problem, we need to calculate how many numbers are greater than i in the range [i + 1, a[i]].

      Let d[l, r, x] denote how many numbers are greater than x in the range [l, r].

      Obviously, d[l, r, x] = d[1, r, x]-d[1, l-1, x] (prefix sums)

      Then you can use Binary Indexed Tree (BIT) with vector, which means each node of the BIT is a vector that collects numbers in a range, just like the node of a typical BIT sums numbers in the range.

      After sorting each vector, you can use binary search to get answers in each vector. By using BIT query method, you can form prefix sums and get d[l, r, x].

      • »
        »
        »
        »
        18 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        What will be the complexity of this solution? Like if You sort vectors in every node of BIT? Won't it be too much? Further, what will be the max size of a any vector representing a node?

        • »
          »
          »
          »
          »
          18 months ago, # ^ |
          Rev. 2   Vote: I like it 0 Vote: I do not like it

          Each number appears in O(log n) vectors. So the space complexity is O(n log n). Time complexity is O(n log^2 n).

          Well, the max size of a vector is O(n). However, the average size of vectors is just O(log n).

»
18 months ago, # |
  Vote: I like it 0 Vote: I do not like it

For problem D what would be the approach if maximum number of lines allowed were 3?

  • »
    »
    18 months ago, # ^ |
    Rev. 3   Vote: I like it +3 Vote: I do not like it

    This is one thing I could think of; I am sure we can do better. Assume n >= 4, and assume that the n points lie on 3 lines. Consider any four points (say, the first ten points given). By Pigeonhole Principle, some 2 points lie on the same line. And well, take all cases. Once you are done finding one of the lines, the problem reduces to the given problem.

    Another less "casework" way considers n>= 10. Consider the first 10 points. Again by Pigeonhole Principle, some 4 points lie on the same line, and (I guess) we can also prove that if four points are collinear, then one of the lines must pass through them. So just find a quadruple of points that are collinear. If there does not exist a quadruple, then our assumption is false, otherwise the quadruple determines one line, and the problem has been reduced to D.

  • »
    »
    18 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Another solution which can be easily generalized for more than two lines is: pick two different points at random, remove them and all points collinear with them and repeat until you have drawn expected number lines, and repeat the whole process until you have found way to partition all of the points or until clock() < TIME_LIMIT * CLOCKS_PER_SEC. Suppose pn points lie on first line and qn on the second (p + q) = 1 then probability of choosing points lying on the same line is roughly p2 + q2 which is greater or equal to ). In case of 3 lines we have at least chance for our first guess and at least for our second guess. which is total (or for k lines ). For k ≤ 5 this should be enough.

    • »
      »
      »
      18 months ago, # ^ |
      Rev. 2   Vote: I like it +10 Vote: I do not like it

      But the random can be hacked in open hacking……like 36960802

      • »
        »
        »
        »
        18 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        It can't be if I seed random number generator with the hash of the input. Or at least hacking it would be much more difficult.

»
18 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Can someone explain me the question D ?

»
18 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Can anyone help me in understanding Problem c?i am not getting tutorial too.

  • »
    »
    18 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    We have 4 pieces of board so to make a new chessboard out of the 4 we need 2 pieces with black cell on the (0,0) position and 2 pieces with white cell on the (0,0) position. Also note that once we know the color of (0,0) position we can make the whole chessboard out of it. So we find the cost of converting each piece into two chessboards — one with white cell at (0,0) and another with black cell at (0,0) and then we calculate the minimum of all possible ways.
    My solution

»
18 months ago, # |
  Vote: I like it +3 Vote: I do not like it

Just wanted to mention that F is essentially the same (actually more explicit) as an old POI problem: https://main.edu.pl/en/archive/oi/19/pre

»
18 months ago, # |
  Vote: I like it +8 Vote: I do not like it

How to solve problem D for N points and K lines?

»
18 months ago, # |
  Vote: I like it +34 Vote: I do not like it

Something about Problem G. I guess most of us get the formula below easily:

But the Editorial above claims:

So may anybody prove that:

  • »
    »
    18 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I would gladly hear the formal proof of equation myself since it doesn't sound like easy transformation.

  • »
    »
    18 months ago, # ^ |
    Rev. 6   Vote: I like it +1 Vote: I do not like it

    Here is a proof I thought of. Also, sorry for too many revisions :P

    Consider n students who wish to participate in a contest. They must enter themselves in exactly k non-empty groups. One of these groups is a special group who gets to participate in Div 1, while the others participate in Div 2. Furthermore, Alice, one of the students, is very good at coding, so she will always participate in Div 1. Furthermore, the special group has a team leader. We count the number of ways C of partitioning the students in two ways.

    First, we select, out of n - 1 students, j - 1 students who, along with Alice, form the special group. This can be done in ways. Now the n - j normal students can be partitioned in ways, and the team leader of the special group can be chosen in j ways. Thus .

    Another way is this: Suppose Alice is the team leader. Then simply partition the n students into k groups in ways, and the team Alice belongs to is special. Otherwise choose a team leader out of the remaining students in n - 1 ways (call this chosen leader Bob), and partition the n - 1 students other than Bob in ways. The one Alice belongs to is the special group, so Bob belongs to that group of course. Therefore .

    • »
      »
      »
      18 months ago, # ^ |
        Vote: I like it +14 Vote: I do not like it

      Yes, you are right, but you make exactly what problem G asks. Your proof is just a more formal than from editorial. In other words, formulas are same because they count same thing.

      What I (and probably, Blue233333) expected are just formal equivalent transformations of left and right parts using some properties of Binomial Coefficients and Stirling numbers.

      • »
        »
        »
        »
        18 months ago, # ^ |
        Rev. 2   Vote: I like it +5 Vote: I do not like it

        With swm_sxt and Zsnuo's help, I find an approach to use equivalent transformations to prove that, but I am still a little confused.

        However, I don't understand the last step's formula transformations very clearly, while I could only understand it with this: Dividing n people into k non-empty groups, means that we first choose j, 0 ≤ j ≤ n - 1, people to be members of person n's group, and then divide the remained persons into k - 1 groups.

        • »
          »
          »
          »
          »
          14 months ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          You can check it at wikipedia.

»
18 months ago, # |
  Vote: I like it 0 Vote: I do not like it

There are n circles drawn on a piece of paper in such a way that any two circles intersect in two points, and no three circles pass through the same point. Turbo the snail slides along the circles in the following fashion. Initially he moves on one of the circles in clockwise direction. Turbo always keeps sliding along the current circle until he reaches an intersection with another circle. Then he continues his journey on this new circle and also changes the direction of moving, i.e. from clockwise to anticlockwise or vice versa. Suppose that Turbo’s path entirely covers all circles. Prove that n must be odd.

»
18 months ago, # |
  Vote: I like it 0 Vote: I do not like it

can someone please explain me F. I didn't get the editorial :(

»
18 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Vovuh can you explain "961E — Tufurama" more details so I can get it. Though I solved it using merge sort tree but I want to learn your solution approach.

»
18 months ago, # |
  Vote: I like it 0 Vote: I do not like it

I think problem D and 849B are a little alike. At least almost the same solution applies to both I guess.

»
16 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Here is my blog post on the very elegant geometry problem D :)

»
7 months ago, # |
  Vote: I like it 0 Vote: I do not like it

i feel like my brain expanded after solving E xD