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

Автор keko37, история, 3 года назад, По-английски

Hi everyone!

The fifth round of COCI will be held tomorrow, March 5th at 14:00 UTC. You can access the judging system here. If you are not familiar with COCI contest format, we encourage you to read the announcement.

The round was prepared by ominikfistric, Bartol, pavkal5, and me.

Feel free to discuss the problems in the comment section after the contest ends.

Support for rust will be added either for the next round or for the next season.

Hope to see you tomorrow!

  • Проголосовать: нравится
  • +79
  • Проголосовать: не нравится

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

wow

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

I left the contest when I read the first two problems, Sorry, But this is an Olympiad contest or heavy implementation contest? I didn't like the first two problems this time ...

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

    I agree that A was super toxic but imple for B is quite simple and short?

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

      What is your implementation for B? I rotated the table by 45 degrees and then it can be easily solved, but it wasn't short at all.

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

Is there any simple solution for task Radio? My approach is really ugly and I don't think it's the intended one...

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

    GCD(x, y) != 1 iff exists some prime number that divides both x and y.

    Let's say A[1], A[3], A[4], A[10] are divisible by p, then segments [1, 3], [3, 4] and [4, 10] are "bad", i.e. answer is "DA" if the given segment contains some "bad" segment.

    It is clear that the number of bad segments doesn't exceed O(q*k), where k is the maximal number of prime divisors of some number (k <= 7).

    Let's update each l with the minimum r such that [l, r] is bad. The answer is "DA" if getmin(l, r) <= r.

    Complexity O(n + qklog(n)), where k<=7

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

      Great. I'm so stupid that I used 2D data structures for the last part of the solution. Thank you so much for sharing your solution.

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

      it would be GCD(x, y) != 1 iff there exists some prime number that divides both x and y. also, k <= 8

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

        Yes, you are right, that should be GCD(x, y) != 1.

        But k <= 7 as 2*3*5*7*11*13*17 = 510510 <= 1e6 and 2*3*5*7*11*13*17*19 > 1e6.

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

      Can you show me your code

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

How much does it take to post the tasks in the archive? I think I fixed my bug for Radio and I'm very eager to submit it.

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

How to solve Usmjeravanje(the last problem)?

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

    Here is my solution:

    The problem is essentially just directing the edges in a way to have the minimum possible number of total SCCs.

    Let's say that we directed all the edges from left to right initially. Some edges won't have an impact on the compressed SCC graph. An example of this is if you have the edges "4 1" and "2 3". If you include the edge "4 1", you can notice that adding the edge "2 3" doesn't do anything since node 2 on the left side is already connected to node 3 on the right side. Let's call edges like "2 3" in this example with the term "useless" and all other edges "useful". There are many ways to find the useful edges but I used a segment tree RMQ to do it. After finding all the useful edges, I direct the useful edges from left to right and I direct the useless edges from right to left. After, you can just build the graph and run any SCC algorithm to count the number of SCCs.

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

      The approach focusing on directing the edges from left to right is cool! thanks!

      I was stuck on directing both directions simultaneously and failed to get any points :(

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

      It's also possible to direct the edges without RMQ by using a simple greedy approach: Sort the edges decreasing by x and in case of equal x increasing by y. (call sort on (-x, y)). Now go through the edges in sorted order and maintain the minimum y seen so far (initially -inf). If y < minY, direct the edge right (from left to right), else direct it left.

      The reason why this works can be explained by "useful" and "useless" edges as well: If y >= minY, we could move to the left and increase our x until we reach the edge leading to minY. So directing the edge right would be useless. Otherwise we can reach a lower y and the edge is useful.

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

Can someone help me optimize my solution for problem B?

Let's define a function f(x,y,z) = number of '#' inside the diamond with its top cell being (x,y) and its size being z. We can calculate this function using prefix on diagonals and some observations using triangles.

Then, I binary searched the length of the smallest correct diamond for each cell(x,y). There is at most one correct diamond for each cell so if it exists then I add 1 to the total answer.

Complexity: O(n*m*log(n)), I got TLE on the second sub-problem.

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

Here is a brief description of the solution to task Fliper.

Spoiler