Submission #875560

#TimeUsernameProblemLanguageResultExecution timeMemory
87556012345678Tracks in the Snow (BOI13_tracks)C++17
0 / 100
2138 ms826908 KiB
#include <bits/stdc++.h>

using namespace std;

const int nx=4e3+5;
int h, w, cnt, dx[4]={1, 0, 0, -1}, dy[4]={0, 1, -1, 0};
char mp[nx][nx], c;
queue<pair<int, int>> q, nq;

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>h>>w;
    for (int i=1; i<=h; i++) for (int j=1; j<=w; j++) cin>>mp[h][w];
    nq.push({1, 1});
    while (!nq.empty())
    {
        cnt++;
        q=nq;
        c=mp[nq.front().first][nq.front().second];
        while (!nq.empty()) nq.pop();
        while (!q.empty())
        {
            auto [x, y]=q.front();
            mp[x][y]='.';
            q.pop();
            for (int i=0; i<4; i++)
            {
                int nx=x+dx[i], ny=y+dy[i];
                if (nx<1||nx>h||ny<1||ny>w||mp[nx][ny]=='.') continue;
                if (mp[nx][ny]==c) q.push({nx, ny});
                else nq.push({nx, ny});
            }
        }
    }
    cout<<cnt;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...