P24963 [AtCoder] [ARC038B] Grid and Piece
普及+
题目描述

Problem Description

There is a grid with $ H $ rows and $ W $ columns, and a chess piece. The cell at the $i\ (1 ≦ i ≦ H)$ row and $j\ (1 ≦ j ≦ W)$ column is referred to as cell $ (i,j) $. The top-left cell is cell $ (1,1) $ and the bottom-right cell is cell $ (H,W) $. Some cells, except for cell $ (1,1) $, have obstacles. A brother and sister who love games are going to play the following game using this grid and piece:

  • Initially, the piece is placed on cell $ (1,1) $.
  • On their turn, a player must move the piece to one of the cells directly below, diagonally right below, or directly to the right of the current cell, provided that the target cell does not have an obstacle. That is, if the piece is on cell $ (i,j) $, it must be moved to cell $ (i+1,j) $, cell $ (i+1,j+1) $, or cell $ (i,j+1) $, provided there is no obstacle. Note that the piece cannot be moved outside the grid; i.e., when $ i = H $, it cannot move down or diagonally right below, and when $ j = W $, it cannot move diagonally right below or right.
  • The game alternates turns, and the player who cannot move the piece on their turn loses (the other player wins).

When both players aim to win and adopt optimal strategies, which player, the first or the second, will win?

Input Format

The input is given from the standard input in the following format:

$ H $ $ W $ $ S_{1,1} $$ S_{1,2} $..$ S_{1,W} $ $ S_{2,1} $$ S_{2,2} $..$ S_{2,W} $ : $ S_{H,1} $$ S_{H,2} $..$ S_{H,W} $

  • The first line contains two integers $H\ (1 ≦ H ≦ 100)$ and $W\ (1 ≦ W ≦ 100)$ separated by a space, indicating the number of rows and columns of the grid, respectively.
  • The next $ H $ lines provide information about the cells. The $i\ (1 ≦ i ≦ H)$ line contains $ W $ characters. The $j\ (1 ≦ j ≦ W)$ character $ S_{i,j} $ is either # or ., where # indicates an obstacle on cell $ (i,j) $ and . indicates no obstacle. It is guaranteed that $ S_{1,1} $ is ..

Output Format

Output First if the first player wins, or Second if the second player wins, on a single line. End the output with a newline.

Sample Input and Output

Sample Input #1

2 3
.#.
...

Sample Output #1

First

Sample Input #2

4 4
....
...#
....
.#..

Sample Output #2

Second

Sample Input #3

11 44
............................................
............................................
............................................
.....#.....#####....####.....####....####...
....#.#....#....#..#....#...#....#..#....#..
....#.#....#....#..#.............#..#....#..
...#####...#####...#..........###....####...
...#...#...#....#..#.............#..#....#..
..#.....#..#....#..#....#...#....#..#....#..
..#.....#..#....#...####.....####....####...
............................................

Sample Output #3

Second

Notes/Hints

Partial Points

This problem has partial scoring:

  • If you solve the dataset where $ H ≦ 4 $ and $ W ≦ 4 $ correctly, you will be awarded 30 points.
  • If you solve all test cases correctly, you will be awarded an additional 70 points.

Sample Explanation 1

The game proceeds as follows, where o indicates the position of the piece:

o#.
...
  • Turn 1: The piece is at cell $ (1,1) $. The first player moves it down.
.#.
o..
  • Turn 2: The piece is at cell $ (2,1) $. The second player moves it right.
.#.
.o.
  • Turn 3: The piece is at cell $ (2,2) $. The first player moves it right.
.#.
..o
  • Turn 4: The piece is at cell $ (2,3) $. The second player cannot move it, so they lose.

Since the first player can always win by making the appropriate moves, output First.

Sample Explanation 2

Regardless of how the first player moves the piece, the second player can always win by making the appropriate moves, so output Second.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
2 3 .#. ...
样例输出
First