이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**
* Author : Samuel Batara (Aratab)
**/
#include <bits/stdc++.h>
using namespace std;
int N,M;
string s[4001];
int dep[4001][4001];
vector<int> dx = {1,0,-1,0};
vector<int> dy = {0,1,0,-1};
bool inside(int x, int y) {
return (x>-1 && x<N && y>-1 && y<M && s[x][y]!='.');
}
void dahiken() {
cin >> N >> M;
for(int i=0; i<N; i++) cin >> s[i];
dep[0][0] = 1;
deque<pair<int,int>> q;
q.push_back({0,0});
int ans = 1;
while(!q.empty()) {
int a,b; tie(a,b) = q.front(); q.pop_front();
ans = max(ans, dep[a][b]);
for(int i=0; i<4; i++) {
int x = a + dx[i], y = b + dy[i];
if(inside(x,y) && dep[x][y]==0) {
if(s[a][b] == s[x][y]) {
dep[x][y] = dep[a][b];
q.push_front({x,y});
} else {
dep[x][y] = dep[a][b] + 1;
q.push_back({x,y});
}
}
}
}
cout << ans << '\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int ntc=1;
//cin >> ntc;
while(ntc--) {
dahiken();
}
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |