제출 #926707

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

void File() {
#define file "ZOO"
    freopen(file".inp", "r", stdin);
    freopen(file".out", "w", stdout);
}

int n, m;
bool visited[1001][1001];
char arr[1001][1001];
vector<pair<int, int>> dif, nDif;

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};

bool canGo(int x, int y)
{
    return (x <= n && y <= m && min(x, y) > 0 && arr[x][y] != '.' && !visited[x][y]);
}

void dfs(int x, int y)
{
    visited[x][y] = true;
    for (int i = 0; i < 4; i++)
    {
        int vx = x + dx[i];
        int vy = y + dy[i];
        if (canGo(vx, vy))
        {
            if (arr[vx][vy] == arr[x][y]) dfs(vx, vy);
            else nDif.emplace_back(vx, vy);
        }
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    //File();
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            cin >> arr[i][j];
        }
    }
    nDif.emplace_back(1, 1);
    int ans = 0;
    while (!nDif.empty())
    {
        ans++;
        dif = nDif;
        nDif.clear();
        for (pair<int, int> cur : dif) dfs(cur.first, cur.second);
        dif.clear();
    }
    cout << ans;
    return 0;
}

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

tracks.cpp: In function 'void File()':
tracks.cpp:6:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 |     freopen(file".inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
tracks.cpp:7:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |     freopen(file".out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...