Problem Link . I tried to solve this problem but couldn't solve it. Try to read editorial using google translate help me nothing.
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 166 |
2 | maomao90 | 163 |
2 | Um_nik | 163 |
4 | atcoder_official | 161 |
5 | adamant | 160 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | nor | 153 |
9 | Dominater069 | 153 |
Problem Link . I tried to solve this problem but couldn't solve it. Try to read editorial using google translate help me nothing.
Name |
---|
The solution here hinges on the fact that we don't care about most of the 3x3 subrectangles.
Let's pick any uncolored cell. You can see that any 3x3 subrectangle that would contain that cell would be fully contained within the 5x5 subrectangle in which that cell is the middle. This means that if no cell in the 5x5 subrectangle where the target cell is the middle is colored, then we don't care about that point.
At most $$$9$$$ subrectangles will go through a single point, so there are at most $$$9N$$$ subrectangles we have to worry about. For each point, generate the subrectangles that contain that point (you can iterate through the position in the subrectangle that our target point is in, also be careful about edges). Also, remove duplicates in some way. This process is probably $$$O(nlogn)$$$ because of sorting or something.
Now, for each subrectangle, we will count how many colored cells are in it. We can do this by keeping each point in some ordered list (perhaps a C++
set
) and checking each of the 9 points in each rectangle. This is our answer.The total number of rectangles is $$$(H - 2) * (W - 2)$$$, and if we haven't looked at a rectangle, it has 0 points inside it, so you can just subtract the number of rectangles we've looked at and add that to $$$count(0)$$$.
I got bored and wanted to prove that the constant wouldn't be too bad, so here's a submission with time = 396 ms.
Thanx for the explanation, I implemented the solution but my exe time is 1144ms. Please explain why ? My solution
I would imagine constantly inserting into the set
used
instead of using avector
and removing duplicates would perform significantly slower becauseset
is slow.Also, the use of the
check
function ends up looking at more points than the faster solution, because if a square would be out of bounds, the faster solution wouldn't even look at the square, but you would query the set for some of the points before deciding that it's an invalid square.