11230 - Annoying painting tool
Moderator: Board moderators
11230 - Annoying painting tool
How solve it?
-
- Guru
- Posts: 724
- Joined: Wed Dec 19, 2001 2:00 am
- Location: Germany
-
- Guru
- Posts: 724
- Joined: Wed Dec 19, 2001 2:00 am
- Location: Germany
-
- Guru
- Posts: 724
- Joined: Wed Dec 19, 2001 2:00 am
- Location: Germany
-
- Experienced poster
- Posts: 122
- Joined: Sun Nov 13, 2005 10:25 am
- Location: Taiwan
Well, in my method, I didn't do the "same change" more than one timeWhen I looked at the problem again I realized the naive solution would pass, so I coded it. I can see how to speed it up using bitmasks, but I can't figure out how to do it in O(n*m). Any hints?
I tried to change every block to the right color in a special order
column first, and row next (row first and column next is also possible)
Each change make sure of one block on the right color and it wouldn't be changed again in the changes after.
I think it is the same method as Adrian Kuegel's in the top of this page
-
- Guru
- Posts: 724
- Joined: Wed Dec 19, 2001 2:00 am
- Location: Germany
Well, you just describe the greedy everyone uses. But if you implement this naively, it will be O(r*(n-r)*m*(m-c)), because each time when you apply the operation it takes r * c steps.
The idea how to get O(n*m) is to store how many operations have been applied with the top left corner in one of the first i rows and j columns. With this information it is possible to answer in constant time how many operations
covering a pixel have been applied.
The idea how to get O(n*m) is to store how many operations have been applied with the top left corner in one of the first i rows and j columns. With this information it is possible to answer in constant time how many operations
covering a pixel have been applied.