#include <bits/stdc++.h>
#define int long long
#define chiikawa ios_base::sync_with_stdio(0); cin.tie(0);
#define ff first
#define ss second
#define sz(x) (x).size()
#define pii pair<int,int>
#define plii pair<int, pair<int,int>>
#define lc u<<1
#define rc u<<1|1
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define per(i,x,y) for(int i=x;i>=y;--i)
#define INF 0x3f3f3f3f
#define lowbit(x) (x & (-x))
using namespace std;
int n, m, dep[4005][4005], ans = 1;
int dr[4] = {1, -1, 0, 0}, dc[4] = {0, 0, 1, -1};
string sn[4005];
bool check(int x, int y){
return (x >= 0 && x < n && y >= 0 && y < m && sn[x][y] == '.');
}
signed main(){
chiikawa
cin >> n >> m;
for(int i = 0 ;i < n; i ++) cin >> sn[i];
deque<pii> q;
q.push_back({0, 0});
dep[0][0] = 1;
while(sz(q)){
auto c = q.front();
int u = c.ff, v = c.ss;
q.pop_front();
ans = max(ans, dep[u][v]);
for(int k = 0; k < 4; k ++){
int i = u + dr[k], j = v + dc[k];
if(check(i, j) && dep[i][j] == 0){
if(sn[i][j] == sn[u][v])
dep[i][j] = dep[u][v], q.push_front({i, j});
else
dep[i][j] = dep[u][v] + 1, q.push_back({i, j});
}
}
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
604 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
604 KB |
Output isn't correct |
4 |
Incorrect |
0 ms |
860 KB |
Output isn't correct |
5 |
Incorrect |
0 ms |
604 KB |
Output isn't correct |
6 |
Incorrect |
0 ms |
604 KB |
Output isn't correct |
7 |
Incorrect |
0 ms |
604 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
11 |
Incorrect |
0 ms |
604 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
600 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
14 |
Incorrect |
0 ms |
604 KB |
Output isn't correct |
15 |
Incorrect |
1 ms |
1884 KB |
Output isn't correct |
16 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
17 |
Incorrect |
1 ms |
920 KB |
Output isn't correct |
18 |
Incorrect |
1 ms |
868 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
16232 KB |
Output isn't correct |
2 |
Incorrect |
3 ms |
3536 KB |
Output isn't correct |
3 |
Incorrect |
274 ms |
214540 KB |
Output isn't correct |
4 |
Incorrect |
14 ms |
18000 KB |
Output isn't correct |
5 |
Incorrect |
49 ms |
48720 KB |
Output isn't correct |
6 |
Incorrect |
35 ms |
33872 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
8 |
Incorrect |
7 ms |
16240 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
11 |
Incorrect |
7 ms |
16988 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
1368 KB |
Output isn't correct |
13 |
Incorrect |
3 ms |
3676 KB |
Output isn't correct |
14 |
Incorrect |
2 ms |
2392 KB |
Output isn't correct |
15 |
Incorrect |
4 ms |
6748 KB |
Output isn't correct |
16 |
Incorrect |
1 ms |
1884 KB |
Output isn't correct |
17 |
Incorrect |
8 ms |
10508 KB |
Output isn't correct |
18 |
Incorrect |
11 ms |
17228 KB |
Output isn't correct |
19 |
Incorrect |
12 ms |
17832 KB |
Output isn't correct |
20 |
Incorrect |
56 ms |
53512 KB |
Output isn't correct |
21 |
Incorrect |
22 ms |
19632 KB |
Output isn't correct |
22 |
Incorrect |
50 ms |
48872 KB |
Output isn't correct |
23 |
Incorrect |
16 ms |
16472 KB |
Output isn't correct |
24 |
Incorrect |
14 ms |
19748 KB |
Output isn't correct |
25 |
Incorrect |
221 ms |
159192 KB |
Output isn't correct |
26 |
Correct |
27 ms |
25680 KB |
Output is correct |
27 |
Incorrect |
37 ms |
33872 KB |
Output isn't correct |
28 |
Incorrect |
37 ms |
34128 KB |
Output isn't correct |
29 |
Incorrect |
37 ms |
33872 KB |
Output isn't correct |
30 |
Incorrect |
37 ms |
33168 KB |
Output isn't correct |
31 |
Incorrect |
24 ms |
21520 KB |
Output isn't correct |
32 |
Incorrect |
37 ms |
33872 KB |
Output isn't correct |