이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
pair<int, int> dir[4]={{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
vector<pair<int, int> > vec[2];
string a[4000];
int n, m, ans;
bool ok(pair<int, int> u)
{
return (u.first>=0 && u.first<n && u.second>=0 && u.second<m && a[u.first][u.second]!='.');
}
void dfs(pair<int, int> u)
{
char x=a[u.first][u.second];
a[u.first][u.second]='.';
for (pair<int, int> i:dir)
{
pair<int, int> v=u;
v.first+=i.first;
v.second+=i.second;
if (ok(v))
{
if (a[v.first][v.second]==x)
dfs(v);
else
vec[(ans&1)^1].push_back(v);
}
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i=0; i<n; i++)
cin >> a[i];
vec[0].push_back({0, 0});
while (vec[ans&1].size())
{
for (pair<int, int> u:vec[ans&1])
if (a[u.first][u.second]!='.')
dfs(u);
vec[ans&1].clear();
ans++;
}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |