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

Автор atcoder_official, история, 17 месяцев назад, По-английски

We will hold Toyota Programming Contest 2023#4(AtCoder Beginner Contest 311).

We are looking forward to your participation!

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

»
17 месяцев назад, # |
Rev. 2   Проголосовать: нравится +35 Проголосовать: не нравится

Let (i,j) denote the square at the i-th row from the top and j-th column from the left of a grid.

Should have written it in the announcement :)

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

hopefully, now you've emptied all the grid problems from your db and we can get nice problems from the next contest

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

would appreciate it a lot if someone could give hints for : F , G and Ex

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

    I don't know about G and Ex but for F I noticed two things.

    Hint 1 (which helped me arrive at hint 2)
    Hint 2 (big hint)
  • »
    »
    17 месяцев назад, # ^ |
      Проголосовать: нравится +35 Проголосовать: не нравится

    For G, you can iterate over all pairs $$$(l, r)$$$ to consider all rectangles whose left column is $$$l$$$ and right column is $$$r$$$. Then, you can "compress" every row $$$i$$$ in this subgrid with two numbers: $$$sum_i$$$ (the sum of numbers in the i-th row) and $$$min_i$$$ (the minimum number in the i-th row). Both numbers can be preprocessed. Now your problem is: "given arrays $$$sum$$$ and $$$min$$$, what is the maximum value of (sum[l] + ... + sum[r]) * (min(min[l], ..., min[r])) over all possible pairs of $$$(l, r)$$$?". This can be solved with monotonic stack.

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

    For Problem G,

    We need to maximize the (sum of a rectangular region) * (minimum of that same region). Let's fix the minimum value(instead of going over all the cells) [Notice that 1 <= Ai <= 300].

    For each minimum value mn_value we can generate a binary matrix, such that new_mat[i][j] = A[i][j] >= mn_value.

    Now this problem reduces to finding the maximum area rectangle in new_mat which can be solved using the maximum area histogram as a subroutine with a slight modification. Using binary matrix we cannot obtain the actual sum of the rectangular region. So, for that prepare a prefix sum matrix and pass it to all the functions.

    In the Largest rectangular histogram logic, when we are finding the maximum area, we can also find out the coordinates of the rectangle that produces the maximum area [Top left: (row - height + 1, pse + 1), Bottom right: (row, nse - 1)]. Since we know the coordinates of the rectangle, we can get the actual sum of that region from the Prefix Sum Matrix we created in O(1) time.

    So, the time complexity of this solution is O(300 * n * m)

    Subroutines used:

    1. Previous Smaller Element (Using a Monotonic Stack)

    2. Next Smaller Element (Using a Monotonic Stack)

    3. Maximum Area Histogram (Using 1) and 2))

    4. Largest Rectangular Area in a Binary Matrix (Using 3)

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

Apparently the intended solution in problem E was dp. However it can be solved in $$$O\left(HW\log\left(\max\{H,W\}\right)\right)$$$ iterating through all $$$(i, j)$$$ and finding the biggest $$$n$$$ such that $$$(i,j,n)$$$ is a holeless square.

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

How to solve F?

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

E is truly an ancient problem.

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

G is a very good problem. But in my opinon, it shouldn't be solved in $$$O(n^4)$$$. However, in this submission:https://atcoder.jp/contests/abc311/submissions/43878994, it passed in $$$O(n^4)$$$.

Is $$$O(n^4)$$$ the correct answer or the data is too weak ?

(I know this code's real complexity is $$$O(\frac{n^4}4)$$$, that is $$$2,025,000,000$$$. In the time limit of 3 seconds, it maybe pass. But I don't think it is fair to others. )

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

    The editorial seems to doubt that an $$$O(n^3 \log_2(n))$$$ solution could work, so $$$O(n^4)$$$ was probably unintended.

    In addition, a solution akin to a finding the maximum-size rectangle in a histogram (bunch of stacks) can solve the problem without the constraint on $$$A$$$.

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

can someone explain whats wrong in this approach for E

Code

(https://atcoder.jp/contests/abc311/submissions/43888872)

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

I misread problem E to be rectangle, not just square, is there an efficient way to solve this harder version ? (Count the number of sub-rectangles that do not contain any of the holed cells).

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

Can anyone please provide hint or solution for problem D.I couldn't find it in editorials yet.

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

    Do a dfs from (2,2) and maintain a visited 2D array and move to that neighbour whichever has atleast one cell left unvisited.You can brute force to check the row or column have any unvisited cell or not.

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

      Actually there are rules of where we have to move from current cell to other.We can not move in any direction even if there is possibilty.

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

        Yes you have to check the next character in the direction you are currently moving in is it '.' or not.

        For reference see my solution submission

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

Can someone tell me how to solve F?