이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using int32 = int32_t;
using int64 = int64_t;
const int32 INF = 1'000'000'000;
const vector<int32> DX = {-1, +1, 0, 0};
const vector<int32> DY = {0, 0, -1, +1};
int32 N, M;
inline bool inGrid(int32 x, int32 y)
{
    return (0 <= x && x < N && 0 <= y && y < M);
}
int32 main()
{
    cin >> N >> M;
    vector<string> grid(N);
    for (auto &row : grid)
    {
        cin >> row;
    }
    deque<pair<int32, int32>> cells;
    vector<vector<int32>> depth(N, vector<int32>(M, INF));
    depth[0][0] = 1;
    cells.emplace_back(0, 0);
    int32 result = 0;
    while (!cells.empty())
    {
        auto [x, y] = cells.front();
        cells.pop_front();
        result = max(result, depth[x][y]);
        for (int32 d = 0; d < 4; ++d)
        {
            int32 nx = x + DX[d];
            int32 ny = y + DY[d];
            if (inGrid(nx, ny) && grid[nx][ny] != '.' && depth[nx][ny] == INF)
            {
                if (grid[nx][ny] == grid[x][y])
                {
                    depth[nx][ny] = depth[x][y];
                    cells.emplace_front(nx, ny);
                }
                else
                {
                    depth[nx][ny] = depth[x][y] + 1;
                    cells.emplace_back(nx, ny);
                }
            }
        }
    }
    cout << result << "\n";
    return 0;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |