#include <bits/stdc++.h>
using namespace std;
int main(){
int ans = 0, amount = 0;
int n, m, score, x, y;
char a;
cin >> n >> m;
char board[n][m];
bool board2[n][m];
for (int i = 0; i < n; i++){
for (int j = 0; j < m; j++){
cin >> board[i][j];
board2[i][j] = 0;
}
}
char moves = board[0][0];
if (moves == 'F') a = 'R';
if (moves == 'R') a = 'F';
if (moves == '.'){
cout << ans;
return 0;
}
ans = 1;
board2[0][0] = 1;
priority_queue <pair<int, pair <int, int>>> q;
q.push({-1,{0, 0}});
while (!q.empty()){
score = q.top().first;
x = q.top().second.first;
y = q.top().second.second;
q.pop();
if (x != 0 && !board2[x-1][y]){
board2[x-1][y] = 1;
if (board[x-1][y] == board[x][y]){
q.push({score, {x-1, y}});
}
else if (board[x-1][y] != '.'){
q.push({score-1, {x-1, y}});
ans = max(ans, 1-score);
}
}
if (y != 0 && !board2[x][y-1]){
board2[x][y-1] = 1;
if (board[x][y-1] == board[x][y]){
q.push({score, {x, y-1}});
}
else if (board[x][y-1] != '.'){
q.push({score-1, {x, y-1}});
ans = max(ans, 1-score);
}
}
if (y != m - 1 && !board2[x][y+1]){
board2[x][y+1] = 1;
if (board[x][y+1] == board[x][y]){
q.push({score, {x, y+1}});
}
else if (board[x][y+1] != '.'){
q.push({score-1, {x, y+1}});
ans = max(ans, 1-score);
}
}
if (x != n-1 && !board2[x+1][y]){
board2[x+1][y] = 1;
if (board[x+1][y] == board[x][y]){
q.push({score, {x+1, y}});
}
else if (board[x+1][y] != '.'){
q.push({score-1, {x+1, y}});
ans = max(ans, 1-score);
}
}
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |