1 marine VS 2 zerglings

1 marine VS 2 zerglings

Time limit:1s

Space restriction:1024KiB


Background

In a weird operational map of Starcraft, you are asked to defeat two Zergling with a marine at a narrow height. Since you think it's impossible, you're going to program to verify that.
, ^_^

Description

To facilitate processing, you abstracted such a model:
As a narrow highland of battlefield, it can be considered as a 5 * 5 square array. Each square may be "passable" or "inaccessible". Marine and Zergling always occupy one of the accessible squares. Two zerglings can be in the same square, but marine cannot be in the same square with any undead Zergling at any time. Both marine and Zergling have life values (HP), marine's initial life value is m, and all zergling's initial life value is Z.
Game can be abstracted into turn system. In each round, Marine acts first. Marine can choose to move a grid vertically or horizontally or shoot at a Zergling in situ (because the altitude is very narrow, marine can hit Zergling anywhere on the altitude). Each shot of Marine reduces the target Zergling's life by one point, and when a Zergling's life is reduced to zero or less, it dies.
After Marine's operation, all the undead zerglings will act at the same time. If a Zergling and marine are next to each other, he will attack marine, otherwise he will move along the shortest path from his current position to marine. If there are multiple shortest paths, Zergling will try to move in the order of left, top, right and bottom (for example, if left and top are the shortest paths, Zergling will go left). If two zerglings attack marine in the same grid, marine's life value will only be reduced by 1 point, otherwise each Zergling attack will reduce marine's life value by 1 point.
At the end of a round, if Zergling dies, the game wins, if marine's life is reduced to 0 or less, or if the game has played 34 rounds but has not won, the game loses.
You need to determine whether the game is likely to win, and if possible, output the minimum number of rounds needed to win.

Format

Input

The input file consists of six lines.
The first five lines of the input file have five characters per line, representing the situation of each square in the battlefield.
Characters can only appear as "M", "Z", "z", "1", "0".
The character "1" denotes the corresponding square, while the other characters denote that the corresponding square can be passed. The capital letter "M" denotes the initial position of marine, and the capital letter "Z" and the lowest letter "z" denote the initial position of two zerglings.
Line 6 of the input file has two positive integers m, Z (1 < m < 16, 1 < Z < 99), representing marine's initial life value and zergling's initial life value, respectively.
Note: Closed area surrounded by "1" may appear on battlefield map.

Output

If the game can win, output a line of "WIN" and an integer on the second line, indicating the minimum number of rounds needed to win.
If the game can't win, only one line of "LOSE" is output.

Sample

Input

zZ000
11110
00M10
01110
00000
15 15

Output

WIN
30

Limitation

1s, 1024KiB for each test case.
Sample explanation: Marine can win by attacking two zerglings in situ
Note: All input and output files are returned at the end of the text.

Source

@liang

信息

ID
1001
难度
9
分类
搜索与剪枝动态规划 点击显示
标签
递交数
1
已通过
1
通过率
100%
上传者