#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ll long long
struct P{
ll x, y;
};
void dbg_out() { cerr << endl; }
template <typename H, typename... T>
void dbg_out(H h, T... t) { cerr << ' ' << h; dbg_out(t...); }
#define dbg(...) { cerr << #__VA_ARGS__ << ':'; dbg_out(__VA_ARGS__); }
const int N = 4001;
char grid[N][N];
int dist[N][N];
int h, w;
int valid(int x, int y){
return (0 <= x && x < h) && (0 <= y && y < w);
}
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
signed main(){
fastio;
cin >> h >> w;
for (int i=0; i<h; i++){
for (int j=0; j<w; j++){
cin >> grid[i][j];
}
}
memset(dist, -1, sizeof(dist));
queue<pair<int, int>> q;
int ans=1;
dist[0][0] = 1;
q.push({0, 0});
while (!q.empty()){
int x, y;
tie(x, y) = q.front(); q.pop();
for (int i=0; i<4; i++){
int a, b;
a = dx[i]+x;
b = dy[i]+y;
if (!valid(a, b) || grid[a][b] == '.') continue;
int v = dist[x][y] + (grid[a][b] != grid[x][y]);
if (dist[a][b] == -1) {
dist[a][b] = v;
q.push({a, b});
}
else dist[a][b] = min(dist[a][b], v);
}
}
for (int i=0; i<h; i++){
for (int j=0; j<w; j++){
ans = max(ans, dist[i][j]);
}
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
66396 KB |
Output isn't correct |
2 |
Correct |
7 ms |
64092 KB |
Output is correct |
3 |
Incorrect |
8 ms |
64188 KB |
Output isn't correct |
4 |
Incorrect |
10 ms |
66396 KB |
Output isn't correct |
5 |
Incorrect |
9 ms |
64272 KB |
Output isn't correct |
6 |
Correct |
6 ms |
64252 KB |
Output is correct |
7 |
Incorrect |
8 ms |
64092 KB |
Output isn't correct |
8 |
Incorrect |
8 ms |
64252 KB |
Output isn't correct |
9 |
Incorrect |
8 ms |
64092 KB |
Output isn't correct |
10 |
Incorrect |
9 ms |
64252 KB |
Output isn't correct |
11 |
Incorrect |
8 ms |
64220 KB |
Output isn't correct |
12 |
Incorrect |
10 ms |
64092 KB |
Output isn't correct |
13 |
Incorrect |
8 ms |
64092 KB |
Output isn't correct |
14 |
Incorrect |
9 ms |
64300 KB |
Output isn't correct |
15 |
Incorrect |
13 ms |
66396 KB |
Output isn't correct |
16 |
Incorrect |
14 ms |
66544 KB |
Output isn't correct |
17 |
Incorrect |
12 ms |
66396 KB |
Output isn't correct |
18 |
Incorrect |
10 ms |
66392 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
78428 KB |
Output is correct |
2 |
Incorrect |
30 ms |
69836 KB |
Output isn't correct |
3 |
Incorrect |
164 ms |
94292 KB |
Output isn't correct |
4 |
Incorrect |
54 ms |
76116 KB |
Output isn't correct |
5 |
Correct |
129 ms |
85328 KB |
Output is correct |
6 |
Incorrect |
357 ms |
94396 KB |
Output isn't correct |
7 |
Correct |
9 ms |
78684 KB |
Output is correct |
8 |
Correct |
10 ms |
78596 KB |
Output is correct |
9 |
Incorrect |
8 ms |
64312 KB |
Output isn't correct |
10 |
Correct |
8 ms |
64204 KB |
Output is correct |
11 |
Correct |
10 ms |
78428 KB |
Output is correct |
12 |
Correct |
8 ms |
64272 KB |
Output is correct |
13 |
Incorrect |
35 ms |
69884 KB |
Output isn't correct |
14 |
Incorrect |
20 ms |
69244 KB |
Output isn't correct |
15 |
Correct |
20 ms |
69192 KB |
Output is correct |
16 |
Incorrect |
17 ms |
66908 KB |
Output isn't correct |
17 |
Incorrect |
76 ms |
76348 KB |
Output isn't correct |
18 |
Correct |
55 ms |
76116 KB |
Output is correct |
19 |
Incorrect |
53 ms |
75856 KB |
Output isn't correct |
20 |
Incorrect |
44 ms |
73556 KB |
Output isn't correct |
21 |
Incorrect |
117 ms |
85584 KB |
Output isn't correct |
22 |
Correct |
129 ms |
85292 KB |
Output is correct |
23 |
Incorrect |
122 ms |
82004 KB |
Output isn't correct |
24 |
Correct |
128 ms |
85424 KB |
Output is correct |
25 |
Correct |
258 ms |
94144 KB |
Output is correct |
26 |
Correct |
301 ms |
90544 KB |
Output is correct |
27 |
Incorrect |
365 ms |
94292 KB |
Output isn't correct |
28 |
Incorrect |
365 ms |
94392 KB |
Output isn't correct |
29 |
Incorrect |
386 ms |
94288 KB |
Output isn't correct |
30 |
Incorrect |
351 ms |
93776 KB |
Output isn't correct |
31 |
Incorrect |
256 ms |
86352 KB |
Output isn't correct |
32 |
Incorrect |
340 ms |
94516 KB |
Output isn't correct |