이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
signed main() {
cin.tie(0)->sync_with_stdio(0);
int n, m;
cin >> n >> m;
vector<string> mat(n);
for (string& s : mat) {
cin >> s;
s.resize(n);
}
int di[]{0, 0, -1, 1};
int dj[]{-1, 1, 0, 0};
vector vis(n, vector<bool>(m));
int cnt = 0, res = 0;
auto dfs = [&](auto& dfs, int i, int j, int d)->void {
res = max(res, d);
cnt++;
//if (!(cnt & (1<<20)-1)) cout << cnt << endl;
vis[i][j] = 1;
for (int d = 0; d < 4; d++) {
int ei = i + di[d];
int ej = j + dj[d];
if (0 <= ei && ei < n && 0 <= ej && ej < m && !vis[ei][ej] && mat[ei][ej] == mat[i][j]) {
dfs(dfs, ei, ej, d);
}
}
for (int d = 0; d < 4; d++) {
int ei = i + di[d];
int ej = j + dj[d];
if (0 <= ei && ei < n && 0 <= ej && ej < m && !vis[ei][ej] && mat[ei][ej] == mat[i][j]) {
dfs(dfs, ei, ej, d+1);
}
}
};
dfs(dfs, 0, 0, 1);
cout << res << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |