#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
int dx[] = {1,0,-1,0}, dy[] = {0,1,0,-1};
int main(){
int h,w;
scanf("%d%d",&h,&w);
char grid[h][w];
int nonempty = 0;
for (int i = 0; i < h; i++){
for (int j = 0; j < w; j++){
scanf(" %c",&grid[i][j]);
if (grid[i][j] != '.') nonempty++;
}
}
int num = 0;
int vis[h][w];
int ans = 1;
char a = grid[0][0];
char b = a^'F'^'R';
memset(vis,0,sizeof(vis));
deque<ii> q;
q.push_back(ii(0,0));
vis[0][0] = 1;
while(q.size()){
ii cur = q.front(); q.pop_front();
int x = cur.first, y = cur.second;
for (int k = 0; k < 4; k++){
int nx = x + dx[k], ny = y + dy[k];
if (nx >= 0 && nx < h && ny >= 0 && ny < w && vis[nx][ny] == 0 && grid[nx][ny] != '.'){
if (grid[nx][ny] == grid[x][y]){
vis[nx][ny] = vis[x][y];
q.push_front(ii(nx,ny));
}
else{
vis[nx][ny] = vis[x][y]+1;
q.push_back(ii(nx,ny));
}
ans = max(ans,vis[nx][ny]);
//printf("%d %d %d\n",vis[nx][ny],nx,ny);
}
}
}
printf("%d",ans);
}
Compilation message
tracks.cpp: In function 'int main()':
tracks.cpp:16:9: warning: unused variable 'num' [-Wunused-variable]
int num = 0;
^~~
tracks.cpp:20:10: warning: unused variable 'b' [-Wunused-variable]
char b = a^'F'^'R';
^
tracks.cpp:7:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&h,&w);
~~~~~^~~~~~~~~~~~~~
tracks.cpp:12:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf(" %c",&grid[i][j]);
~~~~~^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
1528 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
15 ms |
1280 KB |
Output is correct |
5 |
Correct |
7 ms |
768 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
11 ms |
256 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
7 ms |
768 KB |
Output is correct |
11 |
Correct |
6 ms |
512 KB |
Output is correct |
12 |
Correct |
10 ms |
768 KB |
Output is correct |
13 |
Correct |
12 ms |
768 KB |
Output is correct |
14 |
Correct |
8 ms |
768 KB |
Output is correct |
15 |
Correct |
38 ms |
1536 KB |
Output is correct |
16 |
Correct |
36 ms |
1528 KB |
Output is correct |
17 |
Correct |
22 ms |
1536 KB |
Output is correct |
18 |
Correct |
25 ms |
1280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
127 ms |
7928 KB |
Output is correct |
3 |
Correct |
1187 ms |
78588 KB |
Output is correct |
4 |
Correct |
266 ms |
18780 KB |
Output is correct |
5 |
Correct |
734 ms |
44572 KB |
Output is correct |
6 |
Correct |
1742 ms |
92668 KB |
Output is correct |
7 |
Correct |
7 ms |
512 KB |
Output is correct |
8 |
Correct |
6 ms |
640 KB |
Output is correct |
9 |
Correct |
9 ms |
640 KB |
Output is correct |
10 |
Correct |
4 ms |
512 KB |
Output is correct |
11 |
Correct |
5 ms |
512 KB |
Output is correct |
12 |
Correct |
6 ms |
384 KB |
Output is correct |
13 |
Correct |
137 ms |
7964 KB |
Output is correct |
14 |
Correct |
78 ms |
4728 KB |
Output is correct |
15 |
Correct |
81 ms |
5240 KB |
Output is correct |
16 |
Correct |
74 ms |
3448 KB |
Output is correct |
17 |
Correct |
431 ms |
20224 KB |
Output is correct |
18 |
Correct |
388 ms |
19880 KB |
Output is correct |
19 |
Correct |
301 ms |
18680 KB |
Output is correct |
20 |
Correct |
263 ms |
17248 KB |
Output is correct |
21 |
Correct |
669 ms |
45896 KB |
Output is correct |
22 |
Correct |
734 ms |
44360 KB |
Output is correct |
23 |
Correct |
714 ms |
38280 KB |
Output is correct |
24 |
Correct |
675 ms |
45020 KB |
Output is correct |
25 |
Correct |
1332 ms |
78828 KB |
Output is correct |
26 |
Correct |
1121 ms |
110516 KB |
Output is correct |
27 |
Correct |
1568 ms |
113192 KB |
Output is correct |
28 |
Correct |
1586 ms |
92780 KB |
Output is correct |
29 |
Correct |
1640 ms |
90292 KB |
Output is correct |
30 |
Correct |
1647 ms |
96324 KB |
Output is correct |
31 |
Correct |
1298 ms |
50988 KB |
Output is correct |
32 |
Correct |
1678 ms |
102980 KB |
Output is correct |