We will hold Toyota Programming Contest 2023#4(AtCoder Beginner Contest 311).
- Contest URL: https://atcoder.jp/contests/abc311
- Start Time: http://www.timeanddate.com/worldclock/fixedtime.html?iso=20230722T2100&p1=248
- Duration: 100 minutes
- Number of Tasks: 8
- Writer: Nyaan, physics0523, evima, leaf1415
- Tester: cn449, m_99
- Rated range: ~ 1999
- The point values will be 100-200-350-400-475-525-575-675.
We are looking forward to your participation!
Should have written it in the announcement :)
hopefully, now you've emptied all the grid problems from your db and we can get nice problems from the next contest
gitgud
would appreciate it a lot if someone could give hints for : F , G and Ex
I don't know about G and Ex but for F I noticed two things.
You can think of the process of painting as painting some cells, then painting all the necessary cells so the grid becomes beautiful.
That way when you decide to paint some cell, it shouldn't matter if you paint below it (it won't change the final beautiful grid).
If you consider only the painted cells in the first $$$j$$$ columns, then the only thing that matters for the choices of the other columns is the highest cell in column $$$j$$$ that will be black in the final beautiful grid.
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.
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 thatnew_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:
Previous Smaller Element (Using a Monotonic Stack)
Next Smaller Element (Using a Monotonic Stack)
Maximum Area Histogram (Using 1) and 2))
Largest Rectangular Area in a Binary Matrix (Using 3)
https://atcoder.jp/contests/abc311/submissions/43887409
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.
How to solve F?
E is truly an ancient problem.
E was basically this, just the answer to be calculated changed.
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. )
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$$$.
can someone explain whats wrong in this approach for E
(https://atcoder.jp/contests/abc311/submissions/43888872)
I am sending one leetcode problem link Count Squares.Hope you will understand from there and will able to debug your code.
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).
Can anyone please provide hint or solution for problem D.I couldn't find it in editorials yet.
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.
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.
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
Can someone tell me how to solve F?