#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
const int MAX_H=4000,MAX_W=4000;
bool visited[MAX_H][MAX_W];
char grid[MAX_H][MAX_W];
int dist[MAX_H][MAX_W];
//L,R,U,D
vector<int> dx={0,0,-1,1};
vector<int> dy={-1,1,0,0};
int main() {
int h,w; cin >> h >> w;
for(int i=0; i<h; i++) {
for(int j=0; j<w; j++) {
cin >> grid[i][j];
}
}
deque<pair<int,int>> q;
q.push_back(make_pair(0,0));
while(!q.empty()) {
pair<int,int> v=q.front();
q.pop_front();
for(int i=0; i<4; i++) {
pair<int,int> u={v.first+dx[i],v.second+dy[i]};
if(u.first<0 || u.first>=h || u.second<0 || u.second>=w || visited[u.first][u.second] || grid[u.first][u.second]=='.') continue;
if(grid[v.first][v.second]==grid[u.first][u.second]) {
dist[u.first][u.second]=dist[v.first][v.second];
q.push_front(make_pair(u.first,u.second));
}
else {
dist[u.first][u.second]=dist[v.first][v.second]+1;
q.push_back(make_pair(u.first,u.second));
}
}
}
int ans=0;
for(int i=0; i<h; i++) {
for(int j=0; j<w; j++) {
if(visited[i][j]) ans=max(ans,dist[i][j]);
}
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1650 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Runtime error |
1768 ms |
1048576 KB |
Execution killed with signal 9 |
3 |
Runtime error |
1441 ms |
1048576 KB |
Execution killed with signal 9 |
4 |
Runtime error |
1466 ms |
1048576 KB |
Execution killed with signal 9 |
5 |
Runtime error |
1521 ms |
1048576 KB |
Execution killed with signal 9 |
6 |
Runtime error |
1802 ms |
1048576 KB |
Execution killed with signal 9 |
7 |
Runtime error |
1405 ms |
1048576 KB |
Execution killed with signal 9 |
8 |
Runtime error |
1270 ms |
1048576 KB |
Execution killed with signal 9 |
9 |
Runtime error |
1711 ms |
1048576 KB |
Execution killed with signal 9 |
10 |
Runtime error |
1451 ms |
1048576 KB |
Execution killed with signal 9 |
11 |
Runtime error |
1291 ms |
1048576 KB |
Execution killed with signal 9 |
12 |
Runtime error |
1324 ms |
1048576 KB |
Execution killed with signal 9 |
13 |
Runtime error |
1539 ms |
1048576 KB |
Execution killed with signal 9 |
14 |
Runtime error |
1534 ms |
1048576 KB |
Execution killed with signal 9 |
15 |
Runtime error |
1966 ms |
1048576 KB |
Execution killed with signal 9 |
16 |
Runtime error |
1361 ms |
1048576 KB |
Execution killed with signal 9 |
17 |
Runtime error |
1887 ms |
1048576 KB |
Execution killed with signal 9 |
18 |
Runtime error |
1414 ms |
1048576 KB |
Execution killed with signal 9 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1683 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Runtime error |
1887 ms |
1048576 KB |
Execution killed with signal 9 |
3 |
Runtime error |
1762 ms |
1048576 KB |
Execution killed with signal 9 |
4 |
Runtime error |
1535 ms |
1048576 KB |
Execution killed with signal 9 |
5 |
Runtime error |
1993 ms |
1048576 KB |
Execution killed with signal 9 |
6 |
Runtime error |
1759 ms |
1048576 KB |
Execution killed with signal 9 |
7 |
Runtime error |
1509 ms |
1048576 KB |
Execution killed with signal 9 |
8 |
Runtime error |
1631 ms |
1048576 KB |
Execution killed with signal 9 |
9 |
Runtime error |
1350 ms |
1048576 KB |
Execution killed with signal 9 |
10 |
Execution timed out |
2049 ms |
736472 KB |
Time limit exceeded |
11 |
Runtime error |
1659 ms |
1048576 KB |
Execution killed with signal 9 |
12 |
Execution timed out |
2061 ms |
736244 KB |
Time limit exceeded |
13 |
Runtime error |
1856 ms |
1048576 KB |
Execution killed with signal 9 |
14 |
Runtime error |
1811 ms |
1048576 KB |
Execution killed with signal 9 |
15 |
Runtime error |
1751 ms |
1048576 KB |
Execution killed with signal 9 |
16 |
Runtime error |
1706 ms |
1048576 KB |
Execution killed with signal 9 |
17 |
Execution timed out |
2063 ms |
1048576 KB |
Time limit exceeded |
18 |
Runtime error |
1825 ms |
1048576 KB |
Execution killed with signal 9 |
19 |
Runtime error |
1522 ms |
1048576 KB |
Execution killed with signal 9 |
20 |
Runtime error |
1337 ms |
1048576 KB |
Execution killed with signal 9 |
21 |
Execution timed out |
2063 ms |
1006480 KB |
Time limit exceeded |
22 |
Runtime error |
1924 ms |
1048576 KB |
Execution killed with signal 9 |
23 |
Execution timed out |
2048 ms |
1048576 KB |
Time limit exceeded |
24 |
Execution timed out |
2052 ms |
713808 KB |
Time limit exceeded |
25 |
Execution timed out |
2073 ms |
663336 KB |
Time limit exceeded |
26 |
Runtime error |
1641 ms |
1048576 KB |
Execution killed with signal 9 |
27 |
Runtime error |
1724 ms |
1048576 KB |
Execution killed with signal 9 |
28 |
Runtime error |
1759 ms |
1048576 KB |
Execution killed with signal 9 |
29 |
Runtime error |
1821 ms |
1048576 KB |
Execution killed with signal 9 |
30 |
Runtime error |
1713 ms |
1048576 KB |
Execution killed with signal 9 |
31 |
Runtime error |
1746 ms |
1048576 KB |
Execution killed with signal 9 |
32 |
Runtime error |
1727 ms |
1048576 KB |
Execution killed with signal 9 |