제출 #407108

#제출 시각아이디문제언어결과실행 시간메모리
407108iulia13Tracks in the Snow (BOI13_tracks)C++14
100 / 100
954 ms131044 KiB
#include <iostream>
#include <map>
#include <vector>
#include <deque>
using namespace std;
const int N = 4005;
char a[N][N];
int lvl[N][N];
int ans = 0;
int dL[4] = {0, 1, 0, -1};
int dC[4] = {1, 0, -1, 0};
struct NOD{
    int x, y;
};
deque <NOD> dq;
int main()
{
    int n, m, i, j;
    cin >> n >> m;
    for (i = 1; i <= n; i++)
        cin >> a[i] + 1;
    dq.push_back({1, 1});
    lvl[1][1] = 1;
    while (!dq.empty())
    {
        int x = dq.front().x;
        int y = dq.front().y;
        ans = max(ans, lvl[x][y]);
        dq.pop_front();
        for (i = 0; i < 4; i++)
        {
            int xx = x + dL[i];
            int yy = y + dC[i];
            if (a[xx][yy] != '.' && xx >= 1 && yy >= 1 && xx <= n && yy <= m && !lvl[xx][yy])
            {
                if (a[xx][yy] == a[x][y])
                {
                    lvl[xx][yy] = lvl[x][y];
                    dq.push_front({xx, yy});
                }
                else
                {
                    lvl[xx][yy] = lvl[x][y] + 1;
                    dq.push_back({xx, yy});
                }
            }
        }
    }
    cout << ans;
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

tracks.cpp: In function 'int main()':
tracks.cpp:21:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   21 |         cin >> a[i] + 1;
      |                ~~~~~^~~
tracks.cpp:18:18: warning: unused variable 'j' [-Wunused-variable]
   18 |     int n, m, i, j;
      |                  ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...