제출 #102695

#제출 시각아이디문제언어결과실행 시간메모리
102695luciocfTracks in the Snow (BOI13_tracks)C++14
100 / 100
1395 ms114228 KiB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 4e3+10;

typedef pair<int, int> pii;

int n, m;
int ans;

char tab[maxn][maxn];

bool mark[maxn][maxn];

int linha[] = {-1, 1, 0, 0};
int coluna[] = {0, 0, -1, 1};

void bfs(void)
{
    deque<pair<pii, int>> dq;

    ans = 1, mark[0][0] = 1;
    dq.push_front({{0, 0}, 1});

    while (!dq.empty())
    {
        int x = dq.front().first.first;
        int y = dq.front().first.second;
        int t = dq.front().second;
        dq.pop_front();

        ans = max(ans, t);

        for (int i = 0; i < 4; i++)
        {
            int a = x+linha[i], b = y+coluna[i];

            if (a < 0 || a >= n || b < 0 || b >= m || mark[a][b] || tab[a][b] == '.') continue;

            if (tab[a][b] != tab[x][y]) dq.push_back({{a, b}, t+1});
            else dq.push_front({{a, b}, t});

            mark[a][b] = 1;
        }
    }
}

int main(void)
{
    scanf("%d %d", &n, &m);

    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            scanf(" %c", &tab[i][j]);

    bfs();

    printf("%d\n", ans);
}

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

tracks.cpp: In function 'int main()':
tracks.cpp:51:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~
tracks.cpp:55:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf(" %c", &tab[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...