이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <queue>
#include <vector>
#include <set>
using namespace std;
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
char a[4001][4001];
int dist[4001][4001];
int n, m;
int Max;
deque<pair<int, int>> Q;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, 1, 0, -1};
bool inside(int i, int j) {
    if (i >= 1 && j >= 1 && i <= n && j <= m)
        return 1;
    return 0;
}
void bfs01(int istart, int jstart) {
    int i, j, inou, jnou, k;
    pair<int, int> p;
    Q.push_back({istart, jstart});
    dist[istart][jstart] = 1;
    while (!Q.empty()) {
        i = Q.front().first, j = Q.front().second;
        Q.pop_front();
        if (dist[i][j] > Max) {
            Max = dist[i][j];
        }
        for (k = 0; k < 4; k++) {
            inou = i + di[k], jnou = j + dj[k];
            if (inside(inou, jnou) && !dist[inou][jnou] && a[inou][jnou] != '.') 
                if (a[inou][jnou] == a[i][j]) {
                    Q.push_front({inou, jnou});
                    dist[inou][jnou] = dist[i][j];
                }
                else {
                    Q.push_back({inou, jnou});
                    dist[inou][jnou] = dist[i][j] + 1;
                }
        }
    }
}
int main() {
    fast
    int i, j;
    cin >> n >> m;
    for (i = 1; i <= n; i++)
        for (j = 1; j <= m; j++)
            cin >> a[i][j];
    bfs01(1, 1);
    cout << Max;
    return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
tracks.cpp: In function 'void bfs01(int, int)':
tracks.cpp:38:16: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   38 |             if (inside(inou, jnou) && !dist[inou][jnou] && a[inou][jnou] != '.')
      |                ^| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |