제출 #807482

#제출 시각아이디문제언어결과실행 시간메모리
807482gtm7Tracks in the Snow (BOI13_tracks)C++17
6.67 / 100
2095 ms454236 KiB
#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    char a[4000][4000];
    bool visited[4000][4000]{false};
    const int dx[4] = {1, 0, -1, 0};
    const int dy[4] = {0, 1, 0, -1};
    int h, w;
    cin >> h >> w;
    char ch;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cin >> a[i][j];
        }
    }
    int ans = 1;
    set<vector<int>> q;
    vector<int> s;
    int ii, jj;
    q.insert({1, 0, 0});
    visited[0][0] = true;
    while (!q.empty())
    {
        s = *q.begin();
        q.erase(q.begin());
        for (int i = 0; i < 4; i++)
        {
            ii = s[1] + dx[i];
            jj = s[2] + dy[i];
            if (ii >= 0 && ii < h && jj >= 0 && jj < w && !visited[ii][jj] && a[ii][jj] != 3)
            {
                visited[ii][jj] = true;
                if (a[ii][jj] == a[s[1]][s[2]])
                {
                    q.insert({s[0], ii, jj});
                }
                else
                {
                    ans = max(ans, s[0] + 1);
                    q.insert({s[0] + 1, ii, jj});
                }
            }
        }
    }
    cout << ans << "\n";
}

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

tracks.cpp: In function 'int main()':
tracks.cpp:14:10: warning: unused variable 'ch' [-Wunused-variable]
   14 |     char ch;
      |          ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...