이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
using namespace std;
using ii = pair<int,int>;
int xd[] = {1,-1,0,0}, yd[] = {0,0,1,-1};
#define forn(i, x, n) for(int i = (x); i < (int)(n); i++)
const int MAXS = 4000;
int N, M;
char G[MAXS][MAXS];
bool inside(int i, int j){
return (i > -1 && j > -1 && i < N && j < M && G[i][j] != '.');
}
int main(){
scanf("%d%d",&N,&M);
forn(i,0,N) forn(j,0,M) scanf(" %c",&G[i][j]);
deque<pair<ii, int>> Q;
vector<vector<bool>> vis(N, vector<bool>(M, false));
int ans=0;
Q.push_front({{0,0},1});
while(!Q.empty()){
pair<ii, int> p = Q.front(); Q.pop_front();
int d = p.second; ii pos = p.first;
ans = max(ans, d);
forn(i,0,4){
int x2 = xd[i]+pos.first, y2 = yd[i]+pos.second;
if(inside(x2, y2) && !vis[x2][y2]){
vis[x2][y2] = true;
if(G[pos.first][pos.second] == G[x2][y2]) Q.push_front({{x2,y2},d});
else Q.push_back({{x2,y2},d+1});
}
}
}
printf("%d\n",ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
tracks.cpp: In function 'int main()':
tracks.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
21 | scanf("%d%d",&N,&M);
| ~~~~~^~~~~~~~~~~~~~
tracks.cpp:22:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
22 | forn(i,0,N) forn(j,0,M) scanf(" %c",&G[i][j]);
| ~~~~~^~~~~~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |