이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int N = 4001, INF = 2e9, dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};
int n, m, d[N][N];
char a[N][N];
inline bool check(int x, int y){
return 1 <= x && x <= n && 1 <= y && y <= m;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; i++){
cin >> a[i] + 1;
for(int j = 1; j <= m; j++){
d[i][j] = INF;
}
}
deque < pair < short, short > > q;
q.push_back(make_pair(1, 1));
d[1][1] = 1;
while(!q.empty()){
int x = q.front().first,
y = q.front().second;
q.pop_front();
for(int i = 0; i < 4; i++){
int xx = x + dx[i],
yy = y + dy[i];
if(check(xx, yy) && a[xx][yy] != '.'){
int val = d[x][y] + (a[x][y] != a[xx][yy]);
if(d[xx][yy] > val){
d[xx][yy] = val;
if(a[x][y] == a[xx][yy]){
q.push_front(make_pair(xx, yy));
}
else{
q.push_back(make_pair(xx, yy));
}
}
}
}
}
int ans = 0;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
if(a[i][j] != '.'){
ans = max(ans, d[i][j]);
}
}
}
cout << ans << "\n";
}
컴파일 시 표준 에러 (stderr) 메시지
tracks.cpp: In function 'int main()':
tracks.cpp:23:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
cin >> a[i] + 1;
~~~~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |