atcoder_official's blog

By atcoder_official, history, 17 months ago, In English

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

We are looking forward to your participation!

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

| Write comment?
»
17 months ago, # |
Rev. 2   Vote: I like it +35 Vote: I do not like it

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 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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

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

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

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

    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 months ago, # ^ |
      Vote: I like it +35 Vote: I do not like it

    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 months ago, # ^ |
      Vote: I like it +4 Vote: I do not like it

    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 months ago, # |
  Vote: I like it +17 Vote: I do not like it

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 months ago, # |
  Vote: I like it 0 Vote: I do not like it

How to solve F?

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

E is truly an ancient problem.

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

    E was basically this, just the answer to be calculated changed.

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

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 months ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    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 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

can someone explain whats wrong in this approach for E

Code

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

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

    I am sending one leetcode problem link Count Squares.Hope you will understand from there and will able to debug your code.

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

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 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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

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

    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 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      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 months ago, # ^ |
        Rev. 2   Vote: I like it 0 Vote: I do not like it

        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 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Can someone tell me how to solve F?