이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
/**
* IDEA:
*/
const int sz = 4e3 + 5;
int m, n;
int a[sz][sz], vi[sz][sz], d[sz][sz];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
bool valid(int x, int y){
return (x >= 1 && x <= m && y >= 1 && y <= n);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("main.inp","r",stdin);
// freopen("main.out","w",stdout);
cin>>m>>n;
for(int i=1;i<=m;++i){
for(int j=1;j<=n;++j){
char c;
cin>>c;
if(c == '.'){
a[i][j] = -1;
continue;
}
if(c == 'F'){
a[i][j] = 1;
}
else{
a[i][j] = 2;
}
}
}
deque<pair<int,int>> q;
q.push_front({1, 1});
vi[1][1] = 1;
d[1][1] = 1;
int ans = 0;
while(q.size()){
int x = q.front().first;
int y = q.front().second;
q.pop_front();
ans = max(ans, d[x][y]);
for(int i=0;i<4;++i){
int u = x + dx[i];
int v = y + dy[i];
int c = (a[x][y] != a[u][v]);
if(valid(u, v) && !vi[u][v] && a[u][v] != -1){
d[u][v] = d[x][y] + c;
vi[u][v] = 1;
if(!c){
q.push_front({u, v});
}
else{
q.push_back({u, v});
}
}
}
}
cout<<ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |