ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1122. Game

Painful to code
Posted by Mahilewets Nikita [BSUIR] 24 Sep 2017 12:19
My solution is very ugly
Maybe yours is beautiful
How nice is your solution?
Re: Painful to code
Posted by Oleg Baskakov 24 Sep 2017 15:30
How ugly can it be? Just need to use three functions: convert board to 2-byte value, unconvert, modify board by making a move at (x, y). And with those, we just do usual BFS, until 0 or 65535 is reached.
Unless of course you're not doing brute force but some smart solution.
Re: Painful to code
Posted by Mahilewets Nikita [BSUIR] 24 Sep 2017 21:43
That function modifies board
https://ideone.com/w5JRRH
Re: Painful to code
Posted by Oleg Baskakov 24 Sep 2017 23:00
What? Why? You can't be serious.

I'll try to scribble the concept in pascal...

type TBoard = array[0..3, 0..3] of shortint; //the board
     TMod = array[0..2, 0..2] of shortint;   //the modifier
var md: TMod;
...
procedure ModifyBoard(x, y: shortint; var board: TBoard);
//x, y are coordinates of our move's center
//board links to the board array we're modifying
var i, j: shortint;
begin
    for i:=-1 to +1 do
        for j:=-1 to +1 do
            if (x + i >= 0) and (x + i <= 3) and
               (y + j >= 0) and (y + j <= 3) then begin //out of bounds check
                if md[i + 1, j + 1] > 0 then board[x + i, y + j]:=1 - board[x + i, y + j]; //flipping if spot is marked for that
            end;
end;

I guess not more effecient than your bit operations, but definitely easier to read. You can, like, just convert 2-byte state into a full board and convert it back with separate functions if needed.
Re: Painful to code
Posted by Mahilewets Nikita [BSUIR] 25 Sep 2017 00:37
Why?
Because I have solved a very similar task
Flip game
I don't like to solve the same task with the same method twice
Re: Painful to code
Posted by Oleg Baskakov 25 Sep 2017 01:43
I see, you weren't serious. Sorry.