시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
0.5 초 | 512 MB | 15 | 3 | 2 | 25.000% |
Tamta and Anna are sisters who like playing a game of Dots and Boxes.
The game starts with an empty N + 1 by M + 1 grid of dots (and correspondingly, N by M grid of boxes). Players take turns adding a single horizontal or vertical edge between two unjoined adjacent dots (two dots are adjacent if the distance between them is 1). If a player completes the fourth side of a 1 × 1 box on her turn she claims it, earns one point and takes another turn, otherwise the turn switches to another player.
The game ends when no more edges can be placed. Possible next three turns in a grid with N = 2, M = 3 (dotted lines are player moves):
Anna and Tamta have been playing for a while and you’ve noticed that in a current state each box has exactly zero or two unjoined sides and it's Anna's turn to move. (you can see an example in the image on the right. Note that image above does not fit this description).
The score of this game will be calculated as SA - ST where SA is the number of points Anna earns from this point forward and ST is the number of points that Tamta earns. Obviously, Anna is trying to maximize the score while Tamta is trying to minimize it. You need to calculate the final score knowing both players act optimally.
The first line contains two integers N and M which are number of rows and number of columns in a grid of boxes.
Each of the next N + 1 lines contain M digits, each being one or zero (without separating spaces), j-th number in the i-th row is one if and only if there is an horizontal edge between the dots with coordinates (i, j) and (i, j+1).
Following N lines contain M + 1 digits in the same format, j-th number in i-th row is 1 if and only if there is a b edge between the dots with coordinates (i, j) and (i+1, j).
The only line should contain a single integer, the final score.
Let’s define a component as a maximum set of unclaimed boxes on a grid such that you can move from any box to any other box by traversing the edges that aren’t drawn yet. In the image you can see 5 different components.
번호 | 배점 | 제한 |
---|---|---|
1 | 20 | There is only a single component left in the game |
2 | 20 | N · M ≤ 12 |
3 | 20 | There are only two components left in the game |
4 | 20 | N ≤ 7, M ≤ 7 |
5 | 20 | No additional constraints |
3 3 000 111 011 110 1010 1000 1001
-5
5 5 00100 10100 11010 00100 01000 11100 011111 001011 101011 110111 100111
6
The first example and one of the possible optimal move orders are depicted below (numbers on edges indicate turn order, red colors used by Anna and blue used by Tamta).
Second example is the one shown in the above pictures.