bfs problem: https://codeforces.net/problemset/problem/1105/D
# | 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 | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | nor | 153 |
9 | Dominater069 | 153 |
bfs problem: https://codeforces.net/problemset/problem/1105/D
Name |
---|
And what?
I think the best way of getting some idea about a problem's solution is looking at the editorial. Here's the Round 533 (Div. 2) editorial: https://codeforces.net/blog/entry/64664
It's a simulation problem so your task is only to simulate the game following a given set of rules. They're unequivocal so for a particular initial grid, there's only one correct course of the game. The algorithm that you need is multi-source BFS. Firstly, put on the queue all of the cells which belong to some player. Then, simulate the turn as below: Take one player (which is first in order) and using BFS, expand his cells. Then, take the next player... finish it when there are no empty cells left.
If you put on all cells, which belong to some player, in the queue, I'm not sure that it is a clear O(n^2), because every move you traverse over all visited cells. And if the moves are a lot (a sample can be constructed) the complexity can possibly reach O(n^3). One possible optimization is to put only cells, which were end points on the previous move. It's pretty obvious that the other cells are useless and you can observe that this way we visit every cell at most twice, which leads to a clear O(n^2) solution. The most solutions passed without this, but in my opinion the test cases are pretty weak.
Of course, that's what I meant. We put all cells which belong to some player only in the first move. Then, only these which are 'new'. Like in normal BFS. Thanks for clarification because I didn't say it plainly. Really, did solutions O(n^3) passed? So the test cases were really weak.