이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define vl vector<ll>
#define sl set<ll>
#define conn continue
#define tests while(t--)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define f first
#define s second
using namespace std;
const int sz = 4005;
int neighborx[4] = {1, -1, 0, 0};
int neighbory[4] = {0, 0, 1, -1};
int depth[sz][sz], n, m, i, j;
string a[sz];
bool isvalid(int c, int d)
{
if(c < 0 || d < 0 || c >= n || d >= m || a[c][d] == '.') return false;
return true;
}
int main()
{
cin >> n >> m;
for(i = 0; i < n; i++) cin >> a[i];
depth[0][0] = 1;
deque<pii>q;
q.pb({0, 0});
int ans = 0;
while(!q.empty())
{
auto s = q.front();
q.pop_front();
int x = s.f, y = s.s;
ans = max(ans, depth[x][y]);
for(i = 0; i < 4; i++)
{
int nx = x + neighborx[i], ny = y + neighbory[i];
if(isvalid(nx, ny) && depth[nx][ny] == 0)
{
if(a[x][y] == a[nx][ny])
{
depth[nx][ny] = depth[x][y];
q.push_front({nx, ny});
}
else
{
depth[nx][ny] = depth[x][y] + 1;
q.pb({nx, ny});
}
}
}
}
cout << ans << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |