Language: C++

###D - Grid Repainting
Time limit : 2sec / Memory limit : 256MB
Score: 400 points
###Problem statement
We have an H×W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i,j).Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1,1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H,W) passing only white squares.Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1,1) and (H,W). Also, changes of color must all be carried out before the beginning of the game.When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print −1 if the game cannot be completed, that is, Kenus can never reach square (H,W) regardless of how Snuke changes the color of the squares.
The color of the squares are given to you as characters si,j. If square (i,j) is initially painted by white, si,j is '.'; if square (i,j) is initially painted by black, si,j is '#'.
###Constraints•H is an integer between 2 and 50 (inclusive).•W is an integer between 2 and 50 (inclusive).•si,j is '.' or '#' (1≤i≤H,1≤j≤W).•s1,1 and sH,W are '.'.
###Input
Input is given from Standard Input in the following format:H Ws1,1s1,2s1,3…s1,Ws2,1s2,2s2,3…s2,W: :sH,1sH,2sH,3…sH,W
###Output
Print the maximum possible score that Snuke can achieve, or print −1 if the game cannot be completed.
Sample Input 1
3 3..##.....
###Sample Output 1
2
The score 2 can be achieved by changing the color of squares as follows:
Explanation of Sample 1
###Sample Input 2
10 37 ..................................... ...#...####...####..###...###...###.. ..#.#..#...#.##....#...#.#...#.#...#. ..#.#..#...#.#.....#...#.#...#.#...#. .#...#.#..##.#.....#...#.#.###.#.###. .#####.####..#.....#...#..##....##... .#...#.#...#.#.....#...#.#...#.#...#. .#...#.#...#.##....#...#.#...#.#...#. .#...#.####...####..###...###...###.. .....................................
###Sample Output 2
209
题意： 给你个包含.#的地图，.代表白色方块，#代表黑色方块，在保证可以从左上角走到右下角情况下，求最多可以把多少白块变成黑块
分析：我们直接先枚举下黑块的数量，然后再减去最短路，即可，这里的最短路可以用DFS，或者是BFS都行，我用的BFS。
###参考代码
#include<bits/stdc++.h>

using namespace std;

#define fi first
#define se second

const ll maxn = 1e3 + 10;
const int Move[4][2] = {-1,0,1,0,0,1,0,-1};
char mp[maxn][maxn];
int step[maxn][maxn];
bool vis[maxn][maxn];
int n,m;

bool check(int x,int y) {
if(x < 0 || y < 0|| x >= n || y >= m || vis[x][y] || mp[x][y] == '#') return false;
return true;
}

int BFS() {
queue<pair<int ,int> > q;
q.push(make_pair(0,0));
step[0][0] = 1;
vis[0][0] = true;
while (!q.empty()) {
pair<int ,int> t = q.front();
q.pop();
for(int i = 0;i < 4;i++) {
int tox = t.fi + Move[i][0];
int toy = t.se + Move[i][1];
if(tox == n - 1 && toy == m - 1) return step[t.fi][t.se] + 1;
if(check(tox,toy)) {
vis[tox][toy] = true;
step[tox][toy] = step[t.fi][t.se] + 1;
q.push(make_pair(tox,toy));
}
}
}
return -1;
}


int main(){
init();
cin>>n>>m;
int cnt = 0;
for(int i = 0;i < n;i++)
for(int j = 0;j < m;j++) {
cin>>mp[i][j];
if(mp[i][j] == '#') cnt++;
}
int res = BFS();
if(res == -1) {
cout<<"-1"<<endl;
} else {
cout<<nm - res - cnt<<endl;
}
return 0;
}

Compiler output:
a.cc:1:1: error: stray '##' in program
    1 | ###D - Grid Repainting
      | ^~
a.cc:1:3: error: stray '#' in program
    1 | ###D - Grid Repainting
      |   ^
a.cc:4:1: error: stray '##' in program
    4 | ###Problem statement
      | ^~
a.cc:4:3: error: stray '#' in program
    4 | ###Problem statement
      |   ^
a.cc:5:12: error: extended character × is not valid in an identifier
    5 | We have an H×W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i,j).Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1,1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H,W) passing only white squares.Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1,1) and (H,W). Also, changes of color must all be carried out before the beginning of the game.When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print −1 if the game cannot be completed, that is, Kenus can never reach square (H,W) regardless of how Snuke changes the color of the squares.
      |            ^
a.cc:5:719: warning: missing terminating ' character
    5 | We have an H×W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i,j).Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1,1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H,W) passing only white squares.Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1,1) and (H,W). Also, changes of color must all be carried out before the beginning of the game.When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print −1 if the game cannot be completed, that is, Kenus can never reach square (H,W) regardless of how Snuke changes the color of the squares.
      |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               ^
a.cc:5:719: error: missing terminating ' character
    5 | We have an H×W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i,j).Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1,1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H,W) passing only white squares.Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1,1) and (H,W). Also, changes of color must all be carried out before the beginning of the game.When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print −1 if the game cannot be completed, that is, Kenus can never reach square (H,W) regardless of how Snuke changes the color of the squares.
      |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:7:1: error: stray '##' in program
    7 | ###Constraints•H is an integer between 2 and 50 (inclusive).•W is an integer between 2 and 50 (inclusive).•si,j is '.' or '#' (1≤i≤H,1≤j≤W).•s1,1 and sH,W are '.'.
      | ^~
a.cc:7:3: error: stray '#' in program
    7 | ###Constraints•H is an integer between 2 and 50 (inclusive).•W is an integer between 2 and 50 (inclusive).•si,j is '.' or '#' (1≤i≤H,1≤j≤W).•s1,1 and sH,W are '.'.
      |   ^
a.cc:7:4: error: extended character • is not valid in an identifier
    7 | ###Constraints•H is an integer between 2 and 50 (inclusive).•W is an integer between 2 and 50 (inclusive).•si,j is '.' or '#' (1≤i≤H,1≤j≤W).•s1,1 and sH,W are '.'.
      |    ^
a.cc:7:61: error: extended character • is not valid in an identifier
    7 | ###Constraints•H is an integer between 2 and 50 (inclusive).•W is an integer between 2 and 50 (inclusive).•si,j is '.' or '#' (1≤i≤H,1≤j≤W).•s1,1 and sH,W are '.'.
      |                                                             ^
a.cc:7:107: error: extended character • is not valid in an identifier
    7 | ###Constraints•H is an integer between 2 and 50 (inclusive).•W is an integer between 2 and 50 (inclusive).•si,j is '.' or '#' (1≤i≤H,1≤j≤W).•s1,1 and sH,W are '.'.
      |                                                                                                           ^
a.cc:7:128: error: extended character ≤ is not valid in an identifier
    7 | ###Constraints•H is an integer between 2 and 50 (inclusive).•W is an integer between 2 and 50 (inclusive).•si,j is '.' or '#' (1≤i≤H,1≤j≤W).•s1,1 and sH,W are '.'.
      |                                                                                                                                ^
a.cc:7:128: error: extended character ≤ is not valid in an identifier
a.cc:7:134: error: extended character ≤ is not valid in an identifier
    7 | ###Constraints•H is an integer between 2 and 50 (inclusive).•W is an integer between 2 and 50 (inclusive).•si,j is '.' or '#' (1≤i≤H,1≤j≤W).•s1,1 and sH,W are '.'.
      |                                                                                                                                      ^
a.cc:7:134: error: extended character ≤ is not valid in an identifier
a.cc:7:141: error: extended character • is not valid in an identifier
    7 | ###Constraints•H is an integer between 2 and 50 (inclusive).•W is an integer between 2 and 50 (inclusive).•si,j is '.' or '#' (1≤i≤H,1≤j≤W).•s1,1 and sH,W are '.'.
      |                                                                                                                                             ^
a.cc:8:1: error: stray '##' in program
    8 | ###Input
      | ^~
a.cc:8:3: error: stray '#' in program
    8 | ###Input
      |   ^
a.cc:9:74: error: extended character … is not valid in an identifier
    9 | Input is given from Standard Input in the following format:H Ws1,1s1,2s1,3…s1,Ws2,1s2,2s2,3…s2,W: :sH,1sH,2sH,3…sH,W
      |                                                                          ^
a.cc:9:91: error: extended character … is not valid in an identifier
    9 | Input is given from Standard Input in the following format:H Ws1,1s1,2s1,3…s1,Ws2,1s2,2s2,3…s2,W: :sH,1sH,2sH,3…sH,W
      |                                                                                           ^
a.cc:9:111: error: extended character … is not valid in an identifier
    9 | Input is given from Standard Input in the following format:H Ws1,1s1,2s1,3…s1,Ws2,1s2,2s2,3…s2,W: :sH,1sH,2sH,3…sH,W
      |                                                                                                               ^
a.cc:10:1: error: stray '##' in program
   10 | ###Output
      | ^~
a.cc:10:3: error: stray '#' in program
   10 | ###Output
      |   ^
a.cc:11:67: error: extended character − is not valid in an identifier
   11 | Print the maximum possible score that Snuke can achieve, or print −1 if the game cannot be completed.
      |                                                                   ^
a.cc:13:3: error: too many decimal points in number
   13 | 3 3..##.....
      |   ^~~
a.cc:13:6: error: stray '##' in program
   13 | 3 3..##.....
      |      ^~
a.cc:14:1: error: stray '##' in program
   14 | ###Sample Output 1
      | ^~
a.cc:14:3: error: stray '#' in program
   14 | ###Sample Output 1
      |   ^
a.cc:18:1: error: stray '##' in program
   18 | ###Sample Input 2
      | ^~
a.cc:18:3: error: stray '#' in program
   18 | ###Sample Input 2
      |   ^
a.cc:19:48: error: stray '#' in program
   19 | 10 37 ..................................... ...#...####...####..###...###...###.. ..#.#