이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int dx[4]{0, 0, 1, -1}, dy[4]{1, -1, 0, 0};
int dist[4000][4000];
int w, h;
bool inside(int i, int j)
{
return (0 <= i && i < w && 0 <= j && j < h);
}
int main()
{
cin >> w >> h;
vector<string> mp(4000);
for (int i = 0; i < w; i++)
{
cin >> mp[i];
}
int ans = 1;
deque<pair<int, int>> q;
dist[0][0] = 1;
q.push_back({0, 0});
while (!q.empty())
{
auto [x, y] = q.front();
q.pop_front();
for (int i = 0; i < 4; i++)
{
int newx = x + dx[i];
int newy = y + dy[i];
if (inside(newx, newy) && dist[newx][newy] == 0 && mp[newx][newy] != '.')
{
if (mp[newx][newy] == mp[x][y])
{
dist[newx][newy] = dist[x][y];
q.push_front({newx, newy});
}
else
{
dist[newx][newy] = dist[x][y] + 1;
ans = max(ans, dist[newx][newy]);
q.push_back({newx, newy});
}
}
}
}
cout << ans << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |