MikeMirzayanov's blog

By MikeMirzayanov, history, 8 years ago, translation, In English

Welcome to 2016-2017 CT S03E05: Codeforces Trainings Season 3 Episode 5 (2016 Stanford Local Programming Contest, Extended). The training duration is 4.30 hours. It is opened for teams as well as for individual participants. After the end you may use the practice mode to complete problem solving. Also it will be available as a virtual contest for whose of you who can't take part today. Please, do not cheat. Only fair play!

Visit Codeforces::Gym to find the contest and register.

We are planning to start on October, 5, 2016 13:10 (UTC).

It is possible that the problems will be too easy for some participants, it is possible that we will add some problems.

Good luck!

  • Vote: I like it
  • +114
  • Vote: I do not like it

| Write comment?
»
8 years ago, # |
  Vote: I like it -19 Vote: I do not like it

Aha, a nice try! This is very creative.

»
8 years ago, # |
  Vote: I like it +128 Vote: I do not like it

He forgot to append '\n' character. That is why the teacher is angry.

  • »
    »
    8 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it
    #include <stdio.h>
    int main(void)
    {
        int myCuteCount;
        for(myCuteCount = 1;myCuteCount <= 500;myCuteCount++)
            printf("I will not forget to append '\n'.");
        return 0;
    }
    
»
8 years ago, # |
Rev. 2   Vote: I like it -29 Vote: I do not like it
#include <stdio.h>
int main(void)
{
    int myCuteCount;
    for(myCuteCount = 1;myCuteCount <= 500;myCuteCount++)
        printf("I will not throw junk comments in codeforces.\n");
    return 0;
}
»
8 years ago, # |
  Vote: I like it +1 Vote: I do not like it

How to view solution of other users in Gym contest which I haven't solved ?

»
8 years ago, # |
  Vote: I like it +11 Vote: I do not like it

How to solve A, H and J?

  • »
    »
    8 years ago, # ^ |
    Rev. 5   Vote: I like it +26 Vote: I do not like it

    In problem A, we're asked only the smallest 100 combinations in the worst case, so we can keep track of the smallest k combinations we've seen so far in an array, and whenever the array exceeds k (after sorting) we remove elements from the back.

    • Initially, put all v1, i into the ans array.
    • Then process piece types one by one. To process piece type i, for all current values x from the ans array and all values vi, j we push value x + vi, j to ans. After adding all new values, we must delete the old ones (we can do it with one array by swapping new elements with old ones or have two arrays and swap them at each piece type). When we're done removing old elements, we sort the ans array and remove elements from the back until size is  ≤ k.
    • Finally, print the contains of the ans array.
    • We do m2 operations to process each type and logm2 for sorting the ans array, and there are m piece types, so in total we do m3 + m * logm2 operations. Total complexity: O(m3).

    PS: The technique used in this problem is known as Beam Search, and is widely used in optimization problems.

    C++ Code
  • »
    »
    8 years ago, # ^ |
      Vote: I like it +12 Vote: I do not like it

    H: Let's compute the area of the polygon using pseudoscalar product (not sure if this is the right term in English, in 2D it is equal to x1y2 - x2y1). To do that, we just sum up all the oriented areas of triangles (ai, ai + 1, (0, 0)). Note that if we reverse the order, the area will be exactly the opposite. That is why, we can conclude the answer from the sign of the area computed this way.

  • »
    »
    8 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    H: For any point X in the polygon, the sum of the signed angles PiXPi + 1 is either , or  - 2π, depending on the polygon's orientation. From outside the polygon, the sum is 0.

    So all we need to do is find a point in the polygon. I took the midpoint of a non-vertical edge, perturbed it by a small amount upwards and downwards, and computed the sum for these two points.

  • »
    »
    8 years ago, # ^ |
      Vote: I like it +8 Vote: I do not like it

    J: First sort all points by x-coordinate. Now brute force over all combinations of the minimum and maximum y for the rectangle. For each min-max pair, we can find all rectangles containing n/2+1 points using a two-pointer approach, where the pointers mark the left and right boundaries of the rectangle. When we march the left pointer forwards, we lose some points, so we must march the right pointer forwards as well. Total time is O(n3).

»
8 years ago, # |
  Vote: I like it +22 Vote: I do not like it

Is there any tutorial available? Thank you in advance

»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Can anyone help me with J. Thanks in advance

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

    for each 2 X's --> for each Y --> do binary search

    the idea is : you need 2 points( upper-left , lower-right )( 2 X's , 2 Y's )

    the 2 X's may be the same and the 2 Y's may be the same

    the bruteforce solution is O(n^4) ( bad )

    to reduce the complexity a little bit you can try :

    every 2 X's and 1 Y : binary search the other Y

    this solution is O(n^3 logn) ( good enough to pass )

    • »
      »
      »
      8 years ago, # ^ |
        Vote: I like it +3 Vote: I do not like it

      every 2 X's , 1 Y and binary search the other Y

      There is no need to do binary search. If you have sorted array of points between X1 and X2 (which you probably need for binary search as well), you can just try pairs .

  • »
    »
    8 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    hhhh

»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

in problem G-Ground Defence :

i'm trying to solve it with segment tree ,but how to handle lazy propagation ??

  • »
    »
    8 years ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    You don't need lazy propagation at all. You're dealing with range updates and point queries.

»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Just a key observation for not being stuck for ever in problem F: the length of the least path between two points with the same latitude IS NOT the length of the arc of the maximal circle of the sphere that contains both points.

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

How to solve L and M?

»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

How to solve problem K?

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

How to solve C?

I compute probabilities for each triple (t, n, nd) (where t — time, n — number of unique cards, nd — number of dublicates, nd < d). But I get expected time 10.414 for the second sample instead of 10.185.

c++ code
  • »
    »
    8 years ago, # ^ |
      Vote: I like it +10 Vote: I do not like it

    You don't need to trade duplicates immediately.

»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

how to solve B??

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

    Here

    Edit :I thought its Ep-03 'B'

    • »
      »
      »
      8 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I read that too .... Won't it exceed the time limit with given constraints ...?

      • »
        »
        »
        »
        8 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Your_dad Idea is very Simple.

        Think optimally!

        This Test Case will help you.

        [IN]

        1

        3 4

        0101

        1000

        0001

        [OUT]

        9

        • »
          »
          »
          »
          »
          8 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          i solved it too... i just need to confirm the complexity :--> mine is O(n*m) yrs??

»
8 years ago, # |
  Vote: I like it +3 Vote: I do not like it

How to solve F?)

»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Oh, I was solving J for one hour because I coded a solution with complexity O(T*N^3) for stress testing in the beginning and then tried to come up with a fast solution. In the end, I just sent the O(T*N^3) and it got accepted in about 100 ms :D

Is this the expected complexity, I thought it would be too slow?