이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int)(x).size()
const int MAXN = 4005;
const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
int n, m;
char snow[MAXN][MAXN];
int depth[MAXN][MAXN];
deque<pair<int, int>> dq;
bool inbounds(int x, int y){
return (x >= 0 && y >= 0 && x < n && y < m && snow[x][y] != '.');
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
cin >> n >> m;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cin >> snow[i][j];
}
}
depth[0][0] = 1;
dq.push_back(make_pair(0, 0));
int ans = 0;
while(!dq.empty()){
pair<int, int> curr = dq.front();
dq.pop_front();
ans = max(ans, depth[curr.first][curr.second]);
for(int i = 0; i < 4; i++){
int x = curr.first + dx[i];
int y = curr.second + dy[i];
if(inbounds(x, y) && !depth[x][y]){
if(snow[x][y] == snow[curr.first][curr.second]){
depth[x][y] = depth[curr.first][curr.second];
dq.push_front(make_pair(x, y));
}
else{
depth[x][y] = depth[curr.first][curr.second] + 1;
dq.push_back(make_pair(x, y));
}
}
}
}
cout << ans << '\n';
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |